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
e7805402
Commit
e7805402
authored
Jul 08, 2016
by
Matthias Vallentin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make optional<T> inspectable
(via @Neverlord)
parent
a7b5c235
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
38 additions
and
0 deletions
+38
-0
libcaf_core/caf/optional.hpp
libcaf_core/caf/optional.hpp
+38
-0
No files found.
libcaf_core/caf/optional.hpp
View file @
e7805402
...
...
@@ -28,6 +28,7 @@
#include "caf/config.hpp"
#include "caf/detail/safe_equal.hpp"
#include "caf/detail/scope_guard.hpp"
namespace
caf
{
...
...
@@ -230,6 +231,8 @@ class optional<T&> {
template
<
>
class
optional
<
void
>
{
public:
using
type
=
unit_t
;
optional
(
none_t
=
none
)
:
m_value
(
false
)
{
// nop
}
...
...
@@ -254,6 +257,41 @@ class optional<void> {
bool
m_value
;
};
template
<
class
Inspector
,
class
T
>
typename
std
::
enable_if
<
Inspector
::
is_saving
::
value
,
typename
Inspector
::
result_type
>::
type
inspect
(
Inspector
&
f
,
optional
<
T
>&
x
)
{
return
x
?
f
(
false
)
:
f
(
true
,
*
x
);
}
template
<
class
T
>
struct
optional_inspect_helper
{
bool
&
enabled
;
T
&
storage
;
template
<
class
Inspector
>
friend
typename
Inspector
::
result_type
inspect
(
Inspector
&
f
,
optional_inspect_helper
&
x
)
{
return
x
.
enabled
?
f
(
x
.
storage
)
:
f
();
}
};
template
<
class
Inspector
,
class
T
>
typename
std
::
enable_if
<
Inspector
::
is_loading
::
value
,
typename
Inspector
::
result_type
>::
type
inspect
(
Inspector
&
f
,
optional
<
T
>&
x
)
{
bool
flag
;
typename
optional
<
T
>::
type
tmp
;
optional_inspect_helper
<
T
>
helper
{
flag
,
tmp
};
auto
guard
=
detail
::
make_scope_guard
([
&
]
{
if
(
flag
)
x
=
std
::
move
(
tmp
);
else
x
=
none
;
});
return
f
(
flag
,
helper
);
}
/// @relates optional
template
<
class
T
>
auto
to_string
(
const
optional
<
T
>&
x
)
->
decltype
(
to_string
(
*
x
))
{
...
...
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