value_or_error.html 4.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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>value_or_error&lt;T, U&gt; - 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="../../reference/converters.html"><img src="../../images/prev.png" alt="Prev"></a>
  10. <a accesskey="u" href="../../reference/converters.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="../../reference/traits.html"><img src="../../images/next.png" alt="Next"></a></div><div id="content">
  12. <div class="titlepage"><div><div><h1 style="clear: both"><code>value_or_error&lt;T, U&gt;</code></h1></div></div></div>
  13. <p>A customisable converter of <a href="../../reference/concepts/valueorerror.html" class="api-reference"><code>ValueOrError&lt;T, E&gt;</code></a>
  14. concept matching types. It must have the following form:</p>
  15. <div class="highlight"><pre class="chroma"><code class="language-c++" data-lang="c++"><span class="c1">// `T` will be the destination basic_result or basic_outcome.
  16. </span><span class="c1">// `U` will be the decayed form of the `ValueOrError&lt;T, E&gt;` concept matching input type.
  17. </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">T</span><span class="o">&gt;</span> <span class="k">struct</span> <span class="n">value_or_error</span><span class="o">&lt;</span><span class="n">T</span><span class="p">,</span> <span class="n">U</span><span class="o">&gt;</span>
  18. <span class="p">{</span>
  19. <span class="c1">// False to indicate that this converter wants `basic_result`/`basic_outcome` to reject all other `basic_result`
  20. </span><span class="c1"></span> <span class="k">static</span> <span class="k">constexpr</span> <span class="kt">bool</span> <span class="n">enable_result_inputs</span> <span class="o">=</span> <span class="nb">false</span><span class="p">;</span>
  21. <span class="c1">// False to indicate that this converter wants `basic_outcome` to reject all other `basic_outcome`
  22. </span><span class="c1"></span> <span class="k">static</span> <span class="k">constexpr</span> <span class="kt">bool</span> <span class="n">enable_outcome_inputs</span> <span class="o">=</span> <span class="nb">false</span><span class="p">;</span>
  23. <span class="c1">// `X` will be the raw input form of `U`. It must return a `T`.
  24. </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">X</span><span class="o">&gt;</span> <span class="k">constexpr</span> <span class="n">T</span> <span class="k">operator</span><span class="p">()(</span><span class="n">X</span> <span class="o">&amp;&amp;</span><span class="n">v</span><span class="p">);</span>
  25. <span class="p">};</span>
  26. </code></pre></div>
  27. <p><em>Overridable</em>: By template specialisation into the <code>convert</code> namespace.</p>
  28. <p><em>Default</em>: If decayed <code>X</code> is same as <code>U</code>, concept <code>ValueOrError&lt;U&gt;</code> matches, <code>X::value_type</code> is <code>void</code> or is explicitly constructible to <code>T::value_type</code>, and <code>X::error_type</code> is <code>void</code> or is explicitly constructible to <code>T::error_type</code>, then <code>operator()(X &amp;&amp;)</code> is made available.</p>
  29. <p><code>operator()(X &amp;&amp;v)</code> tests if <code>v.has_value()</code> is true, if so then a <code>T</code> with successful value is returned, else a <code>T</code> with unsuccessful value. If the input type was <code>void</code>, a default constructed value is used for either, else a move/copy construction from the source is performed.</p>
  30. <p><em>Namespace</em>: <code>BOOST_OUTCOME_V2_NAMESPACE::convert</code></p>
  31. <p><em>Header</em>: <code>&lt;boost/outcome/convert.hpp&gt;</code></p>
  32. </div><p><small>Last revised: December 15, 2018 at 17:49:37 UTC</small></p>
  33. <hr>
  34. <div class="spirit-nav">
  35. <a accesskey="p" href="../../reference/converters.html"><img src="../../images/prev.png" alt="Prev"></a>
  36. <a accesskey="u" href="../../reference/converters.html"><img src="../../images/up.png" alt="Up"></a>
  37. <a accesskey="h" href="../../index.html"><img src="../../images/home.png" alt="Home"></a><a accesskey="n" href="../../reference/traits.html"><img src="../../images/next.png" alt="Next"></a></div></body>
  38. </html>