hooks.html 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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>Hooking events - 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="../../tutorial/advanced/constructors/metaprogrammg3.html"><img src="../../images/prev.png" alt="Prev"></a>
  10. <a accesskey="u" href="../../tutorial/advanced.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="../../tutorial/advanced/hooks/keeping_state.html"><img src="../../images/next.png" alt="Next"></a></div><div id="content">
  12. <div class="titlepage"><div><div><h1 style="clear: both">Hooking events</h1></div></div></div>
  13. <p>Outcome provides multiple methods for user code to intercept various events which occur.
  14. The deepest method is simply to inherit from <code>basic_result</code> or <code>basic_outcome</code>, and override member functions,
  15. for which you will need to study the source code as that form of customisation is out of scope for this tutorial.</p>
  16. <p>Another option is to supply a custom <code>NoValuePolicy</code> which can get you surprisingly
  17. far into customisation (<a href="../../tutorial/essential/no-value/custom.html">see preceding section</a>).</p>
  18. <p>The final option, which this section covers, is to use the ADL discovered event hooks
  19. which tell you when a namespace-localised <code>basic_outcome</code> or <code>basic_result</code> has been:</p>
  20. <ul>
  21. <li>Constructed
  22. <ul>
  23. <li><a href="../../reference/functions/hooks/hook_result_construction.html" class="api-reference"><code>void hook_result_construction(T *, U &amp;&amp;) noexcept</code></a>
  24. </li>
  25. <li><a href="../../reference/functions/hooks/hook_outcome_construction.html" class="api-reference"><code>void hook_outcome_construction(T *, U &amp;&amp;) noexcept</code></a>
  26. </li>
  27. </ul></li>
  28. <li>In-place constructed
  29. <ul>
  30. <li><a href="../../reference/functions/hooks/hook_result_in_place_construction.html" class="api-reference"><code>void hook_result_in_place_construction(T *, in_place_type_t&lt;U&gt;, Args &amp;&amp;...) noexcept</code></a>
  31. </li>
  32. <li><a href="../../reference/functions/hooks/hook_outcome_in_place_construction.html" class="api-reference"><code>void hook_outcome_in_place_construction(T *, in_place_type_t&lt;U&gt;, Args &amp;&amp;...) noexcept</code></a>
  33. </li>
  34. </ul></li>
  35. <li>Copied
  36. <ul>
  37. <li><a href="../../reference/functions/hooks/hook_result_copy_construction.html" class="api-reference"><code>void hook_result_copy_construction(T *, U &amp;&amp;) noexcept</code></a>
  38. </li>
  39. <li><a href="../../reference/functions/hooks/hook_outcome_copy_construction.html" class="api-reference"><code>void hook_outcome_copy_construction(T *, U &amp;&amp;) noexcept</code></a>
  40. </li>
  41. </ul></li>
  42. <li>Moved
  43. <ul>
  44. <li><a href="../../reference/functions/hooks/hook_result_move_construction.html" class="api-reference"><code>void hook_result_move_construction(T *, U &amp;&amp;) noexcept</code></a>
  45. </li>
  46. <li><a href="../../reference/functions/hooks/hook_outcome_move_construction.html" class="api-reference"><code>void hook_outcome_move_construction(T *, U &amp;&amp;) noexcept</code></a>
  47. </li>
  48. </ul></li>
  49. </ul>
  50. <p>One criticism often levelled against library-based exception throw alternatives is that they do
  51. not provide as rich a set of facilities as C++ exception throws. This section shows
  52. you how to configure Outcome, using the ADL event hooks, to take a stack backtrace on
  53. construction of an errored <code>result&lt;T, error_code&gt;</code>,
  54. and if that <code>result&lt;T, error_code&gt;</code> should ever be converted into an <code>outcome&lt;T, error_code, std::exception_ptr&gt;</code>,
  55. a custom <code>std::exception_ptr</code> will be just-in-time synthesised consisting of the <code>std::system_error</code>
  56. for the error code, plus an expanded message string containing the stack backtrace of where
  57. the error originally occurred.</p>
  58. <p>One can see the use case for such a configuration where low-level, deterministic,
  59. fixed latency code is built with <code>result</code>, and it dovetails into higher-level
  60. application code built with <code>outcome</code> where execution time guarantees are not
  61. important, and thus where a <code>malloc</code> is okay. One effectively has constructed a
  62. &ldquo;lazy indeterminism&rdquo;, or &ldquo;just-in-time indeterminism&rdquo; mechanism for handling
  63. failure, but with all the rich information of throwing C++ exceptions.</p>
  64. </div><p><small>Last revised: February 08, 2019 at 22:18:08 UTC</small></p>
  65. <hr>
  66. <div class="spirit-nav">
  67. <a accesskey="p" href="../../tutorial/advanced/constructors/metaprogrammg3.html"><img src="../../images/prev.png" alt="Prev"></a>
  68. <a accesskey="u" href="../../tutorial/advanced.html"><img src="../../images/up.png" alt="Up"></a>
  69. <a accesskey="h" href="../../index.html"><img src="../../images/home.png" alt="Home"></a><a accesskey="n" href="../../tutorial/advanced/hooks/keeping_state.html"><img src="../../images/next.png" alt="Next"></a></div></body>
  70. </html>