boost::urls::error_types::result :: Boost Libraries Documentation

# boost::urls::error_types::result

The type of result returned by library functions

## Synopsis

Declared in `<boost/url/error_types.hpp>`

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

## Description

| This alias is no longer supported and should not be used in new code. Please use `system::result` instead.

This alias is included for backwards compatibility with earlier versions of the library.

However, it will be removed in future releases, and using it in new code is not recommended.

Please use the updated version instead to ensure compatibility with future versions of the library.

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;

        //
        // Return the error
        //
        constexpr system::error_code error() const noexcept;

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

        // Return the value.
        // Precondition: has_value()==true
        //
        constexpr T& operator*() noexcept;
        constexpr T* operator->() noexcept;
        constexpr T const& operator*() const noexcept;
        constexpr T const* operator->() const noexcept;

        ...more

## Usage

Given the function `parse_uri` with this signature:

    system::result< url_view > parse_uri( core::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:

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

    if(! rv )
        std::cout << rv.error();
    else
        std::cout << *rv;

- https://boost.org/libs/system/doc/html/system.html#ref_resultt_e

## Template Parameters

Name | Description
T | The type of value held by the result.

## See Also

Created with MrDocs