builtin.html 7.7 KB

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