Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
A
Actor Framework
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Metrics
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
cpp-libs
Actor Framework
Commits
dc768236
Commit
dc768236
authored
Feb 04, 2015
by
Dominik Charousset
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Coding style nitpicks
parent
a82a0356
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
69 additions
and
69 deletions
+69
-69
libcaf_core/caf/detail/lifted_fun.hpp
libcaf_core/caf/detail/lifted_fun.hpp
+26
-27
libcaf_core/caf/policy/invoke_policy.hpp
libcaf_core/caf/policy/invoke_policy.hpp
+2
-2
libcaf_core/caf/variant.hpp
libcaf_core/caf/variant.hpp
+41
-40
No files found.
libcaf_core/caf/detail/lifted_fun.hpp
View file @
dc768236
...
...
@@ -35,21 +35,16 @@
namespace
caf
{
namespace
detail
{
class
lifted_fun_zipper
{
public:
struct
lifted_fun_zipper
{
template
<
class
F
,
typename
T
>
auto
operator
()(
const
F
&
fun
,
T
&
arg
)
->
decltype
(
fun
(
arg
))
const
{
return
fun
(
arg
);
}
// forward everything as reference if no guard/transformation is set
template
<
class
T
>
auto
operator
()(
const
unit_t
&
,
T
&
arg
)
const
->
decltype
(
std
::
ref
(
arg
))
{
return
std
::
ref
(
arg
);
}
};
template
<
class
T
>
...
...
@@ -67,62 +62,64 @@ inline bool has_none() {
}
template
<
class
T
,
class
...
Ts
>
inline
bool
has_none
(
const
T
&
,
const
Ts
&
...
vs
)
{
bool
has_none
(
const
T
&
,
const
Ts
&
...
vs
)
{
return
has_none
(
vs
...);
}
template
<
class
T
,
class
...
Ts
>
inline
bool
has_none
(
const
optional
<
T
>&
v
,
const
Ts
&
...
vs
)
{
bool
has_none
(
const
optional
<
T
>&
v
,
const
Ts
&
...
vs
)
{
return
!
v
||
has_none
(
vs
...);
}
// allows F to have fewer arguments than the lifted_fun calling it
template
<
class
R
,
typename
F
>
class
lifted_fun_invoker
{
public:
using
arg_types
=
typename
get_callable_trait
<
F
>::
arg_types
;
static
constexpr
size_t
num_args
=
tl_size
<
arg_types
>::
value
;
public:
lifted_fun_invoker
(
F
&
fun
)
:
f
(
fun
)
{
}
lifted_fun_invoker
(
F
&
fun
)
:
f
(
fun
)
{
// nop
}
template
<
class
...
Ts
>
typename
std
::
enable_if
<
sizeof
...(
Ts
)
==
num_args
,
R
>::
type
operator
()(
Ts
&
...
vs
)
const
{
if
(
has_none
(
vs
...))
return
none
;
if
(
has_none
(
vs
...))
{
return
none
;
}
return
f
(
unopt
(
vs
)...);
}
template
<
class
T
,
class
...
Ts
>
typename
std
::
enable_if
<
(
sizeof
...(
Ts
)
+
1
>
num_args
),
R
>::
type
operator
()(
T
&
v
,
Ts
&
...
vs
)
const
{
if
(
has_none
(
v
))
return
none
;
if
(
has_none
(
v
))
{
return
none
;
}
return
(
*
this
)(
vs
...);
}
private:
F
&
f
;
};
template
<
class
F
>
class
lifted_fun_invoker
<
bool
,
F
>
{
public:
using
arg_types
=
typename
get_callable_trait
<
F
>::
arg_types
;
static
constexpr
size_t
num_args
=
tl_size
<
arg_types
>::
value
;
public:
lifted_fun_invoker
(
F
&
fun
)
:
f
(
fun
)
{
}
lifted_fun_invoker
(
F
&
fun
)
:
f
(
fun
)
{
// nop
}
template
<
class
...
Ts
>
typename
std
::
enable_if
<
sizeof
...(
Ts
)
==
num_args
,
bool
>::
type
operator
()(
Ts
&&
...
vs
)
const
{
if
(
has_none
(
vs
...))
return
false
;
if
(
has_none
(
vs
...))
{
return
false
;
}
f
(
unopt
(
vs
)...);
return
true
;
}
...
...
@@ -130,14 +127,14 @@ class lifted_fun_invoker<bool, F> {
template
<
class
T
,
class
...
Ts
>
typename
std
::
enable_if
<
(
sizeof
...(
Ts
)
+
1
>
num_args
),
bool
>::
type
operator
()(
T
&&
arg
,
Ts
&&
...
vs
)
const
{
if
(
has_none
(
arg
))
return
false
;
if
(
has_none
(
arg
))
{
return
false
;
}
return
(
*
this
)(
vs
...);
}
private:
F
&
f
;
};
/**
...
...
@@ -181,7 +178,9 @@ class lifted_fun {
lifted_fun
&
operator
=
(
const
lifted_fun
&
)
=
default
;
lifted_fun
(
F
f
)
:
m_fun
(
std
::
move
(
f
))
{}
lifted_fun
(
F
f
)
:
m_fun
(
std
::
move
(
f
))
{
// nop
}
lifted_fun
(
F
f
,
projections
ps
)
:
m_fun
(
std
::
move
(
f
)),
m_ps
(
std
::
move
(
ps
))
{
// nop
...
...
libcaf_core/caf/policy/invoke_policy.hpp
View file @
dc768236
...
...
@@ -160,7 +160,7 @@ class invoke_policy {
if
(
ref_opt
)
{
auto
fhdl
=
fetch_response_promise
(
self
,
hdl
);
behavior
inner
=
*
ref_opt
;
*
ref_opt
=
behavior
{
ref_opt
->
assign
(
others
()
>>
[
=
]
{
// inner is const inside this lambda and mutable a C++14 feature
behavior
cpy
=
inner
;
...
...
@@ -169,7 +169,7 @@ class invoke_policy {
fhdl
.
deliver
(
*
inner_res
);
}
}
}
;
)
;
}
}
else
{
// respond by using the result of 'fun'
...
...
libcaf_core/caf/variant.hpp
View file @
dc768236
...
...
@@ -25,8 +25,9 @@
#include "caf/detail/variant_data.hpp"
#define CAF_VARIANT_CASE(x) \
case x: return visitor(from.get(std::integral_constant<int, \
x < max_type_id ? x : max_type_id >()))
case x: \
return visitor(from.get( \
std::integral_constant<int, (x < max_type_id ? x : max_type_id)>()))
namespace
caf
{
...
...
@@ -36,7 +37,7 @@ struct variant_assign_helper {
T
&
lhs
;
variant_assign_helper
(
T
&
lhs_ref
)
:
lhs
(
lhs_ref
)
{
}
template
<
class
U
>
inline
void
operator
()(
const
U
&
rhs
)
const
{
void
operator
()(
const
U
&
rhs
)
const
{
lhs
=
rhs
;
}
};
...
...
@@ -47,17 +48,18 @@ struct variant_move_helper {
T
&
lhs
;
variant_move_helper
(
T
&
lhs_ref
)
:
lhs
(
lhs_ref
)
{
}
template
<
class
U
>
inline
void
operator
()(
U
&
rhs
)
const
{
void
operator
()(
U
&
rhs
)
const
{
lhs
=
std
::
move
(
rhs
);
}
};
template
<
class
T
,
typename
U
,
bool
Enable
=
std
::
is_integral
<
T
>
::
value
&&
std
::
is_integral
<
U
>::
value
>
template
<
class
T
,
class
U
,
bool
Enable
=
std
::
is_integral
<
T
>
::
value
&&
std
::
is_integral
<
U
>::
value
>
struct
is_equal_int_type
{
static
constexpr
bool
value
=
sizeof
(
T
)
==
sizeof
(
U
)
&&
std
::
is_signed
<
T
>::
value
==
std
::
is_signed
<
U
>::
value
;
static
constexpr
bool
value
=
sizeof
(
T
)
==
sizeof
(
U
)
&&
std
::
is_signed
<
T
>::
value
==
std
::
is_signed
<
U
>::
value
;
};
template
<
class
T
,
typename
U
>
...
...
@@ -70,7 +72,8 @@ struct is_equal_int_type<T, U, false> : std::false_type { };
* `uint8_t != unsigned char on some compilers.
*/
template
<
class
T
,
typename
U
>
struct
is_same_ish
:
std
::
conditional
<
struct
is_same_ish
:
std
::
conditional
<
std
::
is_same
<
T
,
U
>::
value
,
std
::
true_type
,
is_equal_int_type
<
T
,
U
>
...
...
@@ -81,9 +84,7 @@ struct is_same_ish : std::conditional<
*/
template
<
class
...
Ts
>
class
variant
{
public:
using
types
=
detail
::
type_list
<
Ts
...
>
;
static
constexpr
int
max_type_id
=
sizeof
...(
Ts
)
-
1
;
...
...
@@ -134,20 +135,19 @@ class variant {
}
/** @cond PRIVATE */
template
<
int
Pos
>
inline
bool
is
(
std
::
integral_constant
<
int
,
Pos
>
)
const
{
bool
is
(
std
::
integral_constant
<
int
,
Pos
>
)
const
{
return
m_type
==
Pos
;
}
template
<
int
Pos
>
inline
const
typename
detail
::
tl_at
<
types
,
Pos
>::
type
&
const
typename
detail
::
tl_at
<
types
,
Pos
>::
type
&
get
(
std
::
integral_constant
<
int
,
Pos
>
token
)
const
{
return
m_data
.
get
(
token
);
}
template
<
int
Pos
>
inline
typename
detail
::
tl_at
<
types
,
Pos
>::
type
&
typename
detail
::
tl_at
<
types
,
Pos
>::
type
&
get
(
std
::
integral_constant
<
int
,
Pos
>
token
)
{
return
m_data
.
get
(
token
);
}
...
...
@@ -161,11 +161,9 @@ class variant {
typename
Visitor
::
result_type
apply
(
Visitor
&
visitor
)
{
return
apply_impl
(
*
this
,
visitor
);
}
/** @endcond */
private:
template
<
class
Self
,
typename
Visitor
>
static
typename
Visitor
::
result_type
apply_impl
(
Self
&
from
,
Visitor
&
visitor
)
{
switch
(
from
.
m_type
)
{
...
...
@@ -222,7 +220,7 @@ class variant {
}
template
<
class
...
Us
>
inline
void
set
(
const
variant
<
Us
...
>&
other
)
{
void
set
(
const
variant
<
Us
...
>&
other
)
{
using
namespace
detail
;
static_assert
(
tl_is_strict_subset
<
type_list
<
Us
...
>
,
types
>::
value
,
"cannot set variant of type A to variant of type B "
...
...
@@ -233,7 +231,7 @@ class variant {
}
template
<
class
...
Us
>
inline
void
set
(
variant
<
Us
...
>&&
other
)
{
void
set
(
variant
<
Us
...
>&&
other
)
{
using
namespace
detail
;
static_assert
(
tl_is_strict_subset
<
type_list
<
Us
...
>
,
types
>::
value
,
"cannot set variant of type A to variant of type B "
...
...
@@ -245,7 +243,6 @@ class variant {
int
m_type
;
detail
::
variant_data
<
typename
lift_void
<
Ts
>::
type
...
>
m_data
;
};
/**
...
...
@@ -254,7 +251,8 @@ class variant {
template
<
class
T
,
class
...
Us
>
T
&
get
(
variant
<
Us
...
>&
value
)
{
using
namespace
detail
;
constexpr
int
type_id
=
tl_find_if
<
type_list
<
Us
...
>
,
constexpr
int
type_id
=
tl_find_if
<
type_list
<
Us
...
>
,
tbind
<
is_same_ish
,
T
>::
template
type
>
::
value
;
std
::
integral_constant
<
int
,
type_id
>
token
;
...
...
@@ -278,11 +276,14 @@ const T& get(const variant<Us...>& value) {
template
<
class
T
,
class
...
Us
>
T
*
get
(
variant
<
Us
...
>*
value
)
{
using
namespace
detail
;
constexpr
int
type_id
=
tl_find_if
<
type_list
<
Us
...
>
,
constexpr
int
type_id
=
tl_find_if
<
type_list
<
Us
...
>
,
tbind
<
is_same_ish
,
T
>::
template
type
>
::
value
;
std
::
integral_constant
<
int
,
type_id
>
token
;
if
(
value
->
is
(
token
))
return
&
get
<
T
>
(
*
value
);
if
(
value
->
is
(
token
))
{
return
&
get
<
T
>
(
*
value
);
}
return
nullptr
;
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment