• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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>Worked example: Custom domain - 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/status_result.html"><img src="../images/prev.png" alt="Prev"></a>
11    <a accesskey="u" href="../experimental.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="../experimental/worked-example/preamble.html"><img src="../images/next.png" alt="Next"></a></div><div id="content">
13
14  <div class="titlepage"><div><div><h1 style="clear: both">Worked example: Custom domain</h1></div></div></div>
15
16
17<p>Here follows a worked example of use of Experimental Outcome. It presents
18the same sample program I sent to the San Diego 2018 WG21 standards meeting
19after I was asked by the committee to demonstrate how P1095 implements P0709
20in a working code example they could study and discuss.</p>
21
22<p>We will walk through this worked example, step by step, explaining how each
23part works in detail. This will help you implement your own code based on
24Experimental Outcome.</p>
25
26<p>You may find it useful to open now in a separate browser tab the reference API
27documentation for proposed <code>&lt;system_error2&gt;</code> at <a href="https://ned14.github.io/status-code/">https://ned14.github.io/status-code/</a>
28(scroll half way down). The references in the comments to P1028 are to
29<a href="http://wg21.link/P1028">P1028 <em>SG14 status_code and standard error object for P0709 Zero-overhead
30deterministic exceptions</em></a>, which is the WG21 proposal
31paper for potential <code>&lt;system_error2&gt;</code>.</p>
32
33<h3 id="goal-of-this-section">Goal of this section</h3>
34
35<p>We are going to define a simple custom code domain which defines that
36the status code&rsquo;s payload will consist of a POSIX error code, and the
37<code>__FILE__</code> and <code>__LINE__</code> where the failure occurred. This custom status
38code will have an implicit conversion to type erased <code>error</code> defined, which dynamically
39allocates memory for the original status code, and outputs an <code>error</code>
40which manages that dynamic allocation, indirecting all queries etc
41to the erased custom status code type such that the <code>error</code> instance
42quacks as if just like the original. This demonstrates that <code>error</code> could
43just as equally convey a <code>std::exception_ptr</code>, for example, or indeed
44manage the lifetime of any pointer.</p>
45
46
47
48        </div><p><small>Last revised: January 26, 2019 at 23:38:56 UTC</small></p>
49<hr>
50<div class="spirit-nav">
51<a accesskey="p" href="../experimental/status_result.html"><img src="../images/prev.png" alt="Prev"></a>
52    <a accesskey="u" href="../experimental.html"><img src="../images/up.png" alt="Up"></a>
53    <a accesskey="h" href="../index.html"><img src="../images/home.png" alt="Home"></a><a accesskey="n" href="../experimental/worked-example/preamble.html"><img src="../images/next.png" alt="Next"></a></div></body>
54</html>
55