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
27ca7829
Commit
27ca7829
authored
Feb 07, 2013
by
Dominik Charousset
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added specialization for `option<T&>`
parent
bb38e40a
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
65 additions
and
13 deletions
+65
-13
cppa/option.hpp
cppa/option.hpp
+65
-13
No files found.
cppa/option.hpp
View file @
27ca7829
...
@@ -94,24 +94,15 @@ class option {
...
@@ -94,24 +94,15 @@ class option {
return
*
this
;
return
*
this
;
}
}
option
&
operator
=
(
const
T
&
value
)
{
if
(
m_valid
)
m_value
=
value
;
else
cr
(
value
);
return
*
this
;
}
option
&
operator
=
(
T
&
value
)
{
if
(
m_valid
)
m_value
=
std
::
move
(
value
);
else
cr
(
std
::
move
(
value
));
return
*
this
;
}
/**
/**
* @brief Returns @p true if this @p option has a valid value;
* @brief Returns @p true if this @p option has a valid value;
* otherwise @p false.
* otherwise @p false.
*/
*/
inline
bool
valid
()
const
{
return
m_valid
;
}
inline
bool
valid
()
const
{
return
m_valid
;
}
/**
* @brief Returns <tt>!valid()</tt>.
*/
inline
bool
empty
()
const
{
return
!
m_valid
;
}
inline
bool
empty
()
const
{
return
!
m_valid
;
}
/**
/**
...
@@ -120,7 +111,7 @@ class option {
...
@@ -120,7 +111,7 @@ class option {
inline
explicit
operator
bool
()
const
{
return
valid
();
}
inline
explicit
operator
bool
()
const
{
return
valid
();
}
/**
/**
* @brief Returns <tt>!valid()</tt>
* @brief Returns <tt>!valid()</tt>
.
*/
*/
inline
bool
operator
!
()
const
{
return
empty
();
}
inline
bool
operator
!
()
const
{
return
empty
();
}
...
@@ -187,6 +178,67 @@ class option {
...
@@ -187,6 +178,67 @@ class option {
};
};
template
<
typename
T
>
class
option
<
T
&>
{
public:
typedef
T
type
;
option
()
:
m_value
(
nullptr
)
{
}
option
(
T
&
value
)
:
m_value
(
&
value
)
{
}
option
(
const
option
&
other
)
=
default
;
option
&
operator
=
(
const
option
&
other
)
=
default
;
inline
bool
valid
()
const
{
return
m_value
!=
nullptr
;
}
inline
bool
empty
()
const
{
return
!
valid
();
}
inline
explicit
operator
bool
()
const
{
return
valid
();
}
inline
bool
operator
!
()
const
{
return
empty
();
}
inline
T
&
operator
*
()
{
CPPA_REQUIRE
(
valid
());
return
*
m_value
;
}
inline
const
T
&
operator
*
()
const
{
CPPA_REQUIRE
(
valid
());
return
*
m_value
;
}
inline
T
&
get
()
{
CPPA_REQUIRE
(
valid
());
return
*
m_value
;
}
inline
const
T
&
get
()
const
{
CPPA_REQUIRE
(
valid
());
return
*
m_value
;
}
inline
const
T
&
get_or_else
(
const
T
&
default_value
)
const
{
if
(
valid
())
return
get
();
return
default_value
;
}
private:
T
*
m_value
;
};
/** @relates option */
template
<
typename
T
>
struct
is_option
{
static
constexpr
bool
value
=
false
;
};
template
<
typename
T
>
struct
is_option
<
option
<
T
>>
{
static
constexpr
bool
value
=
true
;
};
/** @relates option */
/** @relates option */
template
<
typename
T
,
typename
U
>
template
<
typename
T
,
typename
U
>
bool
operator
==
(
const
option
<
T
>&
lhs
,
const
option
<
U
>&
rhs
)
{
bool
operator
==
(
const
option
<
T
>&
lhs
,
const
option
<
U
>&
rhs
)
{
...
...
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