C Results
The C macro API header <boost/outcome/experimental/result.h>
has some macros for working with any kind of Result:
BOOST_OUTCOME_C_DECLARE_RESULT(ident, T, E)
- Declares to C a
basic_result
type uniquely identified byident
.T
is available at the member variable.value
, andE
is available at the member variable.error
. If you call this from within C++, make SURE it is not within aextern "C"
block! BOOST_OUTCOME_C_RESULT(ident)
- A reference to a previously declared
result
type with uniqueident
. BOOST_OUTCOME_C_RESULT_HAS_VALUE(r)
- Evaluates to 1 (true) if the input
result
has a value. BOOST_OUTCOME_C_RESULT_HAS_ERROR(r)
- Evaluates to 1 (true) if the input
result
has an error. BOOST_OUTCOME_C_RESULT_ERROR_IS_ERRNO(r)
- Evaluates to 1 (true) if the input
result
's error value is a code in the POSIXerrno
domain.
The above let you work, somewhat awkwardly, with any C-compatible
basic_result<T, E>
. basic_result<T, E>
is trivially copyable and
standard layout if its T
and E
are both so, and it has the C layout:
struct cxx_result_##ident
{
union
{
T value;
E error;
};
unsigned flags;
};
Note that this layout is different to that of BOOST_OUTCOME_C_DECLARE_STATUS_CODE
as the C++ result
has a different layout if E
is a status code.