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
d5e0477d
Commit
d5e0477d
authored
Jun 23, 2018
by
Dominik Charousset
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Support immutable sum types
parent
ac6b8041
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
22 additions
and
3 deletions
+22
-3
libcaf_core/caf/default_sum_type_access.hpp
libcaf_core/caf/default_sum_type_access.hpp
+2
-0
libcaf_core/caf/sum_type.hpp
libcaf_core/caf/sum_type.hpp
+9
-2
libcaf_core/caf/sum_type_access.hpp
libcaf_core/caf/sum_type_access.hpp
+11
-1
No files found.
libcaf_core/caf/default_sum_type_access.hpp
View file @
d5e0477d
...
...
@@ -36,6 +36,8 @@ struct default_sum_type_access {
static
constexpr
bool
specialized
=
true
;
static
constexpr
bool
is_mutable
=
true
;
template
<
int
Pos
>
static
bool
is
(
const
T
&
x
,
std
::
integral_constant
<
int
,
Pos
>
token
)
{
return
x
.
get_data
().
is
(
token
);
...
...
libcaf_core/caf/sum_type.hpp
View file @
d5e0477d
...
...
@@ -31,6 +31,13 @@ constexpr bool SumType() {
return
has_sum_type_access
<
typename
std
::
decay
<
T
>::
type
>::
value
;
}
/// Concept for checking whether `T` supports the sum type API by specializing
/// `sum_type_access` and grants non-const element access.
template
<
class
T
>
constexpr
bool
MutableSumType
()
{
return
has_mutable_sum_type_access
<
typename
std
::
decay
<
T
>::
type
>::
value
;
}
/// Concept for checking whether all `Ts` support the sum type API by
/// specializing `sum_type_access`.
template
<
class
...
Ts
>
...
...
@@ -44,7 +51,7 @@ constexpr bool SumTypes() {
/// @pre `holds_alternative<T>(x)`
/// @relates SumType
template
<
class
T
,
class
U
>
detail
::
enable_if_t
<
SumType
<
U
>
(),
T
&>
get
(
U
&
x
)
{
detail
::
enable_if_t
<
Mutable
SumType
<
U
>
(),
T
&>
get
(
U
&
x
)
{
using
namespace
detail
;
using
trait
=
sum_type_access
<
U
>
;
int_token
<
tl_index_where
<
typename
trait
::
types
,
...
...
@@ -72,7 +79,7 @@ detail::enable_if_t<SumType<U>(), const T&> get(const U& x) {
/// `nullptr` otherwise.
/// @relates SumType
template
<
class
T
,
class
U
>
detail
::
enable_if_t
<
SumType
<
U
>
(),
T
*>
get_if
(
U
*
x
)
{
detail
::
enable_if_t
<
Mutable
SumType
<
U
>
(),
T
*>
get_if
(
U
*
x
)
{
using
namespace
detail
;
using
trait
=
sum_type_access
<
U
>
;
int_token
<
tl_index_where
<
typename
trait
::
types
,
...
...
libcaf_core/caf/sum_type_access.hpp
View file @
d5e0477d
...
...
@@ -28,13 +28,23 @@ namespace caf {
template
<
class
T
>
struct
sum_type_access
{
static
constexpr
bool
specialized
=
false
;
static
constexpr
bool
is_mutable
=
false
;
};
/// Evaluates to `true` if `T` specializes `sum_type_access`
/// Evaluates to `true` if `T` specializes `sum_type_access`
.
/// @relates SumType
template
<
class
T
>
struct
has_sum_type_access
{
static
constexpr
bool
value
=
sum_type_access
<
T
>::
specialized
;
};
/// Evaluates to `true` if `T` specializes `sum_type_access` and allows
/// non-const element access.
/// @relates SumType
template
<
class
T
>
struct
has_mutable_sum_type_access
{
static
constexpr
bool
value
=
sum_type_access
<
T
>::
specialized
&&
sum_type_access
<
T
>::
is_mutable
;
};
}
// namespace caf
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