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
41784b43
Commit
41784b43
authored
Jun 23, 2015
by
Dominik Charousset
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use perfect forwarding when making uniform values
parent
b5474bbc
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
29 additions
and
11 deletions
+29
-11
libcaf_core/caf/uniform_type_info.hpp
libcaf_core/caf/uniform_type_info.hpp
+23
-11
libcaf_core/src/uniform_type_info.cpp
libcaf_core/src/uniform_type_info.cpp
+6
-0
No files found.
libcaf_core/caf/uniform_type_info.hpp
View file @
41784b43
...
...
@@ -41,28 +41,40 @@ class uniform_type_info;
struct
uniform_value_t
;
/// A unique pointer holding a `uniform_value_t`.
using
uniform_value
=
std
::
unique_ptr
<
uniform_value_t
>
;
/// Generic container for storing a value with associated type information.
struct
uniform_value_t
{
const
uniform_type_info
*
ti
;
void
*
val
;
uniform_value_t
(
const
uniform_type_info
*
,
void
*
);
virtual
uniform_value
copy
()
=
0
;
virtual
~
uniform_value_t
();
};
template
<
class
T
>
class
uniform_value_impl
:
public
uniform_value_t
{
public:
template
<
class
...
Ts
>
uniform_value_impl
(
const
uniform_type_info
*
ptr
,
Ts
&&
...
xs
)
:
uniform_value_t
(
ptr
,
&
value_
),
value_
(
std
::
forward
<
Ts
>
(
xs
)...)
{
// nop
}
uniform_value
copy
()
override
{
return
uniform_value
{
new
uniform_value_impl
(
ti
,
value_
)};
}
private:
T
value_
;
};
/// Creates a uniform value of type `T`.
template
<
class
T
,
class
...
Ts
>
uniform_value
make_uniform_value
(
const
uniform_type_info
*
uti
,
Ts
&&
...
xs
)
{
struct
container
:
uniform_value_t
{
T
value
;
container
(
const
uniform_type_info
*
ptr
,
T
arg
)
:
value
(
std
::
move
(
arg
))
{
ti
=
ptr
;
val
=
&
value
;
}
uniform_value
copy
()
override
{
return
uniform_value
{
new
container
(
ti
,
value
)};
}
};
return
uniform_value
{
new
container
(
uti
,
T
(
std
::
forward
<
Ts
>
(
xs
)...))};
return
uniform_value
{
new
uniform_value_impl
<
T
>
(
uti
,
std
::
forward
<
Ts
>
(
xs
)...)};
}
/// @defgroup TypeSystem Platform-independent type system.
...
...
libcaf_core/src/uniform_type_info.cpp
View file @
41784b43
...
...
@@ -54,6 +54,12 @@ inline detail::uniform_type_info_map& uti_map() {
}
// namespace <anonymous>
uniform_value_t
::
uniform_value_t
(
const
uniform_type_info
*
uti
,
void
*
vptr
)
:
ti
(
uti
),
val
(
vptr
)
{
// nop
}
uniform_value_t
::~
uniform_value_t
()
{
// nop
}
...
...
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