mirror of
https://github.com/boostorg/outcome.git
synced 2026-02-18 14:22:08 +00:00
82 lines
5.2 KiB
HTML
82 lines
5.2 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>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 id="boost-common-heading-doc" style="background: #574D74 url('../../images/header-bg.png') repeat-x top left;">
|
|
<div class="heading-inner" style="background: url('../../images/header-fg.png') no-repeat top left;">
|
|
<div class="heading-placard"></div>
|
|
|
|
<h1 class="heading-title">
|
|
<a href="../../">
|
|
<img src="../../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="p" href="../../tutorial/interop/problem.html"><img src="../../images/prev.png" alt="Prev"></a>
|
|
<a accesskey="u" href="../../tutorial/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/interop/httplib.html"><img src="../../images/next.png" alt="Next"></a></div><div id="content">
|
|
<div class="titlepage"><div><div><h2 class="title" style="clear: both">ValueOrError Concept</h2></div></div></div>
|
|
|
|
|
|
<p>Something not really mentioned until now is how Outcome interoperates with the proposed
|
|
<a href="https://wg21.link/P0323"><code>std::expected<T, E></code></a>, whose design lands in between <code>outcome::unchecked<T, E></code>
|
|
and <code>outcome::checked<T, E></code>, both of which are simplified aliases for <code>outcome::result<T, E></code> <a href="../../policies">hard
|
|
coding the <code>NoValuePolicy</code> to a fixed policy</a>.</p>
|
|
|
|
<p>Expected and Outcome are <a href="../../../faq/#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 proposed <a href="https://wg21.link/P0786"><code>ValueOrError</code>
|
|
concept framework</a>, a subset of which Outcome implements.</p>
|
|
|
|
<p>Outcome’s <code>result<X, Y></code> will explicitly construct from any type matching the <code>ValueOrError</code>
|
|
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>value_type</code> and <code>error_type</code> member typedefs.</li>
|
|
<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 <code>value_or_error<DEST, SRC></code> type into the <code>BOOST_OUTCOME_V2_NAMESPACE::convert</code> namespace.</p>
|
|
|
|
<p>Outcome’s default <code>convert::value_or_error<DEST, SRC></code> implementation explicitly excludes Outcome <code>result</code>
|
|
and <code>outcome</code> types from the default mechanism as there is a major gotcha:
|
|
Outcome’s <code>.value()</code> is often not callable in constexpr as it can throw, which makes this mechanism pretty much
|
|
useless for constexpr code. Thus separate explicit converting constructors exist which constexpr convert
|
|
from any Outcome type (though note that <code>result</code> construction from <code>outcome</code> does use the
|
|
<code>ValueOrError</code> mechanism).</p>
|
|
|
|
<p>Examples of how to implement your own <code>convert::value_or_error<DEST, SRC></code> converter
|
|
is demonstrated in the worked example, next.</p>
|
|
|
|
|
|
</div><p><small>Last revised: December 05, 2018 at 14:18:52 UTC</small></p>
|
|
<hr>
|
|
<div class="spirit-nav">
|
|
<a accesskey="p" href="../../tutorial/interop/problem.html"><img src="../../images/prev.png" alt="Prev"></a>
|
|
<a accesskey="u" href="../../tutorial/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/interop/httplib.html"><img src="../../images/next.png" alt="Next"></a></div></body>
|
|
</html>
|