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
edcd27cb
Commit
edcd27cb
authored
Dec 13, 2020
by
Dominik Charousset
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix get_or with non-default template parameter
parent
5071ccb3
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
24 additions
and
6 deletions
+24
-6
libcaf_core/caf/config_value.hpp
libcaf_core/caf/config_value.hpp
+2
-3
libcaf_core/test/config_value.cpp
libcaf_core/test/config_value.cpp
+16
-1
libcaf_core/test/core-test.hpp
libcaf_core/test/core-test.hpp
+6
-2
No files found.
libcaf_core/caf/config_value.hpp
View file @
edcd27cb
...
@@ -540,11 +540,10 @@ auto get_or(const config_value& x, Fallback&& fallback) {
...
@@ -540,11 +540,10 @@ auto get_or(const config_value& x, Fallback&& fallback) {
else
else
return
guide
::
convert
(
std
::
forward
<
Fallback
>
(
fallback
));
return
guide
::
convert
(
std
::
forward
<
Fallback
>
(
fallback
));
}
else
{
}
else
{
using
value_type
=
std
::
decay_t
<
Fallback
>
;
if
(
auto
val
=
get_as
<
To
>
(
x
))
if
(
auto
val
=
get_as
<
value_type
>
(
x
))
return
std
::
move
(
*
val
);
return
std
::
move
(
*
val
);
else
else
return
std
::
forward
<
Fallback
>
(
fallback
)
;
return
To
{
std
::
forward
<
Fallback
>
(
fallback
)}
;
}
}
}
}
...
...
libcaf_core/test/config_value.cpp
View file @
edcd27cb
...
@@ -585,7 +585,7 @@ SCENARIO("get_as can convert config values to custom types") {
...
@@ -585,7 +585,7 @@ SCENARIO("get_as can convert config values to custom types") {
SCENARIO
(
"get_or converts or returns a fallback value"
)
{
SCENARIO
(
"get_or converts or returns a fallback value"
)
{
using
namespace
caf
::
literals
;
using
namespace
caf
::
literals
;
GIVEN
(
"the config value 42"
)
{
GIVEN
(
"the config value 42"
)
{
config_value
x
{
42
};
auto
x
=
config_value
{
42
};
WHEN
(
"using get_or with type int"
)
{
WHEN
(
"using get_or with type int"
)
{
THEN
(
"CAF ignores the default value"
)
{
THEN
(
"CAF ignores the default value"
)
{
CHECK_EQ
(
get_or
(
x
,
10
),
42
);
CHECK_EQ
(
get_or
(
x
,
10
),
42
);
...
@@ -610,6 +610,21 @@ SCENARIO("get_or converts or returns a fallback value") {
...
@@ -610,6 +610,21 @@ SCENARIO("get_or converts or returns a fallback value") {
CHECK_EQ
(
result
,
std
::
vector
<
int
>
({
10
,
20
,
30
}));
CHECK_EQ
(
result
,
std
::
vector
<
int
>
({
10
,
20
,
30
}));
}
}
}
}
WHEN
(
"using get_or with type i64_wrapper"
)
{
THEN
(
"CAF returns i64_wrapper{42}"
)
{
auto
result
=
get_or
<
i64_wrapper
>
(
x
,
10
);
CHECK_EQ
(
result
.
value
,
42
);
}
}
}
GIVEN
(
"the config value 'hello world'"
)
{
auto
x
=
config_value
{
"hello world"
};
WHEN
(
"using get_or with type i64_wrapper"
)
{
THEN
(
"CAF returns the fallback value"
)
{
auto
result
=
get_or
<
i64_wrapper
>
(
x
,
10
);
CHECK_EQ
(
result
.
value
,
10
);
}
}
}
}
}
}
...
...
libcaf_core/test/core-test.hpp
View file @
edcd27cb
...
@@ -83,7 +83,7 @@ struct i32_wrapper {
...
@@ -83,7 +83,7 @@ struct i32_wrapper {
template
<
class
Inspector
>
template
<
class
Inspector
>
friend
bool
inspect
(
Inspector
&
f
,
i32_wrapper
&
x
)
{
friend
bool
inspect
(
Inspector
&
f
,
i32_wrapper
&
x
)
{
return
f
.
object
(
x
).
fields
(
f
.
field
(
"value"
,
x
.
value
)
);
return
f
.
apply
(
x
.
value
);
}
}
};
};
...
@@ -97,13 +97,17 @@ struct i64_wrapper {
...
@@ -97,13 +97,17 @@ struct i64_wrapper {
++
instances
;
++
instances
;
}
}
explicit
i64_wrapper
(
int64_t
val
)
:
value
(
val
)
{
++
instances
;
}
~
i64_wrapper
()
{
~
i64_wrapper
()
{
--
instances
;
--
instances
;
}
}
template
<
class
Inspector
>
template
<
class
Inspector
>
friend
bool
inspect
(
Inspector
&
f
,
i64_wrapper
&
x
)
{
friend
bool
inspect
(
Inspector
&
f
,
i64_wrapper
&
x
)
{
return
f
.
object
(
x
).
fields
(
f
.
field
(
"value"
,
x
.
value
)
);
return
f
.
apply
(
x
.
value
);
}
}
};
};
...
...
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