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

This is the documentation for a snapshot of the develop branch, built from commit 368435a614.


The type of result returned by library functions.


Defined in header <boost/json/system_error.hpp>

    class T>
using result = boost::system::result< T >;

This is an alias template used as the return type for functions that can either return a value, or fail with an error code. This is a brief synopsis of the type:

template < class T >
class result
public :
    // Return true if the result contains an error
    constexpr bool has_error() const noexcept;

    // These two return true if the result contains a value
    constexpr bool has_value() const noexcept;
    constexpr explicit operator bool () const noexcept;

    // Return the value or throw an exception if has_value() == false
    constexpr T& value();
    constexpr T const& value() const;

    // Return the value, assuming the result contains it
    constexpr T& operator*();
    constexpr T const& operator*() const;

    // Return the error, which is default constructed if has_error() == false
    constexpr error_code error() const noexcept;

Given the function try_value_to with this signature:

template < class T>
result< T > try_value_to( const value& jv );

The following statement captures the value in a variable upon success, otherwise throws:

int n = try_value_to<int>( jv ).value();

This statement captures the result in a variable and inspects the error condition:

result< int > r = try_value_to<int>( jv );
if ( r )
    std::cout << *r;
    std::cout << r.error();

For a full synopsis of the type, please see the corresponding documentation in Boost.System.

Template Parameters




The type of value held by the result.

Convenience header <boost/json.hpp>