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
6243793a
Commit
6243793a
authored
Jan 19, 2017
by
Matthias Vallentin
Committed by
Marian Triebe
Apr 23, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Enable construction of result<T> from expected<T>
parent
03b33445
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
97 additions
and
14 deletions
+97
-14
libcaf_core/caf/result.hpp
libcaf_core/caf/result.hpp
+34
-14
libcaf_core/test/result.cpp
libcaf_core/test/result.cpp
+63
-0
No files found.
libcaf_core/caf/result.hpp
View file @
6243793a
...
@@ -24,9 +24,12 @@
...
@@ -24,9 +24,12 @@
#include "caf/none.hpp"
#include "caf/none.hpp"
#include "caf/skip.hpp"
#include "caf/skip.hpp"
#include "caf/error.hpp"
#include "caf/error.hpp"
#include "caf/expected.hpp"
#include "caf/message.hpp"
#include "caf/message.hpp"
#include "caf/delegated.hpp"
#include "caf/delegated.hpp"
#include "caf/detail/type_list.hpp"
namespace
caf
{
namespace
caf
{
enum
result_runtime_type
{
enum
result_runtime_type
{
...
@@ -48,13 +51,7 @@ public:
...
@@ -48,13 +51,7 @@ public:
init
(
std
::
move
(
x
),
std
::
move
(
xs
)...);
init
(
std
::
move
(
x
),
std
::
move
(
xs
)...);
}
}
template
<
class
E
,
template
<
class
E
,
class
=
enable_if_has_make_error_t
<
E
>
>
class
=
typename
std
::
enable_if
<
std
::
is_same
<
decltype
(
make_error
(
std
::
declval
<
const
E
&
>())),
error
>::
value
>::
type
>
result
(
E
x
)
:
flag
(
rt_error
),
err
(
make_error
(
x
))
{
result
(
E
x
)
:
flag
(
rt_error
),
err
(
make_error
(
x
))
{
// nop
// nop
}
}
...
@@ -63,6 +60,26 @@ public:
...
@@ -63,6 +60,26 @@ public:
// nop
// nop
}
}
template
<
class
T
,
class
=
typename
std
::
enable_if
<
sizeof
...(
Ts
)
==
1
&&
std
::
is_convertible
<
T
,
detail
::
tl_head_t
<
detail
::
type_list
<
Ts
...>
>
>::
value
>::
type
>
result
(
expected
<
T
>
x
)
{
if
(
x
)
{
flag
=
rt_value
;
init
(
std
::
move
(
*
x
));
}
else
{
flag
=
rt_error
;
err
=
std
::
move
(
x
.
error
());
}
}
result
(
skip_t
)
:
flag
(
rt_skip
)
{
result
(
skip_t
)
:
flag
(
rt_skip
)
{
// nop
// nop
}
}
...
@@ -100,13 +117,7 @@ public:
...
@@ -100,13 +117,7 @@ public:
// nop
// nop
}
}
template
<
class
E
,
template
<
class
E
,
class
=
enable_if_has_make_error_t
<
E
>
>
class
=
typename
std
::
enable_if
<
std
::
is_same
<
decltype
(
make_error
(
std
::
declval
<
const
E
&
>())),
error
>::
value
>::
type
>
result
(
E
x
)
:
flag
(
rt_error
),
err
(
make_error
(
x
))
{
result
(
E
x
)
:
flag
(
rt_error
),
err
(
make_error
(
x
))
{
// nop
// nop
}
}
...
@@ -115,6 +126,15 @@ public:
...
@@ -115,6 +126,15 @@ public:
// nop
// nop
}
}
result
(
expected
<
void
>
x
)
{
if
(
x
)
{
flag
=
rt_value
;
}
else
{
flag
=
rt_error
;
err
=
std
::
move
(
x
.
error
());
}
}
result
(
skip_t
)
:
flag
(
rt_skip
)
{
result
(
skip_t
)
:
flag
(
rt_skip
)
{
// nop
// nop
}
}
...
...
libcaf_core/test/result.cpp
0 → 100644
View file @
6243793a
/******************************************************************************
* ____ _ _____ *
* / ___| / \ | ___| C++ *
* | | / _ \ | |_ Actor *
* | |___ / ___ \| _| Framework *
* \____/_/ \_|_| *
* *
* Copyright (C) 2011 - 2017 *
* Dominik Charousset <dominik.charousset (at) haw-hamburg.de> *
* *
* Distributed under the terms and conditions of the BSD 3-Clause License or *
* (at your option) under the terms and conditions of the Boost Software *
* License 1.0. See accompanying files LICENSE and LICENSE_ALTERNATIVE. *
* *
* If you did not receive a copy of the license files, see *
* http://opensource.org/licenses/BSD-3-Clause and *
* http://www.boost.org/LICENSE_1_0.txt. *
******************************************************************************/
#include "caf/config.hpp"
#define CAF_SUITE result
#include "caf/test/unit_test.hpp"
#include "caf/sec.hpp"
#include "caf/result.hpp"
using
namespace
std
;
using
namespace
caf
;
CAF_TEST
(
skip
)
{
auto
x
=
result
<>
{
skip
()};
CAF_CHECK_EQUAL
(
x
.
flag
,
rt_skip
);
CAF_CHECK
(
x
.
value
.
empty
());
}
CAF_TEST
(
value
)
{
auto
x
=
result
<
int
>
{
42
};
CAF_CHECK_EQUAL
(
x
.
flag
,
rt_value
);
CAF_CHECK_EQUAL
(
x
.
value
.
get_as
<
int
>
(
0
),
42
);
}
CAF_TEST
(
expected
)
{
auto
x
=
result
<
int
>
{
expected
<
int
>
{
42
}};
CAF_CHECK_EQUAL
(
x
.
flag
,
rt_value
);
CAF_CHECK_EQUAL
(
x
.
value
.
get_as
<
int
>
(
0
),
42
);
x
=
expected
<
int
>
{
sec
::
unexpected_message
};
CAF_CHECK_EQUAL
(
x
.
flag
,
rt_error
);
CAF_CHECK_EQUAL
(
x
.
err
,
make_error
(
sec
::
unexpected_message
));
CAF_CHECK
(
x
.
value
.
empty
());
}
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
));
}
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