• 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>ADL bridging - 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/hooks/keeping_state.html"><img src="../../../images/prev.png" alt="Prev"></a>
11    <a accesskey="u" href="../../../tutorial/advanced/hooks.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/hook_result.html"><img src="../../../images/next.png" alt="Next"></a></div><div id="content">
13  <div class="titlepage"><div><div><h1 style="clear: both">ADL bridging</h1></div></div></div>
14  <p>In a previous section, we used the <code>failure_info</code> type to create
15the ADL bridge into the namespace where the ADL discovered <a href="../../../reference/functions/policy.html"><code>outcome_throw_as_system_error_with_payload()</code></a> function was to be found.</p>
16
17<p>Here we do the same, but more directly by creating a thin clone of <code>std::error_code</code>
18into the local namespace. This ensures that this namespace will be searched by the
19compiler when discovering the event hooks.</p>
20
21<div class="code-snippet"><div class="highlight"><pre class="chroma"><code class="language-c++" data-lang="c++"><span class="k">namespace</span> <span class="n">error_code_extended</span>
22<span class="p">{</span>
23  <span class="c1">// Use the error_code type as the ADL bridge for the hooks by creating a type here
24</span><span class="c1"></span>  <span class="c1">// It can be any type that your localised result uses, including the value type but
25</span><span class="c1"></span>  <span class="c1">// by localising the error code type here you prevent nasty surprises later when the
26</span><span class="c1"></span>  <span class="c1">// value type you use doesn&#39;t trigger the ADL bridge.
27</span><span class="c1"></span>  <span class="k">struct</span> <span class="nl">error_code</span> <span class="p">:</span> <span class="k">public</span> <span class="n">std</span><span class="o">::</span><span class="n">error_code</span>
28  <span class="p">{</span>
29    <span class="c1">// literally passthrough
30</span><span class="c1"></span>    <span class="k">using</span> <span class="n">std</span><span class="o">::</span><span class="n">error_code</span><span class="o">::</span><span class="n">error_code</span><span class="p">;</span>
31    <span class="n">error_code</span><span class="p">()</span> <span class="o">=</span> <span class="k">default</span><span class="p">;</span>
32    <span class="n">error_code</span><span class="p">(</span><span class="n">std</span><span class="o">::</span><span class="n">error_code</span> <span class="n">ec</span><span class="p">)</span>
33        <span class="o">:</span> <span class="n">std</span><span class="o">::</span><span class="n">error_code</span><span class="p">(</span><span class="n">ec</span><span class="p">)</span>
34    <span class="p">{</span>
35    <span class="p">}</span>
36  <span class="p">};</span>
37
38  <span class="c1">// Localise result and outcome to using the local error_code so this namespace gets looked up for the hooks
39</span><span class="c1"></span>  <span class="k">template</span> <span class="o">&lt;</span><span class="k">class</span><span class="err"> </span><span class="nc">R</span><span class="o">&gt;</span> <span class="k">using</span> <span class="n">result</span> <span class="o">=</span> <span class="n">BOOST_OUTCOME_V2_NAMESPACE</span><span class="o">::</span><span class="n">result</span><span class="o">&lt;</span><span class="n">R</span><span class="p">,</span> <span class="n">error_code</span><span class="o">&gt;</span><span class="p">;</span>
40  <span class="k">template</span> <span class="o">&lt;</span><span class="k">class</span><span class="err"> </span><span class="nc">R</span><span class="o">&gt;</span> <span class="k">using</span> <span class="n">outcome</span> <span class="o">=</span> <span class="n">BOOST_OUTCOME_V2_NAMESPACE</span><span class="o">::</span><span class="n">outcome</span><span class="o">&lt;</span><span class="n">R</span><span class="p">,</span> <span class="n">error_code</span> <span class="cm">/*, std::exception_ptr */</span><span class="o">&gt;</span><span class="p">;</span>
41<span class="p">}</span>
42</code></pre></div><a href="https://github.com/boostorg/outcome/tree/master/doc/src/snippets/error_code_extended.cpp#L95" class="code-snippet-url" target="_blank">View this code on Github</a></div>
43
44
45<p>For convenience, we template alias local copies of <code>result</code> and <code>outcome</code> in this
46namespace bound to the ADL bridging <code>error_code</code>.</p>
47
48
49        </div><p><small>Last revised: February 08, 2019 at 22:18:08 UTC</small></p>
50<hr>
51<div class="spirit-nav">
52<a accesskey="p" href="../../../tutorial/advanced/hooks/keeping_state.html"><img src="../../../images/prev.png" alt="Prev"></a>
53    <a accesskey="u" href="../../../tutorial/advanced/hooks.html"><img src="../../../images/up.png" alt="Up"></a>
54    <a accesskey="h" href="../../../index.html"><img src="../../../images/home.png" alt="Home"></a><a accesskey="n" href="../../../tutorial/advanced/hooks/hook_result.html"><img src="../../../images/next.png" alt="Next"></a></div></body>
55</html>
56