reference.html 5.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  2. <html><meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  3. <title>C Macro API Reference - Boost.Outcome documentation</title>
  4. <link rel="stylesheet" href="../../css/boost.css" type="text/css">
  5. <meta name="generator" content="Hugo 0.52 with Boostdoc theme">
  6. <meta name="viewport" content="width=device-width,initial-scale=1.0"/>
  7. <link rel="icon" href="../../images/favicon.ico" type="image/ico"/>
  8. <body><div class="spirit-nav">
  9. <a accesskey="p" href="../../experimental/c-api/example2.html"><img src="../../images/prev.png" alt="Prev"></a>
  10. <a accesskey="u" href="../../experimental/c-api.html"><img src="../../images/up.png" alt="Up"></a>
  11. <a accesskey="h" href="../../index.html"><img src="../../images/home.png" alt="Home"></a><a accesskey="n" href="../../reference.html"><img src="../../images/next.png" alt="Next"></a></div><div id="content">
  12. <div class="titlepage"><div><div><h1 style="clear: both">C Macro API Reference</h1></div></div></div>
  13. <p>The C macro API header <code>&lt;boost/outcome/experimental/result.h&gt;</code> consists of these macros:</p>
  14. <dl>
  15. <dt><code>BOOST_OUTCOME_C_DECLARE_RESULT(ident, T, E)</code>
  16. <dd>Declares to C a <code>basic_result<T, E></code> type uniquely
  17. identified by <code>ident</code>. <code>T</code> is available at the
  18. member variable <code>.value</code>, and <code>E</code> is available
  19. at the member variable <code>.error</code>.
  20. <dt><code>BOOST_OUTCOME_C_RESULT(ident)</code>
  21. <dd>A reference to a previously declared <code>result</code> type with
  22. unique <code>ident</code>.
  23. <dt><code>BOOST_OUTCOME_C_RESULT_HAS_VALUE(r)</code>
  24. <dd>Evaluates to 1 (true) if the input <code>result</code> has a value.
  25. <dt><code>BOOST_OUTCOME_C_RESULT_HAS_ERROR(r)</code>
  26. <dd>Evaluates to 1 (true) if the input <code>result</code> has an error.
  27. <dt><code>BOOST_OUTCOME_C_RESULT_ERROR_IS_ERRNO(r)</code>
  28. <dd>Evaluates to 1 (true) if the input <code>result</code>'s error value
  29. is a code in the POSIX <code>errno</code> domain.
  30. </dl>
  31. <p>The above let you work, somewhat awkwardly, with any C-compatible
  32. <code>basic_result&lt;T, E&gt;</code>. <code>basic_result&lt;T, E&gt;</code> is trivially copyable and
  33. standard layout if its <code>T</code> and <code>E</code> are both so, and it has the C layout:</p>
  34. <div class="highlight"><pre class="chroma"><code class="language-c++" data-lang="c++"><span class="k">struct</span> <span class="n">cxx_result_</span><span class="cp">##ident
  35. </span><span class="cp"></span><span class="p">{</span>
  36. <span class="n">T</span> <span class="n">value</span><span class="p">;</span>
  37. <span class="kt">unsigned</span> <span class="n">flags</span><span class="p">;</span>
  38. <span class="n">E</span> <span class="n">error</span><span class="p">;</span>
  39. <span class="p">};</span>
  40. </code></pre></div>
  41. <h3 id="system-error2-support"><code>&lt;system_error2&gt;</code> support</h3>
  42. <dl>
  43. <dt><code>BOOST_OUTCOME_C_DECLARE_STATUS_CODE(ident, value_type)</code>
  44. <dd>Declares to C a status code type with domain <code>value_type</code>
  45. available at the member variable <code>.value</code>. The <code>ident</code>
  46. must be any identifier fragment unique in this translation unit. It is
  47. used to uniquely identify this status code type in other macros.
  48. <dt><code>BOOST_OUTCOME_C_STATUS_CODE(ident)</code>
  49. <dd>A reference to a previously declared status code type with unique
  50. <code>ident</code>.
  51. </dl>
  52. <p>There is a high likelihood that C++ functions regularly called by C
  53. code will return their failures either in erased <code>system_code</code>
  54. or in <code>posix_code</code> (i.e. <code>errno</code> code domain). Via querying the
  55. returned value using <code>BOOST_OUTCOME_C_RESULT_ERROR_IS_ERRNO(r)</code>, one can determine
  56. if the returned code is in the <code>errno</code> code domain, and thus can be
  57. fed to <code>strerror()</code> and so on. Therefore there are
  58. convenience macro APIs for those particular use cases.</p>
  59. <dl>
  60. <dt><code>BOOST_OUTCOME_C_DECLARE_RESULT_ERRNO(ident, T)</code>
  61. <dd>Declares to C a <code>basic_result&lt;T, posix_code&gt;</code>
  62. type uniquely identified by <code>ident</code>.
  63. <dt><code>BOOST_OUTCOME_C_RESULT_ERRNO(ident)</code>
  64. <dd>A reference to a previously declared <code>basic_result&lt;T, posix_code&gt;</code>
  65. type with unique <code>ident</code>.
  66. <dt><code>BOOST_OUTCOME_C_DECLARE_RESULT_SYSTEM(ident, T)</code>
  67. <dd>Declares to C a <code>basic_result&lt;T, system_code&gt;</code>
  68. type uniquely identified by <code>ident</code>.
  69. <dt><code>BOOST_OUTCOME_C_RESULT_SYSTEM(ident)</code>
  70. <dd>A reference to a previously declared <code>basic_result&lt;T, system_code&gt;</code>
  71. type with unique <code>ident</code>.
  72. </dl>
  73. </div><p><small>Last revised: February 05, 2019 at 17:14:18 UTC</small></p>
  74. <hr>
  75. <div class="spirit-nav">
  76. <a accesskey="p" href="../../experimental/c-api/example2.html"><img src="../../images/prev.png" alt="Prev"></a>
  77. <a accesskey="u" href="../../experimental/c-api.html"><img src="../../images/up.png" alt="Up"></a>
  78. <a accesskey="h" href="../../index.html"><img src="../../images/home.png" alt="Home"></a><a accesskey="n" href="../../reference.html"><img src="../../images/next.png" alt="Next"></a></div></body>
  79. </html>