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
2e0c42e8
Unverified
Commit
2e0c42e8
authored
Apr 02, 2018
by
Dominik Charousset
Committed by
GitHub
Apr 02, 2018
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #680
Fix implicit conversion to result<unit_t>
parents
3e98c0ee
6bbc6101
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 @
2e0c42e8
...
@@ -126,12 +126,11 @@ public:
...
@@ -126,12 +126,11 @@ public:
}
}
result
(
expected
<
void
>
x
)
{
result
(
expected
<
void
>
x
)
{
if
(
x
)
{
init
(
x
);
flag
=
rt_value
;
}
}
else
{
flag
=
rt_error
;
result
(
expected
<
unit_t
>
x
)
{
err
=
std
::
move
(
x
.
error
());
init
(
x
);
}
}
}
result
(
skip_t
)
:
flag
(
rt_skip
)
{
result
(
skip_t
)
:
flag
(
rt_skip
)
{
...
@@ -142,10 +141,18 @@ public:
...
@@ -142,10 +141,18 @@ public:
// nop
// nop
}
}
result
(
delegated
<
unit_t
>
)
:
flag
(
rt_delegated
)
{
// nop
}
result
(
const
typed_response_promise
<
void
>&
)
:
flag
(
rt_delegated
)
{
result
(
const
typed_response_promise
<
void
>&
)
:
flag
(
rt_delegated
)
{
// nop
// nop
}
}
result
(
const
typed_response_promise
<
unit_t
>&
)
:
flag
(
rt_delegated
)
{
// nop
}
result
(
const
response_promise
&
)
:
flag
(
rt_delegated
)
{
result
(
const
response_promise
&
)
:
flag
(
rt_delegated
)
{
// nop
// nop
}
}
...
@@ -153,6 +160,17 @@ public:
...
@@ -153,6 +160,17 @@ public:
result_runtime_type
flag
;
result_runtime_type
flag
;
message
value
;
message
value
;
error
err
;
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
<
>
template
<
>
...
...
libcaf_core/test/result.cpp
View file @
2e0c42e8
...
@@ -27,6 +27,23 @@
...
@@ -27,6 +27,23 @@
using
namespace
std
;
using
namespace
std
;
using
namespace
caf
;
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
)
{
CAF_TEST
(
skip
)
{
auto
x
=
result
<>
{
skip
()};
auto
x
=
result
<>
{
skip
()};
CAF_CHECK_EQUAL
(
x
.
flag
,
rt_skip
);
CAF_CHECK_EQUAL
(
x
.
flag
,
rt_skip
);
...
@@ -50,13 +67,9 @@ CAF_TEST(expected) {
...
@@ -50,13 +67,9 @@ CAF_TEST(expected) {
}
}
CAF_TEST
(
void_specialization
)
{
CAF_TEST
(
void_specialization
)
{
auto
x
=
result
<
void
>
{};
test_unit_void
<
void
>
();
CAF_CHECK_EQUAL
(
x
.
flag
,
rt_value
);
}
x
=
skip
();
CAF_CHECK_EQUAL
(
x
.
flag
,
rt_skip
);
CAF_TEST
(
unit_specialization
)
{
x
=
expected
<
void
>
{};
test_unit_void
<
unit_t
>
();
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
));
}
}
libcaf_core/test/unit.cpp
View file @
2e0c42e8
...
@@ -28,17 +28,23 @@
...
@@ -28,17 +28,23 @@
using
namespace
caf
;
using
namespace
caf
;
using
unit_res_atom
=
atom_constant
<
atom
(
"unitRes"
)
>
;
using
unit_res_atom
=
atom_constant
<
atom
(
"unitRes"
)
>
;
using
void_res_atom
=
atom_constant
<
atom
(
"voidRes"
)
>
;
using
void_res_atom
=
atom_constant
<
atom
(
"voidRes"
)
>
;
using
unit_raw_atom
=
atom_constant
<
atom
(
"unitRaw"
)
>
;
using
unit_raw_atom
=
atom_constant
<
atom
(
"unitRaw"
)
>
;
using
void_raw_atom
=
atom_constant
<
atom
(
"voidRaw"
)
>
;
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
{
return
{
[]
(
unit_res_atom
)
->
result
<
unit_t
>
{
return
unit
;
},
[]
(
unit_res_atom
)
->
result
<
unit_t
>
{
return
unit
;
},
[]
(
void_res_atom
)
->
result
<
void
>
{
return
{};
},
[]
(
void_res_atom
)
->
result
<
void
>
{
return
{};
},
[]
(
unit_raw_atom
)
->
unit_t
{
return
unit
;
},
[]
(
unit_raw_atom
)
->
unit_t
{
return
unit
;
},
[]
(
void_raw_atom
)
->
void
{
}
[]
(
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) {
...
@@ -48,7 +54,8 @@ CAF_TEST(unit_results) {
scoped_actor
self
{
sys
};
scoped_actor
self
{
sys
};
auto
aut
=
sys
.
spawn
(
testee
);
auto
aut
=
sys
.
spawn
(
testee
);
atom_value
as
[]
=
{
unit_res_atom
::
value
,
void_res_atom
::
value
,
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
)
{
for
(
auto
a
:
as
)
{
self
->
request
(
aut
,
infinite
,
a
).
receive
(
self
->
request
(
aut
,
infinite
,
a
).
receive
(
[
&
]
{
[
&
]
{
...
@@ -60,4 +67,3 @@ CAF_TEST(unit_results) {
...
@@ -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