• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1+++
2title = "C Macro API Reference"
3weight = 50
4+++
5
6The C macro API header `<boost/outcome/experimental/result.h>` consists of these macros:
7
8<dl>
9<dt><code>BOOST_OUTCOME_C_DECLARE_RESULT(ident, T, E)</code>
10<dd>Declares to C a <code>basic_result<T, E></code> type uniquely
11identified by <code>ident</code>. <code>T</code> is available at the
12member variable <code>.value</code>, and <code>E</code> is available
13at the member variable <code>.error</code>.
14
15<dt><code>BOOST_OUTCOME_C_RESULT(ident)</code>
16<dd>A reference to a previously declared <code>result</code> type with
17unique <code>ident</code>.
18
19<dt><code>BOOST_OUTCOME_C_RESULT_HAS_VALUE(r)</code>
20<dd>Evaluates to 1 (true) if the input <code>result</code> has a value.
21
22<dt><code>BOOST_OUTCOME_C_RESULT_HAS_ERROR(r)</code>
23<dd>Evaluates to 1 (true) if the input <code>result</code> has an error.
24
25<dt><code>BOOST_OUTCOME_C_RESULT_ERROR_IS_ERRNO(r)</code>
26<dd>Evaluates to 1 (true) if the input <code>result</code>'s error value
27is a code in the POSIX <code>errno</code> domain.
28</dl>
29
30The above let you work, somewhat awkwardly, with any C-compatible
31`basic_result<T, E>`. `basic_result<T, E>` is trivially copyable and
32standard layout if its `T` and `E` are both so, and it has the C layout:
33
34```c++
35struct cxx_result_##ident
36{
37  T value;
38  unsigned flags;
39  E error;
40};
41```
42
43### `<system_error2>` support
44
45<dl>
46<dt><code>BOOST_OUTCOME_C_DECLARE_STATUS_CODE(ident, value_type)</code>
47<dd>Declares to C a status code type with domain <code>value_type</code>
48available at the member variable <code>.value</code>. The <code>ident</code>
49must be any identifier fragment unique in this translation unit. It is
50used to uniquely identify this status code type in other macros.
51
52<dt><code>BOOST_OUTCOME_C_STATUS_CODE(ident)</code>
53<dd>A reference to a previously declared status code type with unique
54<code>ident</code>.
55</dl>
56
57There is a high likelihood that C++ functions regularly called by C
58code will return their failures either in erased `system_code`
59or in `posix_code` (i.e. `errno` code domain). Via querying the
60returned value using `BOOST_OUTCOME_C_RESULT_ERROR_IS_ERRNO(r)`, one can determine
61if the returned code is in the `errno` code domain, and thus can be
62fed to `strerror()` and so on. Therefore there are
63convenience macro APIs for those particular use cases.
64
65<dl>
66<dt><code>BOOST_OUTCOME_C_DECLARE_RESULT_ERRNO(ident, T)</code>
67<dd>Declares to C a <code>basic_result&lt;T, posix_code&gt;</code>
68type uniquely identified by <code>ident</code>.
69
70<dt><code>BOOST_OUTCOME_C_RESULT_ERRNO(ident)</code>
71<dd>A reference to a previously declared <code>basic_result&lt;T, posix_code&gt;</code>
72type with unique <code>ident</code>.
73
74<dt><code>BOOST_OUTCOME_C_DECLARE_RESULT_SYSTEM(ident, T)</code>
75<dd>Declares to C a <code>basic_result&lt;T, system_code&gt;</code>
76type uniquely identified by <code>ident</code>.
77
78<dt><code>BOOST_OUTCOME_C_RESULT_SYSTEM(ident)</code>
79<dd>A reference to a previously declared <code>basic_result&lt;T, system_code&gt;</code>
80type with unique <code>ident</code>.
81</dl>
82