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