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
230375b3
Commit
230375b3
authored
Jan 18, 2012
by
neverlord
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
get_or_else
parent
aba4653d
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
22 additions
and
8 deletions
+22
-8
cppa/option.hpp
cppa/option.hpp
+18
-4
cppa/tuple_cast.hpp
cppa/tuple_cast.hpp
+4
-4
No files found.
cppa/option.hpp
View file @
230375b3
#ifndef OPTION_HPP
#define OPTION_HPP
namespace
cppa
{
namespace
util
{
namespace
cppa
{
template
<
typename
What
>
class
option
...
...
@@ -36,14 +36,16 @@ class option
cr
(
std
::
forward
<
V
>
(
value
));
}
option
(
option
const
&
other
)
:
m_valid
(
other
.
m_valid
)
option
(
option
const
&
other
)
{
if
(
other
.
m_valid
)
cr
(
other
.
m_value
);
else
m_valid
=
false
;
}
option
(
option
&&
other
)
:
m_valid
(
other
.
m_valid
)
option
(
option
&&
other
)
{
if
(
other
.
m_valid
)
cr
(
std
::
move
(
other
.
m_value
));
else
m_valid
=
false
;
}
~
option
()
...
...
@@ -126,8 +128,20 @@ class option
inline
What
const
&
get
()
const
{
return
m_value
;
}
inline
What
&
get_or_else
(
What
const
&
val
)
{
if
(
!
m_valid
)
cr
(
val
);
return
m_value
;
}
inline
What
&
get_or_else
(
What
&&
val
)
{
if
(
!
m_valid
)
cr
(
std
::
move
(
val
));
return
m_value
;
}
};
}
}
// namespace cppa::util
}
// namespace cppa::util
#endif // OPTION_HPP
cppa/tuple_cast.hpp
View file @
230375b3
...
...
@@ -43,12 +43,12 @@ namespace cppa {
// cast using a pattern
template
<
typename
...
P
>
auto
tuple_cast
(
any_tuple
const
&
tup
,
pattern
<
P
...
>
const
&
p
)
->
util
::
option
<
typename
tuple_from_type_list
<
typename
pattern
<
P
...
>::
filtered_types
>::
type
>
->
option
<
typename
tuple_from_type_list
<
typename
pattern
<
P
...
>::
filtered_types
>::
type
>
{
typedef
typename
pattern
<
P
...
>::
mapping_vector
mapping_vector
;
typedef
typename
pattern
<
P
...
>::
filtered_types
filtered_types
;
typedef
typename
tuple_from_type_list
<
filtered_types
>::
type
tuple_type
;
util
::
option
<
tuple_type
>
result
;
option
<
tuple_type
>
result
;
mapping_vector
mv
;
if
(
detail
::
matches
(
detail
::
pm_decorated
(
tup
.
begin
(),
&
mv
),
p
.
begin
()))
{
...
...
@@ -66,9 +66,9 @@ auto tuple_cast(any_tuple const& tup, pattern<P...> const& p)
// cast using types
template
<
typename
...
T
>
util
::
option
<
tuple
<
T
...
>
>
tuple_cast
(
any_tuple
const
&
tup
)
option
<
tuple
<
T
...
>
>
tuple_cast
(
any_tuple
const
&
tup
)
{
util
::
option
<
tuple
<
T
...
>
>
result
;
option
<
tuple
<
T
...
>
>
result
;
auto
&
tarr
=
detail
::
static_types_array
<
T
...
>::
arr
;
if
(
tup
.
size
()
==
sizeof
...(
T
))
{
...
...
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