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>Built-in policies - 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/essential/no-value/custom.html"><img src="../../../images/prev.png" alt="Prev"></a> 11 <a accesskey="u" href="../../../tutorial/essential/no-value.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/essential/coroutines.html"><img src="../../../images/next.png" alt="Next"></a></div><div id="content"> 13 <div class="titlepage"><div><div><h1 style="clear: both">Built-in policies</h1></div></div></div> 14 <p>These are the predefined policies built into Outcome:</p> 15 16<hr style="border-color: black;"> 17 18<p> </p> 19 20<a href="../../../reference/policies/all_narrow.html" class="api-reference"><code>all_narrow</code></a> 21 22 23<p>If there is an observation of a value/error/exception which is not present, 24the program is put into a <strong>hard undefined behaviour</strong> situation. The 25compiler <em>literally</em> compiles no code for an invalid observation – the 26CPU “runs off” into the unknown.</p> 27 28<p>As bad as this may sound, it generates the most optimal code, and such 29hard UB is very tool-friendly for detection e.g. undefined behaviour 30sanitiser, valgrind memcheck, etc.</p> 31 32<p>If you are considering choosing this policy, definitely read 33<a href="../../../reference/policies/base/ub.html" class="api-reference"><code>static void _ub(Impl &&)</code></a> 34 first.</p> 35 36<p>Note that <a href="../../../reference/aliases/unchecked.html" class="api-reference"><code>unchecked<T, E = varies></code></a> 37 aliases a <code>basic_result</code> 38with the <code>all_narrow</code> no-value policy.</p> 39 40<hr style="border-color: black;"> 41 42<p> </p> 43 44<a href="../../../reference/policies/terminate.html" class="api-reference"><code>terminate</code></a> 45 46 47<p>Observation of a missing value/error/exception causes a call to 48<code>std::terminate()</code>.</p> 49 50<p>Note that configuring <code>EC = void</code> or <code>EP = void</code> causes 51<a href="../../../reference/aliases/default_policy.html" class="api-reference"><code>default_policy</code></a> 52 to choose <code>terminate</code> as the no-value policy.</p> 53 54<hr style="border-color: black;"> 55 56<p> </p> 57 58<a href="../../../reference/policies/error_code_throw_as_system_error_outcome.html" class="api-reference"><code>error_code_throw_as_system_error<T, EC, EP></code></a> 59 60 61<p>This policy assumes that <code>EC</code> has the interface of <code>std::error_code</code>, 62and <code>EP</code> has the interface of <code>std::exception_ptr</code>. Upon missing value 63observation:</p> 64 65<ul> 66<li>if an exception is stored through pointer of type <code>EP</code> it is rethrown;</li> 67<li>otherwise, if an error of type <code>EC</code> is stored, it is converted to <code>error_code</code> 68and then thrown as <code>system_error</code>.</li> 69</ul> 70 71<p>Upon missing error observation throws:</p> 72 73<ul> 74<li><code>bad_result_access("no error")</code> from instances of <code>basic_result<></code>.</li> 75<li><code>bad_outcome_access("no error")</code> from instances of <code>basic_outcome<></code>.</li> 76</ul> 77 78<p>Upon missing exception observation throws <code>bad_outcome_access("no exception")</code>.</p> 79 80<p>Overloads are provided for <code>boost::system::error_code</code> and <code>boost::exception_ptr</code>.</p> 81 82<p>Note that if <a href="../../../reference/traits/is_error_code_available.html" class="api-reference"><code>is_error_code_available<T></code></a> 83 is true for <code>EC</code>, 84and (if <code>basic_outcome</code>) <a href="../../../reference/traits/is_exception_ptr_available.html" class="api-reference"><code>is_exception_ptr_available<T></code></a> 85 86is true for <code>EP</code>, <a href="../../../reference/aliases/default_policy.html" class="api-reference"><code>default_policy</code></a> 87 chooses 88<code>error_code_throw_as_system_error<T, EC, EP></code> as the no-value policy.</p> 89 90<hr style="border-color: black;"> 91 92<p> </p> 93 94<a href="../../../reference/policies/exception_ptr_rethrow_outcome.html" class="api-reference"><code>exception_ptr_rethrow<T, EC, EP></code></a> 95 96 97<p>This policy assumes that either <code>EC</code> or <code>EP</code> (unless <code>void</code>) has the interface of <code>std::exception_ptr</code>. Upon missing value observation:</p> 98 99<ul> 100<li>in instances of <code>basic_result<></code>, rethrows exception pointed to by <code>EC</code>;</li> 101<li>in instances of <code>basic_outcome<></code>, if exception <code>EP</code> is present rethrows it, 102otherwise rethrows <code>EC</code>.</li> 103</ul> 104 105<p>Upon missing error observation:</p> 106 107<ul> 108<li>in instances of <code>basic_result<></code>, throws <code>bad_result_access("no error")</code> ;</li> 109<li>in instances of <code>basic_outcome<></code>, throws <code>bad_outcome_access("no error")</code>.</li> 110</ul> 111 112<p>Upon missing exception observation throws <code>bad_outcome_access("no exception")</code>.</p> 113 114<p>Overloads are provided for <code>boost::exception_ptr</code>.</p> 115 116<p>Note that if <a href="../../../reference/traits/is_exception_ptr_available.html" class="api-reference"><code>is_exception_ptr_available<T></code></a> 117 is true for <code>EC</code>, 118or (if <code>basic_outcome</code>) <a href="../../../reference/traits/is_exception_ptr_available.html" class="api-reference"><code>is_exception_ptr_available<T></code></a> 119 120is true for <code>EP</code>, <a href="../../../reference/aliases/default_policy.html" class="api-reference"><code>default_policy</code></a> 121 chooses 122<code>exception_ptr_rethrow<T, EC, EP></code> as the no-value policy.</p> 123 124<hr style="border-color: black;"> 125 126<p> </p> 127 128<a href="../../../reference/policies/throw_bad_result_access.html" class="api-reference"><code>throw_bad_result_access<EC></code></a> 129 130 131<p>Upon missing value observation throws <code>bad_result_access_with<EC>(ec)</code>, 132where <code>ec</code> is the value of the stored error. If error is not stored, 133the behaviour is undefined.</p> 134 135<p>Upon missing error observation throws <code>bad_result_access("no error")</code>.</p> 136 137<p>This policy can be used with <code>basic_outcome<></code> instances, where it always 138throws <code>bad_outcome_access</code> for all no-value/error/exception observations.</p> 139 140<p>Note that <a href="../../../reference/aliases/checked.html" class="api-reference"><code>checked<T, E = varies></code></a> 141 aliases a <code>basic_result</code> 142with the <code>throw_bad_result_access<EC></code> no-value policy.</p> 143 144 145 </div><p><small>Last revised: February 09, 2019 at 15:18:26 UTC</small></p> 146<hr> 147<div class="spirit-nav"> 148<a accesskey="p" href="../../../tutorial/essential/no-value/custom.html"><img src="../../../images/prev.png" alt="Prev"></a> 149 <a accesskey="u" href="../../../tutorial/essential/no-value.html"><img src="../../../images/up.png" alt="Up"></a> 150 <a accesskey="h" href="../../../index.html"><img src="../../../images/home.png" alt="Home"></a><a accesskey="n" href="../../../tutorial/essential/coroutines.html"><img src="../../../images/next.png" alt="Next"></a></div></body> 151</html> 152