co_tryx.html 4.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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>BOOST_OUTCOME_CO_TRYX(expr) - 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/macros/co_tryv_failure_likely.html"><img src="../../images/prev.png" alt="Prev"></a>
  10. <a accesskey="u" href="../../reference/macros.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/macros/co_tryx_failure_likely.html"><img src="../../images/next.png" alt="Next"></a></div><div id="content">
  12. <div class="titlepage"><div><div><h1 style="clear: both"><code>BOOST_OUTCOME_CO_TRYX(expr)</code></h1></div></div></div>
  13. <p>Evaluate within a coroutine an expression which results in a type matching the following customisation points, emitting the <code>T</code> if successful, immediately returning <a href="../../reference/functions/try_operation_return_as.html" class="api-reference"><code>try_operation_return_as(X)</code></a>
  14. from the calling function if unsuccessful:</p>
  15. <ul>
  16. <li><code>BOOST_OUTCOME_V2_NAMESPACE::</code><a href="../../reference/functions/try_operation_has_value.html" class="api-reference"><code>try_operation_has_value(X)</code></a>
  17. </li>
  18. <li><code>BOOST_OUTCOME_V2_NAMESPACE::</code><a href="../../reference/functions/try_operation_return_as.html" class="api-reference"><code>try_operation_return_as(X)</code></a>
  19. </li>
  20. <li><code>BOOST_OUTCOME_V2_NAMESPACE::</code><a href="../../reference/functions/try_operation_extract_value.html" class="api-reference"><code>try_operation_extract_value(X)</code></a>
  21. </li>
  22. </ul>
  23. <p>Default overloads for these customisation points are provided. See <a href="../../recipes/foreign-try.html">the recipe for supporting foreign input to <code>BOOST_OUTCOME_TRY</code></a>.</p>
  24. <p>Hints are given to the compiler that the expression will be successful. If you expect failure, you should use <a href="../../reference/macros/co_tryx_failure_likely.html" class="api-reference"><code>BOOST_OUTCOME_CO_TRYX_FAILURE_LIKELY(expr)</code></a>
  25. instead.</p>
  26. <p><em>Availability</em>: GCC and clang only. Use <code>#ifdef BOOST_OUTCOME_CO_TRYX</code> to determine if available.</p>
  27. <p><em>Overridable</em>: Not overridable.</p>
  28. <p><em>Definition</em>: See <a href="../../reference/macros/co_tryv.html" class="api-reference"><code>BOOST_OUTCOME_CO_TRYV(expr)</code></a>
  29. for most of the mechanics.</p>
  30. <p>This macro makes use of a proprietary extension in GCC and clang to emit the <code>T</code> from a successful expression. You can thus use <code>BOOST_OUTCOME_CO_TRYX(expr)</code> directly in expressions e.g. <code>auto x = y + BOOST_OUTCOME_CO_TRYX(foo(z));</code>.</p>
  31. <p>Be aware there are compiler quirks in preserving the rvalue/lvalue/etc-ness of emitted <code>T</code>&rsquo;s, specifically copy or move constructors may be called unexpectedly and/or copy elision not work as expected. If these prove to be problematic, use <a href="../../reference/macros/co_try.html" class="api-reference"><code>BOOST_OUTCOME_CO_TRY(var, expr)</code></a>
  32. instead.</p>
  33. <p><em>Header</em>: <code>&lt;boost/outcome/try.hpp&gt;</code></p>
  34. </div><p><small>Last revised: October 16, 2019 at 10:26:35 &#43;0100</small></p>
  35. <hr>
  36. <div class="spirit-nav">
  37. <a accesskey="p" href="../../reference/macros/co_tryv_failure_likely.html"><img src="../../images/prev.png" alt="Prev"></a>
  38. <a accesskey="u" href="../../reference/macros.html"><img src="../../images/up.png" alt="Up"></a>
  39. <a accesskey="h" href="../../index.html"><img src="../../images/home.png" alt="Home"></a><a accesskey="n" href="../../reference/macros/co_tryx_failure_likely.html"><img src="../../images/next.png" alt="Next"></a></div></body>
  40. </html>