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
460560ab
Commit
460560ab
authored
Nov 09, 2015
by
Dominik Charousset
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'topic/maybe-void' into develop
parents
bb712a5b
287aee75
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
95 additions
and
0 deletions
+95
-0
libcaf_core/caf/maybe.hpp
libcaf_core/caf/maybe.hpp
+82
-0
libcaf_core/test/maybe.cpp
libcaf_core/test/maybe.cpp
+13
-0
No files found.
libcaf_core/caf/maybe.hpp
View file @
460560ab
...
@@ -381,6 +381,88 @@ bool operator!=(const none_t&, const maybe<T>& val) {
...
@@ -381,6 +381,88 @@ bool operator!=(const none_t&, const maybe<T>& val) {
return
!
val
.
empty
();
return
!
val
.
empty
();
}
}
template
<
>
class
maybe
<
void
>
{
public:
using
type
=
unit_t
;
using
reference
=
const
type
&
;
using
const_reference
=
const
type
&
;
using
pointer
=
const
type
*
;
using
const_pointer
=
const
type
*
;
using
error_type
=
std
::
error_condition
;
maybe
(
const
none_t
&
=
none
)
{
}
maybe
(
error_type
err
)
:
error_
{
std
::
move
(
err
)}
{
}
maybe
&
operator
=
(
const
none_t
&
)
{
error_
=
{};
return
*
this
;
}
maybe
&
operator
=
(
const
error_type
&
err
)
{
error_
=
err
;
return
*
this
;
}
maybe
&
operator
=
(
error_type
&&
err
)
{
error_
=
std
::
move
(
err
);
return
*
this
;
}
bool
available
()
const
{
return
false
;
}
explicit
operator
bool
()
const
{
return
available
();
}
bool
operator
!
()
const
{
return
!
available
();
}
reference
get
()
{
CAF_ASSERT
(
!
"should never be called"
);
return
unit
;
}
const_reference
get
()
const
{
CAF_ASSERT
(
!
"should never be called"
);
return
unit
;
}
reference
operator
*
()
{
return
get
();
}
const_reference
operator
*
()
const
{
return
get
();
}
pointer
operator
->
()
{
return
&
get
();
}
const_pointer
operator
->
()
const
{
return
&
get
();
}
/// Returns whether this objects holds neither a value nor an actual error.
bool
empty
()
const
{
return
!
error
();
}
/// Returns the error.
const
error_type
&
error
()
const
{
CAF_ASSERT
(
!
available
());
return
error_
;
}
private:
error_type
error_
;
};
}
// namespace caf
}
// namespace caf
#endif // CAF_MAYBE_HPP
#endif // CAF_MAYBE_HPP
libcaf_core/test/maybe.cpp
View file @
460560ab
...
@@ -80,3 +80,16 @@ CAF_TEST(custom_type_engaged) {
...
@@ -80,3 +80,16 @@ CAF_TEST(custom_type_engaged) {
CAF_CHECK
(
obj
==
*
j
);
CAF_CHECK
(
obj
==
*
j
);
CAF_CHECK
(
*
j
==
obj
);
CAF_CHECK
(
*
j
==
obj
);
}
}
CAF_TEST
(
maybe_void
)
{
maybe
<
void
>
m
;
CAF_CHECK
(
!
m
);
CAF_CHECK
(
m
.
empty
());
CAF_CHECK
(
!
m
.
error
());
// Assign erroneous state.
m
=
std
::
errc
::
invalid_argument
;
CAF_CHECK
(
!
m
);
CAF_CHECK
(
!
m
.
empty
());
CAF_CHECK
(
m
.
error
());
CAF_CHECK
(
m
.
error
()
==
std
::
errc
::
invalid_argument
);
}
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