|
| | expect ()=delete |
| |
| | expect (std::error_code const &code) noexcept |
| |
| | expect (T val) noexcept(std::is_nothrow_move_constructible< T >()) |
| | Store a value, val, in the expect object. More...
|
| |
| | expect (expect const &src) noexcept(std::is_nothrow_copy_constructible< T >()) |
| |
| template<typename U , typename = detail::enable_if<is_convertible<U const&>()>> |
| | expect (expect< U > const &src) noexcept(std::is_nothrow_constructible< T, U const &>()) |
| | Copy conversion from U to T. More...
|
| |
| | expect (expect &&src) noexcept(std::is_nothrow_move_constructible< T >()) |
| |
| template<typename U , typename = detail::enable_if<is_convertible<U>()>> |
| | expect (expect< U > &&src) noexcept(std::is_nothrow_constructible< T, U >()) |
| | Move conversion from U to T. More...
|
| |
| | ~expect () noexcept |
| |
| expect & | operator= (expect const &src) noexcept(std::is_nothrow_copy_constructible< T >() &&std::is_nothrow_copy_assignable< T >()) |
| |
| expect & | operator= (expect &&src) noexcept(std::is_nothrow_move_constructible< T >() &&std::is_nothrow_move_assignable< T >()) |
| |
| | operator bool () const noexcept |
| |
| bool | has_error () const noexcept |
| |
| bool | has_value () const noexcept |
| |
| std::error_code | error () const noexcept |
| |
| T & | value () & |
| |
| T const & | value () const & |
| |
| T && | value () && |
| |
| T * | operator-> () noexcept |
| |
| T const * | operator-> () const noexcept |
| |
| T & | operator* () noexcept |
| |
| T const & | operator* () const noexcept |
| |
| template<typename U > |
| bool | equal (expect< U > const &rhs) const noexcept(noexcept(*std::declval< expect< T >>()== *rhs)) |
| |
| bool | equal (std::error_code const &rhs) const noexcept |
| |
| template<typename U , typename = detail::enable_if<!std::is_constructible<std::error_code, U>::value>> |
| bool | equal (U const &rhs) const noexcept(noexcept(*std::declval< expect< T >>()==rhs)) |
| |
| bool | matches (std::error_condition const &rhs) const noexcept |
| |
template<typename T>
class expect< T >
expect<T> is a value or error implementation, similar to Rust std::result or various C++ proposals (boost::expected, boost::outcome). This implementation currently has a strict error type, std::error_code, and a templated value type T. expect<T> is implicitly convertible from T or std::error_code, and one expect<T> object type is implicitly convertible to another expect<U> object iff the destination value type can be implicitly constructed from the source value type (i.e. struct U { ... U(T src) { ...} ... };).
operator== and operator!= are the only comparison operators provided; comparison between different value types is allowed provided the two values types have a operator== defined between them (i.e. assert(expect<int>{100} == expect<short>{100});). Comparisons can also be done against std::error_code objects or error code enums directly (i.e. assert(expect<int>{make_error_code(common_error::kInvalidArgument)} == error::kInvalidArgument)). Comparison of default constructed std::error_code will always fail. "Generic" comparisons can be done with std::error_condition via the matches method only (i.e. assert(expect<int>{make_error_code{common_error::kInvalidErrorCode}.matches(std::errc::invalid_argument))), operator== and operator!= will not work with std::errc or std::error_condition. A comparison with matches is more expensive because an equivalency between error categories is computed, but is recommended when an error can be one of several categories (this is going to be the case in nearly every situation when calling a function from another C++ struct/class).
expect<void> is a special case with no stored value. It is used by functions that can fail, but otherwise would return void. It is useful for consistency; all macros, standalone functions, and comparison operators work with expect<void>.
- Note
- See
src/common/error.h for creating a custom error enum.
Definition at line 70 of file expect.h.