Boost C++ Libraries Home Libraries People FAQ More

PrevUpHomeNext

result

The type of result returned by library functions.

Synopsis

Defined in header <boost/url/error_types.hpp>

template<
    class T>
using result = boost::system::result< T, error_code >;
Description

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

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

    // These 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& operator*();
    constexpr T const& value() const;
    constexpr T const& operator*() const;

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

    ...more
Usage

Given the function parse_uri with this signature:

result< url_view > parse_uri( string_view s ) noexcept;

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

url_view u = parse_uri( "http://example.com/path/to/file.txt" ).value();

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

result< url_view > r = parse_uri( "http://example.com/path/to/file.txt" );

if( !r )
    std::cout << r.error();
else
    std::cout << r.value();
Remarks

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

Template Parameters

Type

Description

T

The type of value held by the result.

Convenience header <boost/url.hpp>


PrevUpHomeNext