1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768 |
- <!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>ValueOrError Concept - Boost.Outcome documentation</title>
- <link rel="stylesheet" href="../../../css/boost.css" type="text/css">
- <meta name="generator" content="Hugo 0.52 with Boostdoc theme">
- <meta name="viewport" content="width=device-width,initial-scale=1.0"/>
- <link rel="icon" href="../../../images/favicon.ico" type="image/ico"/>
- <body><div class="spirit-nav">
- <a accesskey="p" href="../../../tutorial/advanced/interop/problem.html"><img src="../../../images/prev.png" alt="Prev"></a>
- <a accesskey="u" href="../../../tutorial/advanced/interop.html"><img src="../../../images/up.png" alt="Up"></a>
- <a accesskey="h" href="../../../index.html"><img src="../../../images/home.png" alt="Home"></a><a accesskey="n" href="../../../tutorial/advanced/interop/httplib.html"><img src="../../../images/next.png" alt="Next"></a></div><div id="content">
- <div class="titlepage"><div><div><h1 style="clear: both">ValueOrError Concept</h1></div></div></div>
-
- <p>Something not really mentioned until now is how Outcome interoperates with the proposed
- <a href="https://wg21.link/P0323" class="api-reference" target="_blank"><i class="fa fa-book" aria-hidden="true"></i> P0323 <code>std::expected<T, E></code></a>
- , whose design lands in between <a href="../../../reference/aliases/unchecked.html" class="api-reference"><code>unchecked<T, E = varies></code></a>
- and <a href="../../../reference/aliases/checked.html" class="api-reference"><code>checked<T, E = varies></code></a>
- (both of which are type aliases hard coding no-value
- policies <a href="../../../tutorial/essential/no-value/builtin.html">as previously covered in this tutorial</a>).</p>
- <p>Expected and Outcome are <a href="../../../faq.html#why-doesn-t-outcome-duplicate-std-expected-t-e-s-design">isomorphic to one another in design intent</a>, but interoperation
- for code using Expected and Outcome ought to be seamless thanks to the <a href="https://wg21.link/P0786">proposed <code>ValueOrError</code>
- concept framework</a>, a subset of which Outcome implements.</p>
- <p>The <a href="../../../reference/types/basic_result/explicit_valueorerror_converting_constructor.html" class="api-reference"><code>explicit basic_result(ValueOrError<T, E> &&)</code></a>
- and <a href="../../../reference/types/basic_outcome/explicit_valueorerror_converting_constructor.html" class="api-reference"><code>explicit basic_outcome(ValueOrError<T, E> &&)</code></a>
- constructors will explicitly construct from any type matching the <a href="../../../reference/concepts/valueorerror.html" class="api-reference"><code>ValueOrError<T, E></code></a>
- concept, which includes <code>std::expected<A, B></code>, if <code>A</code> is constructible to <code>X</code>, and <code>B</code> is
- constructible to <code>Y</code>. The <code>ValueOrError</code> concept in turn is true if and only if the input type has:</p>
- <ol>
- <li>A <code>.has_value()</code> observer returning a <code>bool</code>.</li>
- <li><code>.value()</code> and <code>.error()</code> observers.</li>
- </ol>
- <h2 id="implementation">Implementation</h2>
- <p>Outcome’s machinery for implementing <code>ValueOrError</code> conversion is user extensible by injection
- of specialisations of the <a href="../../../reference/converters/value_or_error.html" class="api-reference"><code>value_or_error<T, U></code></a>
- type into the <code>BOOST_OUTCOME_V2_NAMESPACE::convert</code> namespace.</p>
- <p>Outcome’s default <code>convert::value_or_error<T, U></code> implementation explicitly
- excludes Outcome <code>result</code> and <code>outcome</code> types from the default mechanism as
- there is a major gotcha: the <code>ValueOrError</code> matched type’s <code>.value()</code> is often
- not callable in constexpr as it can throw, which makes this conversion mechanism
- pretty much useless for constexpr code. Besides, <code>outcome</code> has a converting
- constructor overload for <code>result</code> inputs which is constexpr capable.</p>
- <p>Note that if you do enable <code>outcome</code> inputs, a <code>result</code> will match an input
- <code>outcome</code>, but silently dropping any exception state. This is probably undesirable.</p>
- <p>Examples of how to implement your own <code>convert::value_or_error<T, U></code> converter
- is demonstrated in the worked example, next.</p>
- </div><p><small>Last revised: February 11, 2019 at 17:14:51 UTC</small></p>
- <hr>
- <div class="spirit-nav">
- <a accesskey="p" href="../../../tutorial/advanced/interop/problem.html"><img src="../../../images/prev.png" alt="Prev"></a>
- <a accesskey="u" href="../../../tutorial/advanced/interop.html"><img src="../../../images/up.png" alt="Up"></a>
- <a accesskey="h" href="../../../index.html"><img src="../../../images/home.png" alt="Home"></a><a accesskey="n" href="../../../tutorial/advanced/interop/httplib.html"><img src="../../../images/next.png" alt="Next"></a></div></body>
- </html>
|