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
772bebef
Commit
772bebef
authored
Sep 16, 2019
by
Kai Lothar John
Committed by
Dominik Charousset
Oct 11, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Introduces fold-expressions for data processor
parent
d6ebaac3
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
71 additions
and
0 deletions
+71
-0
libcaf_core/caf/data_processor.hpp
libcaf_core/caf/data_processor.hpp
+71
-0
No files found.
libcaf_core/caf/data_processor.hpp
View file @
772bebef
...
@@ -475,6 +475,76 @@ public:
...
@@ -475,6 +475,76 @@ public:
return
none
;
return
none
;
}
}
static_assert
(
__cpp_fold_expressions
,
"C++ fold-expressions required"
);
#if __cpp_fold_expressions
template
<
class
F
>
inline
error
safe_callback_action
(
meta
::
save_callback_t
<
F
>
x
)
{
return
Derived
::
reads_state
?
x
.
fun
()
:
none
;
}
template
<
class
F
>
inline
error
load_callback_action
(
meta
::
load_callback_t
<
F
>
x
)
{
return
Derived
::
writes_state
?
x
.
fun
()
:
none
;
}
inline
error
annotation_action
(
const
meta
::
annotation
&
)
{
return
none
;
}
template
<
typename
T
>
inline
typename
std
::
enable_if
<
is_allowed_unsafe_message_type
<
T
>::
value
,
error
>::
type
allowed_unsafe_message_type_action
(
const
T
&
)
{
return
none
;
}
template
<
class
T
>
inline
typename
std
::
enable_if
<!
meta
::
is_annotation
<
T
>::
value
&&
!
is_allowed_unsafe_message_type
<
T
>::
value
,
error
>::
type
action
(
T
&&
x
)
{
static_assert
(
Derived
::
reads_state
||
(
!
std
::
is_rvalue_reference
<
T
&&>::
value
&&
!
std
::
is_const
<
typename
std
::
remove_reference
<
T
>::
type
>::
value
),
"a loading inspector requires mutable lvalue references"
);
return
apply
(
deconst
(
x
));
}
struct
FoldLeft
{
Derived
&
derived
;
error
err
=
none
;
template
<
class
F
>
inline
FoldLeft
&
operator
<<
(
meta
::
save_callback_t
<
F
>
x
)
{
if
(
not
err
)
err
=
derived
.
safe_callback_action
(
std
::
move
(
x
));
return
*
this
;
}
template
<
class
F
>
inline
FoldLeft
&
operator
<<
(
meta
::
load_callback_t
<
F
>
x
)
{
if
(
not
err
)
err
=
derived
.
load_callback_action
(
std
::
move
(
x
));
return
*
this
;
}
inline
FoldLeft
&
operator
<<
(
const
meta
::
annotation
&
x
)
{
if
(
not
err
)
err
=
derived
.
annotation_action
(
x
);
return
*
this
;
}
template
<
typename
T
>
inline
typename
std
::
enable_if
<
is_allowed_unsafe_message_type
<
T
>::
value
,
FoldLeft
&>::
type
operator
<<
(
const
T
&
x
)
{
if
(
not
err
)
err
=
derived
.
allowed_unsafe_message_type_action
(
x
);
return
*
this
;
}
template
<
typename
T
>
inline
typename
std
::
enable_if
<!
meta
::
is_annotation
<
T
>::
value
&&
!
is_allowed_unsafe_message_type
<
T
>::
value
,
FoldLeft
&>::
type
operator
<<
(
T
&&
x
)
{
if
(
not
err
)
err
=
derived
.
action
(
std
::
forward
<
T
>
(
x
));
return
*
this
;
}
};
template
<
class
...
Ts
>
inline
error
operator
()(
Ts
&&
...
xs
)
{
return
(
FoldLeft
{
dref
()}
<<
...
<<
xs
).
err
;
}
#else // __cpp_fold_expressions
template
<
class
F
,
class
...
Ts
>
template
<
class
F
,
class
...
Ts
>
error
operator
()(
meta
::
save_callback_t
<
F
>
x
,
Ts
&&
...
xs
)
{
error
operator
()(
meta
::
save_callback_t
<
F
>
x
,
Ts
&&
...
xs
)
{
// TODO: use `if constexpr` when switching to C++17.
// TODO: use `if constexpr` when switching to C++17.
...
@@ -524,6 +594,7 @@ public:
...
@@ -524,6 +594,7 @@ public:
return
err
;
return
err
;
return
dref
()(
std
::
forward
<
Ts
>
(
xs
)...);
return
dref
()(
std
::
forward
<
Ts
>
(
xs
)...);
}
}
#endif // __cpp_fold_expressions
protected
:
protected
:
virtual
error
apply_impl
(
int8_t
&
)
=
0
;
virtual
error
apply_impl
(
int8_t
&
)
=
0
;
...
...
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