Boost C++ Libraries

...one of the most highly regarded and expertly designed C++ library projects in the world. Herb Sutter and Andrei Alexandrescu, C++ Coding Standards

Prev Up HomeNext

BOOST_OUTCOME_TRYX(expr)

Evaluate an expression which results in a type matching the following customisation points, emitting the T if successful, immediately returning try_operation_return_as(X) from the calling function if unsuccessful:

Default overloads for these customisation points are provided. See the recipe for supporting foreign input to BOOST_OUTCOME_TRY.

Hints are given to the compiler that the expression will be successful. If you expect failure, you should use BOOST_OUTCOME_TRYX_FAILURE_LIKELY(expr) instead.

An internal temporary to hold the value of the expression is created, which generally invokes a copy/move. If you wish to never copy/move, you can tell this macro to create the internal temporary as a reference instead.

Availability: GCC and clang only. Use #ifdef BOOST_OUTCOME_TRYX to determine if available.

Overridable: Not overridable.

Definition: See BOOST_OUTCOME_TRYV(expr) for most of the mechanics.

This macro makes use of a proprietary extension in GCC and clang to emit the T from a successful expression. You can thus use BOOST_OUTCOME_TRYX(expr) directly in expressions e.g. auto x = y + BOOST_OUTCOME_TRYX(foo(z));.

Be aware there are compiler quirks in preserving the rvalue/lvalue/etc-ness of emitted T’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 BOOST_OUTCOME_TRY(var, expr) instead.

Header: <boost/outcome/try.hpp>

Last revised: February 12, 2021 at 20:25:43 UTC


Prev Up HomeNext