• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1+++
2title = "`BOOST_OUTCOME_TRY(var, expr)`"
3description = "Evaluate an expression which results in an understood type, assigning `T` to a variable called `var` if successful, immediately returning `try_operation_return_as(X)` from the calling function if unsuccessful."
4+++
5
6Evaluate an expression which results in a type matching the following customisation points, assigning `T` to a variable called `var` if successful, immediately returning {{% api "try_operation_return_as(X)" %}} from the calling function if unsuccessful:
7
8- `BOOST_OUTCOME_V2_NAMESPACE::`{{% api "try_operation_has_value(X)" %}}
9- `BOOST_OUTCOME_V2_NAMESPACE::`{{% api "try_operation_return_as(X)" %}}
10- `BOOST_OUTCOME_V2_NAMESPACE::`{{% api "try_operation_extract_value(X)" %}}
11
12Default overloads for these customisation points are provided. See [the recipe for supporting foreign input to `BOOST_OUTCOME_TRY`]({{% relref "/recipes/foreign-try" %}}).
13
14Hints are given to the compiler that the expression will be successful. If you expect failure, you should use {{% api "BOOST_OUTCOME_TRY_FAILURE_LIKELY(var, expr)" %}} instead.
15
16*Overridable*: Not overridable.
17
18*Definition*: See {{% api "BOOST_OUTCOME_TRYV(expr)" %}} for most of the mechanics.
19
20If successful, an `auto &&var` is initialised to the expression result's `.assume_value()` if available, else to its `.value()`. This binds a reference possibly to the `T` stored inside the bound result of the expression, but possibly also to a temporary emitted from the value observer function.
21
22*Header*: `<boost/outcome/try.hpp>`
23
24