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
6bbc6101
Commit
6bbc6101
authored
Mar 31, 2018
by
Marian Triebe
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix implicit conversion to result<unit_t>
closes #679
parent
9205f6fa
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
63 additions
and
26 deletions
+63
-26
libcaf_core/caf/result.hpp
libcaf_core/caf/result.hpp
+24
-6
libcaf_core/test/result.cpp
libcaf_core/test/result.cpp
+22
-9
libcaf_core/test/unit.cpp
libcaf_core/test/unit.cpp
+17
-11
No files found.
libcaf_core/caf/result.hpp
View file @
6bbc6101
...
...
@@ -126,12 +126,11 @@ public:
}
result
(
expected
<
void
>
x
)
{
if
(
x
)
{
flag
=
rt_value
;
}
else
{
flag
=
rt_error
;
err
=
std
::
move
(
x
.
error
());
}
init
(
x
);
}
result
(
expected
<
unit_t
>
x
)
{
init
(
x
);
}
result
(
skip_t
)
:
flag
(
rt_skip
)
{
...
...
@@ -142,10 +141,18 @@ public:
// nop
}
result
(
delegated
<
unit_t
>
)
:
flag
(
rt_delegated
)
{
// nop
}
result
(
const
typed_response_promise
<
void
>&
)
:
flag
(
rt_delegated
)
{
// nop
}
result
(
const
typed_response_promise
<
unit_t
>&
)
:
flag
(
rt_delegated
)
{
// nop
}
result
(
const
response_promise
&
)
:
flag
(
rt_delegated
)
{
// nop
}
...
...
@@ -153,6 +160,17 @@ public:
result_runtime_type
flag
;
message
value
;
error
err
;
private:
template
<
class
T
>
void
init
(
T
&
x
)
{
if
(
x
)
{
flag
=
rt_value
;
}
else
{
flag
=
rt_error
;
err
=
std
::
move
(
x
.
error
());
}
}
};
template
<
>
...
...
libcaf_core/test/result.cpp
View file @
6bbc6101
...
...
@@ -27,6 +27,23 @@
using
namespace
std
;
using
namespace
caf
;
namespace
{
template
<
class
T
>
void
test_unit_void
()
{
auto
x
=
result
<
T
>
{};
CAF_CHECK_EQUAL
(
x
.
flag
,
rt_value
);
x
=
skip
();
CAF_CHECK_EQUAL
(
x
.
flag
,
rt_skip
);
x
=
expected
<
T
>
{};
CAF_CHECK_EQUAL
(
x
.
flag
,
rt_value
);
x
=
expected
<
T
>
{
sec
::
unexpected_message
};
CAF_CHECK_EQUAL
(
x
.
flag
,
rt_error
);
CAF_CHECK_EQUAL
(
x
.
err
,
make_error
(
sec
::
unexpected_message
));
}
}
// namespace anonymous
CAF_TEST
(
skip
)
{
auto
x
=
result
<>
{
skip
()};
CAF_CHECK_EQUAL
(
x
.
flag
,
rt_skip
);
...
...
@@ -50,13 +67,9 @@ CAF_TEST(expected) {
}
CAF_TEST
(
void_specialization
)
{
auto
x
=
result
<
void
>
{};
CAF_CHECK_EQUAL
(
x
.
flag
,
rt_value
);
x
=
skip
();
CAF_CHECK_EQUAL
(
x
.
flag
,
rt_skip
);
x
=
expected
<
void
>
{};
CAF_CHECK_EQUAL
(
x
.
flag
,
rt_value
);
x
=
expected
<
void
>
{
sec
::
unexpected_message
};
CAF_CHECK_EQUAL
(
x
.
flag
,
rt_error
);
CAF_CHECK_EQUAL
(
x
.
err
,
make_error
(
sec
::
unexpected_message
));
test_unit_void
<
void
>
();
}
CAF_TEST
(
unit_specialization
)
{
test_unit_void
<
unit_t
>
();
}
libcaf_core/test/unit.cpp
View file @
6bbc6101
...
...
@@ -28,17 +28,23 @@
using
namespace
caf
;
using
unit_res_atom
=
atom_constant
<
atom
(
"unitRes"
)
>
;
using
void_res_atom
=
atom_constant
<
atom
(
"voidRes"
)
>
;
using
unit_raw_atom
=
atom_constant
<
atom
(
"unitRaw"
)
>
;
using
void_raw_atom
=
atom_constant
<
atom
(
"voidRaw"
)
>
;
using
unit_res_atom
=
atom_constant
<
atom
(
"unitRes"
)
>
;
using
void_res_atom
=
atom_constant
<
atom
(
"voidRes"
)
>
;
using
unit_raw_atom
=
atom_constant
<
atom
(
"unitRaw"
)
>
;
using
void_raw_atom
=
atom_constant
<
atom
(
"voidRaw"
)
>
;
using
typed_unit_atom
=
atom_constant
<
atom
(
"typedUnit"
)
>
;
behavior
testee
(
event_based_actor
*
)
{
behavior
testee
(
event_based_actor
*
self
)
{
return
{
[]
(
unit_res_atom
)
->
result
<
unit_t
>
{
return
unit
;
},
[]
(
void_res_atom
)
->
result
<
void
>
{
return
{};
},
[]
(
unit_raw_atom
)
->
unit_t
{
return
unit
;
},
[]
(
void_raw_atom
)
->
void
{
}
[]
(
unit_res_atom
)
->
result
<
unit_t
>
{
return
unit
;
},
[]
(
void_res_atom
)
->
result
<
void
>
{
return
{};
},
[]
(
unit_raw_atom
)
->
unit_t
{
return
unit
;
},
[]
(
void_raw_atom
)
->
void
{
},
[
=
](
typed_unit_atom
)
->
result
<
unit_t
>
{
auto
rp
=
self
->
make_response_promise
<
unit_t
>
();
rp
.
deliver
(
unit
);
return
rp
;
}
};
}
...
...
@@ -48,7 +54,8 @@ CAF_TEST(unit_results) {
scoped_actor
self
{
sys
};
auto
aut
=
sys
.
spawn
(
testee
);
atom_value
as
[]
=
{
unit_res_atom
::
value
,
void_res_atom
::
value
,
unit_raw_atom
::
value
,
void_raw_atom
::
value
};
unit_raw_atom
::
value
,
void_raw_atom
::
value
,
typed_unit_atom
::
value
};
for
(
auto
a
:
as
)
{
self
->
request
(
aut
,
infinite
,
a
).
receive
(
[
&
]
{
...
...
@@ -60,4 +67,3 @@ CAF_TEST(unit_results) {
);
}
}
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