worked-example.html 3.4 KB

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