55 lines
4.9 KiB
HTML
55 lines
4.9 KiB
HTML
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
|
|
<html><meta http-equiv="Content-Type" content="text/html; charset=utf-8">
|
|
<title>Define a custom code domain - Boost.Outcome documentation</title>
|
|
<link rel="stylesheet" href="../../css/boost.css" type="text/css">
|
|
<meta name="generator" content="Hugo 0.52 with Boostdoc theme">
|
|
<meta name="viewport" content="width=device-width,initial-scale=1.0"/>
|
|
|
|
<link rel="icon" href="../../images/favicon.ico" type="image/ico"/>
|
|
<body><div class="spirit-nav">
|
|
<a accesskey="p" href="../../experimental/worked-example.html"><img src="../../images/prev.png" alt="Prev"></a>
|
|
<a accesskey="u" href="../../experimental/worked-example.html"><img src="../../images/up.png" alt="Up"></a>
|
|
<a accesskey="h" href="../../index.html"><img src="../../images/home.png" alt="Home"></a><a accesskey="n" href="../../experimental/worked-example/value_type.html"><img src="../../images/next.png" alt="Next"></a></div><div id="content">
|
|
<div class="titlepage"><div><div><h1 style="clear: both">Define a custom code domain</h1></div></div></div>
|
|
<p>Firstly let’s alias the experimental Outcome namespace into something
|
|
less tedious to type, declare our custom status code type, and get
|
|
started on defining the custom status code domain implementation.</p>
|
|
|
|
<div class="code-snippet"><div class="highlight"><pre class="chroma"><code class="language-c++" data-lang="c++"><span class="k">namespace</span> <span class="n">outcome_e</span> <span class="o">=</span> <span class="n">BOOST_OUTCOME_V2_NAMESPACE</span><span class="o">::</span><span class="n">experimental</span><span class="p">;</span>
|
|
|
|
<span class="c1">// To define a `file_io_error` which participates in the P1028 world
|
|
</span><span class="c1">// of `std::error`, we must first declare, then define, a custom code
|
|
</span><span class="c1">// domain which extends `posix_code` (the std error coding for POSIX
|
|
</span><span class="c1">// failures). The following is fairly standard boilerplate for defining
|
|
</span><span class="c1">// a custom code domain. It is analogous to defining a custom `std::error_category`.
|
|
</span><span class="c1"></span>
|
|
<span class="k">class</span><span class="err"> </span><span class="nc">_file_io_error_domain</span><span class="p">;</span>
|
|
<span class="c1">// We define `file_io_error` to be the status code whose domain is `_file_io_error_domain`.
|
|
</span><span class="c1"></span><span class="k">using</span> <span class="n">file_io_error</span> <span class="o">=</span> <span class="n">outcome_e</span><span class="o">::</span><span class="n">status_code</span><span class="o"><</span><span class="n">_file_io_error_domain</span><span class="o">></span><span class="p">;</span>
|
|
|
|
<span class="c1">// Now we define `_file_io_error_domain`.
|
|
</span><span class="c1"></span><span class="k">class</span><span class="err"> </span><span class="nc">_file_io_error_domain</span> <span class="o">:</span> <span class="k">public</span> <span class="n">outcome_e</span><span class="o">::</span><span class="n">posix_code</span><span class="o">::</span><span class="n">domain_type</span>
|
|
<span class="p">{</span>
|
|
<span class="k">using</span> <span class="n">_base</span> <span class="o">=</span> <span class="k">typename</span> <span class="n">outcome_e</span><span class="o">::</span><span class="n">posix_code</span><span class="o">::</span><span class="n">domain_type</span><span class="p">;</span>
|
|
</code></pre></div><a href="https://github.com/boostorg/outcome/tree/master/doc/src/snippets/experimental_status_code.cpp#L65" class="code-snippet-url" target="_blank">View this code on Github</a></div>
|
|
|
|
|
|
<p>Note that we inherit from <code>outcome_e::posix_code::domain_type</code>, not
|
|
from <code>outcome_e::status_code_domain</code>. We thus reuse most of the
|
|
implementation of <code>outcome_e::posix_code::domain_type</code> rather than
|
|
implementing required functionality. If you would like to see a
|
|
fuller treatment of defining a custom status code domain from
|
|
scratch, see <a href="https://github.com/ned14/status-code/blob/master/doc/custom_domain_worked_example.md">this worked example here</a>.</p>
|
|
|
|
<p><a href="https://ned14.github.io/status-code/doc_status_code_domain.html#standardese-system_error2__status_code_domain">You may find looking at the API reference documentation for <code>status_code_domain</code>
|
|
useful in the next few pages </a>.</p>
|
|
|
|
|
|
</div><p><small>Last revised: January 26, 2019 at 23:38:56 UTC</small></p>
|
|
<hr>
|
|
<div class="spirit-nav">
|
|
<a accesskey="p" href="../../experimental/worked-example.html"><img src="../../images/prev.png" alt="Prev"></a>
|
|
<a accesskey="u" href="../../experimental/worked-example.html"><img src="../../images/up.png" alt="Up"></a>
|
|
<a accesskey="h" href="../../index.html"><img src="../../images/home.png" alt="Home"></a><a accesskey="n" href="../../experimental/worked-example/value_type.html"><img src="../../images/next.png" alt="Next"></a></div></body>
|
|
</html>
|