...one of the most highly
regarded and expertly designed C++ library projects in the
world.
— Herb Sutter and Andrei
Alexandrescu, C++
Coding Standards
The type of result returned by library functions.
Defined in header <boost/url/error_types.hpp>
template< class T> using result = boost::system::result< T, error_code >;
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:
template< class T > class result { public: // // Return true if the result contains an error // constexpr bool has_error() const noexcept; // // Return the error // constexpr 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
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 > rv = parse_uri( "http://example.com/path/to/file.txt" ); if(! rv ) std::cout << r.error(); else std::cout << *rv;
Type |
Description |
---|---|
|
The type of value held by the result. |
Convenience header <boost/url.hpp>