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
Return result with a
reference to the underlying object.
boost::system::result<object& > try_as_object() noexcept;
If is_object()
is true, the result contains
a reference to the underlying object, otherwise it contains
an error_code.
The return value can be used in both a boolean context and to assign a variable:
if( auto r = jv.try_as_object() ) return *r;
But can also be used to throw an exception on error:
return jv.try_as_object().value();
Constant.
No-throw guarantee.