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 8<link rel="icon" href="../../images/favicon.ico" type="image/ico"/> 9<body><div class="spirit-nav"> 10<a accesskey="p" href="../../experimental/c-api/example2.html"><img src="../../images/prev.png" alt="Prev"></a> 11 <a accesskey="u" href="../../experimental/c-api.html"><img src="../../images/up.png" alt="Up"></a> 12 <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"> 13 <div class="titlepage"><div><div><h1 style="clear: both">C Macro API Reference</h1></div></div></div> 14 15 16<p>The C macro API header <code><boost/outcome/experimental/result.h></code> consists of these macros:</p> 17 18<dl> 19<dt><code>BOOST_OUTCOME_C_DECLARE_RESULT(ident, T, E)</code> 20<dd>Declares to C a <code>basic_result<T, E></code> type uniquely 21identified by <code>ident</code>. <code>T</code> is available at the 22member variable <code>.value</code>, and <code>E</code> is available 23at the member variable <code>.error</code>. 24 25<dt><code>BOOST_OUTCOME_C_RESULT(ident)</code> 26<dd>A reference to a previously declared <code>result</code> type with 27unique <code>ident</code>. 28 29<dt><code>BOOST_OUTCOME_C_RESULT_HAS_VALUE(r)</code> 30<dd>Evaluates to 1 (true) if the input <code>result</code> has a value. 31 32<dt><code>BOOST_OUTCOME_C_RESULT_HAS_ERROR(r)</code> 33<dd>Evaluates to 1 (true) if the input <code>result</code> has an error. 34 35<dt><code>BOOST_OUTCOME_C_RESULT_ERROR_IS_ERRNO(r)</code> 36<dd>Evaluates to 1 (true) if the input <code>result</code>'s error value 37is a code in the POSIX <code>errno</code> domain. 38</dl> 39 40<p>The above let you work, somewhat awkwardly, with any C-compatible 41<code>basic_result<T, E></code>. <code>basic_result<T, E></code> is trivially copyable and 42standard layout if its <code>T</code> and <code>E</code> are both so, and it has the C layout:</p> 43<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 44</span><span class="cp"></span><span class="p">{</span> 45 <span class="n">T</span> <span class="n">value</span><span class="p">;</span> 46 <span class="kt">unsigned</span> <span class="n">flags</span><span class="p">;</span> 47 <span class="n">E</span> <span class="n">error</span><span class="p">;</span> 48<span class="p">};</span> 49</code></pre></div> 50<h3 id="system-error2-support"><code><system_error2></code> support</h3> 51 52<dl> 53<dt><code>BOOST_OUTCOME_C_DECLARE_STATUS_CODE(ident, value_type)</code> 54<dd>Declares to C a status code type with domain <code>value_type</code> 55available at the member variable <code>.value</code>. The <code>ident</code> 56must be any identifier fragment unique in this translation unit. It is 57used to uniquely identify this status code type in other macros. 58 59<dt><code>BOOST_OUTCOME_C_STATUS_CODE(ident)</code> 60<dd>A reference to a previously declared status code type with unique 61<code>ident</code>. 62</dl> 63 64<p>There is a high likelihood that C++ functions regularly called by C 65code will return their failures either in erased <code>system_code</code> 66or in <code>posix_code</code> (i.e. <code>errno</code> code domain). Via querying the 67returned value using <code>BOOST_OUTCOME_C_RESULT_ERROR_IS_ERRNO(r)</code>, one can determine 68if the returned code is in the <code>errno</code> code domain, and thus can be 69fed to <code>strerror()</code> and so on. Therefore there are 70convenience macro APIs for those particular use cases.</p> 71 72<dl> 73<dt><code>BOOST_OUTCOME_C_DECLARE_RESULT_ERRNO(ident, T)</code> 74<dd>Declares to C a <code>basic_result<T, posix_code></code> 75type uniquely identified by <code>ident</code>. 76 77<dt><code>BOOST_OUTCOME_C_RESULT_ERRNO(ident)</code> 78<dd>A reference to a previously declared <code>basic_result<T, posix_code></code> 79type with unique <code>ident</code>. 80 81<dt><code>BOOST_OUTCOME_C_DECLARE_RESULT_SYSTEM(ident, T)</code> 82<dd>Declares to C a <code>basic_result<T, system_code></code> 83type uniquely identified by <code>ident</code>. 84 85<dt><code>BOOST_OUTCOME_C_RESULT_SYSTEM(ident)</code> 86<dd>A reference to a previously declared <code>basic_result<T, system_code></code> 87type with unique <code>ident</code>. 88</dl> 89 90 91 </div><p><small>Last revised: February 05, 2019 at 17:14:18 UTC</small></p> 92<hr> 93<div class="spirit-nav"> 94<a accesskey="p" href="../../experimental/c-api/example2.html"><img src="../../images/prev.png" alt="Prev"></a> 95 <a accesskey="u" href="../../experimental/c-api.html"><img src="../../images/up.png" alt="Up"></a> 96 <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> 97</html> 98