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
c6d63bb7
Commit
c6d63bb7
authored
Sep 17, 2018
by
Dominik Charousset
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implement noexcept-correctness for variant
parent
608879a9
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
48 additions
and
19 deletions
+48
-19
libcaf_core/caf/variant.hpp
libcaf_core/caf/variant.hpp
+48
-19
No files found.
libcaf_core/caf/variant.hpp
View file @
c6d63bb7
...
...
@@ -118,10 +118,34 @@ using variant_visit_result_t =
template
<
class
...
Ts
>
class
variant
{
public:
// -- member types -----------------------------------------------------------
using
types
=
detail
::
type_list
<
Ts
...
>
;
using
type0
=
typename
detail
::
tl_at
<
types
,
0
>::
type
;
// -- constants --------------------------------------------------------------
/// Stores the ID for the last type.
static
constexpr
int
max_type_id
=
sizeof
...(
Ts
)
-
1
;
/// Stores whether all types are nothrow constructible.
static
constexpr
bool
nothrow_move_construct
=
detail
::
conjunction
<
std
::
is_nothrow_move_constructible
<
Ts
>::
value
...
>::
value
;
/// Stores whether all types are nothrow assignable *and* constructible. We
/// need to check both, since assigning to a variant results in a
/// move-contruct unless the before and after types are the same.
static
constexpr
bool
nothrow_move_assign
=
nothrow_move_construct
&&
detail
::
conjunction
<
std
::
is_nothrow_move_assignable
<
Ts
>::
value
...
>::
value
;
// -- sanity checks ----------------------------------------------------------
static_assert
(
sizeof
...(
Ts
)
<=
20
,
"Too many template arguments given."
);
static_assert
(
sizeof
...(
Ts
)
>
0
,
"No template argument given."
);
...
...
@@ -129,19 +153,7 @@ public:
static_assert
(
!
detail
::
tl_exists
<
types
,
std
::
is_reference
>::
value
,
"Cannot create a variant of references"
);
using
type0
=
typename
detail
::
tl_at
<
types
,
0
>::
type
;
variant
&
operator
=
(
const
variant
&
other
)
{
variant_assign_helper
<
variant
>
helper
{
*
this
};
other
.
template
apply
<
void
>(
helper
);
return
*
this
;
}
variant
&
operator
=
(
variant
&&
other
)
{
variant_move_helper
<
variant
>
helper
{
*
this
};
other
.
template
apply
<
void
>(
helper
);
return
*
this
;
}
// -- constructors, destructors, and assignment operators --------------------
variant
()
:
type_
(
variant_npos
)
{
// Never empty ...
...
...
@@ -151,14 +163,16 @@ public:
}
template
<
class
U
>
variant
(
U
&&
arg
)
:
type_
(
variant_npos
)
{
variant
(
U
&&
arg
)
noexcept
(
std
::
is_rvalue_reference
<
U
&&>::
value
&&
nothrow_move_assign
)
:
type_
(
variant_npos
)
{
set
(
std
::
forward
<
U
>
(
arg
));
}
template
<
class
U
>
variant
&
operator
=
(
U
&&
arg
)
{
set
(
std
::
forward
<
U
>
(
arg
))
;
return
*
this
;
variant
(
variant
&&
other
)
noexcept
(
nothrow_move_construct
)
:
type_
(
variant_npos
)
{
variant_move_helper
<
variant
>
helper
{
*
this
}
;
other
.
template
apply
<
void
>(
helper
)
;
}
variant
(
const
variant
&
other
)
:
type_
(
variant_npos
)
{
...
...
@@ -166,15 +180,30 @@ public:
other
.
template
apply
<
void
>(
helper
);
}
variant
(
variant
&&
other
)
:
type_
(
variant_npos
)
{
variant
&
operator
=
(
const
variant
&
other
)
{
variant_assign_helper
<
variant
>
helper
{
*
this
};
other
.
template
apply
<
void
>(
helper
);
return
*
this
;
}
variant
&
operator
=
(
variant
&&
other
)
noexcept
(
nothrow_move_assign
)
{
variant_move_helper
<
variant
>
helper
{
*
this
};
other
.
template
apply
<
void
>(
helper
);
return
*
this
;
}
template
<
class
U
>
variant
&
operator
=
(
U
&&
arg
)
noexcept
(
nothrow_move_assign
)
{
set
(
std
::
forward
<
U
>
(
arg
));
return
*
this
;
}
~
variant
()
{
destroy_data
();
}
// -- properties -------------------------------------------------------------
constexpr
size_t
index
()
const
{
return
static_cast
<
size_t
>
(
type_
);
}
...
...
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