mirror of
https://github.com/boostorg/outcome.git
synced 2026-02-18 14:22:08 +00:00
104 lines
6.3 KiB
HTML
104 lines
6.3 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>Hooking events - Boost.Outcome documentation</title>
|
|
<link rel="stylesheet" href="/boost-outcome/css/boost.css" type="text/css">
|
|
<meta name="generator" content="Hugo with Boostdoc theme">
|
|
<meta name="viewport" content="width=device-width,initial-scale=1.0"/>
|
|
|
|
<link rel="icon" href="/boost-outcome/images/favicon.ico" type="image/ico"/>
|
|
<body><div id="boost-common-heading-doc" style="background: #574D74 url(/boost-outcome/images/header-bg.png) repeat-x top left;">
|
|
<div class="heading-inner" style="background: url(/boost-outcome/images/header-fg.png) no-repeat top left;">
|
|
<div class="heading-placard"></div>
|
|
|
|
<h1 class="heading-title">
|
|
<a href="/">
|
|
<img src="/boost-outcome/images/space.png" alt="Boost C++ Libraries" class="heading-logo" />
|
|
<span class="heading-boost">Boost</span>
|
|
<span class="heading-cpplibraries">C++ Libraries</span>
|
|
</a>
|
|
</h1>
|
|
|
|
<p class="heading-quote">
|
|
<q>...one of the most highly
|
|
regarded and expertly designed C++ library projects in the
|
|
world.</q> <span class="heading-attribution">— <a href=
|
|
"http://www.gotw.ca/" class="external">Herb Sutter</a> and <a href=
|
|
"http://en.wikipedia.org/wiki/Andrei_Alexandrescu" class="external">Andrei
|
|
Alexandrescu</a>, <a href=
|
|
"http://safari.awprofessional.com/?XmlId=0321113586" class="external">C++
|
|
Coding Standards</a></span></p>
|
|
</div>
|
|
</div>
|
|
<div id="boost-common-heading-doc-spacer"></div>
|
|
<div class="spirit-nav">
|
|
|
|
<a accesskey="u" href="/"><img src="/boost-outcome/images/up.png" alt="Up"></a>
|
|
<a accesskey="h" href="/boost-outcome/"><img src="/boost-outcome/images/home.png" alt="Home"></a>
|
|
|
|
</div><div id="content">
|
|
|
|
<p>Outcome provides multiple methods for user code to intercept various events which occur.
|
|
The deepest is simply to inherit from <code>result</code> or <code>outcome</code> and override member functions,
|
|
for which you will need to study the source code as that form of customisation is out of scope for this tutorial.
|
|
Another option is to supply a custom <code>NoValuePolicy</code> (see next section).
|
|
The final option, which this section covers, is to use the ADL discovered event hooks
|
|
which tell you when a namespace-localised <code>outcome</code> or <code>result</code> has been:</p>
|
|
|
|
<ul>
|
|
<li>Constructed
|
|
|
|
<ul>
|
|
<li><a href="https://ned14.github.io/boost-outcome/reference/result/#standardese-outcome_v2_xxx__hooks__hook_result_construction-T-U--T--U---" class="api-reference"><i class="fa fa-book" aria-hidden="true"></i> hook_result_construction(result<T, E> *this, U &&src)</a>
|
|
</li>
|
|
<li><a href="https://ned14.github.io/boost-outcome/reference/outcome/#standardese-outcome_v2_xxx__hooks__hook_outcome_construction-T-U--T--U---" class="api-reference"><i class="fa fa-book" aria-hidden="true"></i> hook_outcome_construction(outcome<T, EC, EP> *this, U &&src)</a>
|
|
</li>
|
|
</ul></li>
|
|
<li>In-place constructed
|
|
|
|
<ul>
|
|
<li><a href="https://ned14.github.io/boost-outcome/reference/result/#standardese-outcome_v2_xxx__hooks__hook_result_in_place_construction-T-U-Args--T--in_place_type_t-U--Args------" class="api-reference"><i class="fa fa-book" aria-hidden="true"></i> hook_result_in_place_construction(result<T, E> *this, in_place_type_t<T|E>, Args&&... srcs)</a>
|
|
</li>
|
|
<li><a href="https://ned14.github.io/boost-outcome/reference/outcome/#standardese-outcome_v2_xxx__hooks__hook_outcome_in_place_construction-T-U-Args--T--in_place_type_t-U--Args------" class="api-reference"><i class="fa fa-book" aria-hidden="true"></i> hook_outcome_in_place_construction(outcome<T, EC, EP> *this, in_place_type_t<T|EC|EP>, Args&&... srcs)</a>
|
|
</li>
|
|
</ul></li>
|
|
<li>Copied
|
|
|
|
<ul>
|
|
<li><a href="https://ned14.github.io/boost-outcome/reference/result/#standardese-outcome_v2_xxx__hooks__hook_result_copy_construction-T-U--T--U---" class="api-reference"><i class="fa fa-book" aria-hidden="true"></i> hook_result_copy_construction(result<T, E> *this, U &&src)</a>
|
|
</li>
|
|
<li><a href="https://ned14.github.io/boost-outcome/reference/outcome/#standardese-outcome_v2_xxx__hooks__hook_outcome_copy_construction-T-U--T--U---" class="api-reference"><i class="fa fa-book" aria-hidden="true"></i> hook_outcome_copy_construction(outcome<T, EC, EP> *this, U &&src)</a>
|
|
</li>
|
|
</ul></li>
|
|
<li>Moved
|
|
|
|
<ul>
|
|
<li><a href="https://ned14.github.io/boost-outcome/reference/result/#standardese-outcome_v2_xxx__hooks__hook_result_move_construction-T-U--T--U---" class="api-reference"><i class="fa fa-book" aria-hidden="true"></i> hook_result_move_construction(result<T, E> *this, U &&src)</a>
|
|
</li>
|
|
<li><a href="https://ned14.github.io/boost-outcome/reference/outcome/#standardese-outcome_v2_xxx__hooks__hook_outcome_move_construction-T-U--T--U---" class="api-reference"><i class="fa fa-book" aria-hidden="true"></i> hook_outcome_move_construction(outcome<T, EC, EP> *this, U &&src)</a>
|
|
</li>
|
|
</ul></li>
|
|
</ul>
|
|
|
|
<p>One criticism often levelled against these success-or-failure objects is that they do
|
|
not provide as rich a set of facilities as C++ exception throws. This section shows
|
|
you how to configure Outcome using the ADL event hooks to take a stack backtrace on
|
|
construction of an errored <code>result<T, error_code></code>,
|
|
and if that <code>result<T, error_code></code> should ever be converted into an <code>outcome<T, error_code, std::exception_ptr></code>,
|
|
a custom <code>std::exception_ptr</code> will be just-in-time synthesised consisting of the <code>std::system_error</code>
|
|
for the error code, plus an expanded message string containing the stack backtrace of where
|
|
the error originally occurred. One can see the use case for fixed latency code being built
|
|
with <code>result</code>, and it dovetailing into application code where execution time guarantees are
|
|
not important where a <code>malloc</code> is permitted.</p>
|
|
|
|
|
|
|
|
</div><p><small>Last revised: December 05, 2018 at 14:18:52 UTC</small></p>
|
|
<hr>
|
|
<div class="spirit-nav">
|
|
|
|
<a accesskey="u" href="/"><img src="/boost-outcome/images/up.png" alt="Up"></a>
|
|
<a accesskey="h" href="/boost-outcome/"><img src="/boost-outcome/images/home.png" alt="Home"></a>
|
|
|
|
</div></body>
|
|
</html>
|