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
a7d8a39c
Commit
a7d8a39c
authored
Dec 16, 2020
by
Dominik Charousset
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add type_id_list::concat
parent
37a96d85
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
77 additions
and
25 deletions
+77
-25
libcaf_core/caf/byte.hpp
libcaf_core/caf/byte.hpp
+5
-7
libcaf_core/caf/detail/type_list.hpp
libcaf_core/caf/detail/type_list.hpp
+0
-17
libcaf_core/caf/fwd.hpp
libcaf_core/caf/fwd.hpp
+0
-1
libcaf_core/caf/type_id_list.hpp
libcaf_core/caf/type_id_list.hpp
+27
-0
libcaf_core/src/type_id_list.cpp
libcaf_core/src/type_id_list.cpp
+13
-0
libcaf_core/test/type_id_list.cpp
libcaf_core/test/type_id_list.cpp
+32
-0
No files found.
libcaf_core/caf/byte.hpp
View file @
a7d8a39c
...
...
@@ -19,8 +19,6 @@
#include <cstdint>
#include <type_traits>
#include "caf/detail/type_traits.hpp"
#pragma once
namespace
caf
{
...
...
@@ -29,31 +27,31 @@ namespace caf {
enum
class
byte
:
uint8_t
{};
template
<
class
IntegerType
,
class
=
detail
::
enable_if_tt
<
std
::
is_integral
<
IntegerType
>
>>
class
=
std
::
enable_if_t
<
std
::
is_integral
<
IntegerType
>
::
value
>>
constexpr
IntegerType
to_integer
(
byte
x
)
noexcept
{
return
static_cast
<
IntegerType
>
(
x
);
}
template
<
class
IntegerType
,
class
E
=
detail
::
enable_if_tt
<
std
::
is_integral
<
IntegerType
>
>>
class
E
=
std
::
enable_if_t
<
std
::
is_integral
<
IntegerType
>
::
value
>>
constexpr
byte
&
operator
<<=
(
byte
&
x
,
IntegerType
shift
)
noexcept
{
return
x
=
static_cast
<
byte
>
(
to_integer
<
uint8_t
>
(
x
)
<<
shift
);
}
template
<
class
IntegerType
,
class
E
=
detail
::
enable_if_tt
<
std
::
is_integral
<
IntegerType
>
>>
class
E
=
std
::
enable_if_t
<
std
::
is_integral
<
IntegerType
>
::
value
>>
constexpr
byte
operator
<<
(
byte
x
,
IntegerType
shift
)
noexcept
{
return
static_cast
<
byte
>
(
to_integer
<
uint8_t
>
(
x
)
<<
shift
);
}
template
<
class
IntegerType
,
class
E
=
detail
::
enable_if_tt
<
std
::
is_integral
<
IntegerType
>
>>
class
E
=
std
::
enable_if_t
<
std
::
is_integral
<
IntegerType
>
::
value
>>
constexpr
byte
&
operator
>>=
(
byte
&
x
,
IntegerType
shift
)
noexcept
{
return
x
=
static_cast
<
byte
>
(
to_integer
<
uint8_t
>
(
x
)
>>
shift
);
}
template
<
class
IntegerType
,
class
E
=
detail
::
enable_if_tt
<
std
::
is_integral
<
IntegerType
>
>>
class
E
=
std
::
enable_if_t
<
std
::
is_integral
<
IntegerType
>
::
value
>>
constexpr
byte
operator
>>
(
byte
x
,
IntegerType
shift
)
noexcept
{
return
static_cast
<
byte
>
(
static_cast
<
unsigned
char
>
(
x
)
>>
shift
);
}
...
...
libcaf_core/caf/detail/type_list.hpp
View file @
a7d8a39c
...
...
@@ -26,8 +26,6 @@
#include "caf/detail/type_pair.hpp"
#include "caf/fwd.hpp"
#include "caf/none.hpp"
#include "caf/type_id.hpp"
#include "caf/type_id_list.hpp"
#include "caf/unit.hpp"
namespace
caf
::
detail
{
...
...
@@ -50,21 +48,6 @@ struct strip_param<param<T>> {
using
type
=
T
;
};
template
<
class
List
>
struct
to_type_id_list_helper
;
template
<
class
...
Ts
>
struct
to_type_id_list_helper
<
type_list
<
Ts
...
>>
{
static
constexpr
type_id_list
get
()
{
return
make_type_id_list
<
typename
strip_param
<
Ts
>::
type
...
>
();
}
};
template
<
class
List
>
constexpr
type_id_list
to_type_id_list
()
{
return
to_type_id_list_helper
<
List
>::
get
();
}
/// Denotes the empty list.
using
empty_type_list
=
type_list
<>
;
...
...
libcaf_core/caf/fwd.hpp
View file @
a7d8a39c
...
...
@@ -144,7 +144,6 @@ class string_view;
class
tracing_data
;
class
tracing_data_factory
;
class
type_id_list
;
class
type_id_list_builder
;
class
uri
;
class
uri_builder
;
class
uuid
;
...
...
libcaf_core/caf/type_id_list.hpp
View file @
a7d8a39c
...
...
@@ -25,6 +25,7 @@
#include "caf/detail/comparable.hpp"
#include "caf/detail/core_export.hpp"
#include "caf/span.hpp"
#include "caf/type_id.hpp"
namespace
caf
{
...
...
@@ -92,6 +93,17 @@ public:
/// type-erased tuple for the element types stored in this list.
size_t
data_size
()
const
noexcept
;
/// Concatenates all `lists` into a single type ID list.
static
type_id_list
concat
(
span
<
type_id_list
>
lists
);
/// Concatenates all `lists` into a single type ID list.
template
<
class
...
Ts
>
static
type_id_list
concat
(
type_id_list
list1
,
type_id_list
list2
,
Ts
...
lists
)
{
type_id_list
arr
[]
=
{
list1
,
list2
,
lists
...};
return
concat
(
arr
);
}
private:
pointer
data_
;
};
...
...
@@ -132,4 +144,19 @@ type_id_list make_argument_type_id_list() {
return
argument_type_id_list_factory
<
F
>::
make
();
}
template
<
class
List
>
struct
to_type_id_list_helper
;
template
<
class
...
Ts
>
struct
to_type_id_list_helper
<
type_list
<
Ts
...
>>
{
static
constexpr
type_id_list
get
()
{
return
make_type_id_list
<
typename
strip_param
<
Ts
>::
type
...
>
();
}
};
template
<
class
List
>
constexpr
type_id_list
to_type_id_list
()
{
return
to_type_id_list_helper
<
List
>::
get
();
}
}
// namespace caf::detail
libcaf_core/src/type_id_list.cpp
View file @
a7d8a39c
...
...
@@ -19,6 +19,7 @@
#include "caf/type_id_list.hpp"
#include "caf/detail/meta_object.hpp"
#include "caf/detail/type_id_list_builder.hpp"
namespace
caf
{
...
...
@@ -49,4 +50,16 @@ std::string to_string(type_id_list xs) {
return
result
;
}
type_id_list
type_id_list
::
concat
(
span
<
type_id_list
>
lists
)
{
auto
total_size
=
size_t
{
0
};
for
(
auto
ls
:
lists
)
total_size
+=
ls
.
size
();
detail
::
type_id_list_builder
builder
;
builder
.
reserve
(
total_size
);
for
(
auto
ls
:
lists
)
for
(
auto
id
:
ls
)
builder
.
push_back
(
id
);
return
builder
.
move_to_list
();
}
}
// namespace caf
libcaf_core/test/type_id_list.cpp
View file @
a7d8a39c
...
...
@@ -59,3 +59,35 @@ CAF_TEST(type ID lists are convertible to strings) {
auto
xs
=
make_type_id_list
<
uint16_t
,
bool
,
float
,
long
double
>
();
CAF_CHECK_EQUAL
(
to_string
(
xs
),
"[uint16_t, bool, float, ldouble]"
);
}
CAF_TEST
(
type
ID
lists
are
concatenable
)
{
// 1 + 0
CHECK_EQ
((
make_type_id_list
<
int8_t
>
()),
type_id_list
::
concat
(
make_type_id_list
<
int8_t
>
(),
make_type_id_list
<>
()));
CHECK_EQ
((
make_type_id_list
<
int8_t
>
()),
type_id_list
::
concat
(
make_type_id_list
<>
(),
make_type_id_list
<
int8_t
>
()));
// 1 + 1
CHECK_EQ
((
make_type_id_list
<
int8_t
,
int16_t
>
()),
type_id_list
::
concat
(
make_type_id_list
<
int8_t
>
(),
make_type_id_list
<
int16_t
>
()));
// 2 + 0
CHECK_EQ
((
make_type_id_list
<
int8_t
,
int16_t
>
()),
type_id_list
::
concat
(
make_type_id_list
<
int8_t
,
int16_t
>
(),
make_type_id_list
<>
()));
CHECK_EQ
((
make_type_id_list
<
int8_t
,
int16_t
>
()),
type_id_list
::
concat
(
make_type_id_list
<>
(),
make_type_id_list
<
int8_t
,
int16_t
>
()));
// 2 + 1
CHECK_EQ
((
make_type_id_list
<
int8_t
,
int16_t
,
int32_t
>
()),
type_id_list
::
concat
(
make_type_id_list
<
int8_t
,
int16_t
>
(),
make_type_id_list
<
int32_t
>
()));
CHECK_EQ
((
make_type_id_list
<
int8_t
,
int16_t
,
int32_t
>
()),
type_id_list
::
concat
(
make_type_id_list
<
int8_t
>
(),
make_type_id_list
<
int16_t
,
int32_t
>
()));
// 2 + 2
CHECK_EQ
((
make_type_id_list
<
int8_t
,
int16_t
,
int32_t
,
int64_t
>
()),
type_id_list
::
concat
(
make_type_id_list
<
int8_t
,
int16_t
>
(),
make_type_id_list
<
int32_t
,
int64_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