Result
|
Partial specialization of result<void, E>
More...
#include <result.hpp>
Public Types | |
using | value_type = void |
The value type of this result. | |
using | error_type = E |
The error type of this result. | |
using | failure_type = failure< E > |
The failure type. | |
template<typename U > | |
using | rebind = result< U, E > |
Rebinds the result type. | |
Public Member Functions | |
constexpr | result () noexcept |
Constructs a result object in a value state. More... | |
constexpr | result (const result &other)=default |
Copy constructs this result. More... | |
constexpr | result (result &&other)=default |
Move constructs a result. More... | |
template<typename U , typename E2 , typename = typename std::enable_if<std::is_constructible<E,E2>::value>::type> | |
result (const result< U, E2 > &other) noexcept(std::is_nothrow_constructible< E, const E2 &>::value) | |
Converting copy constructor. More... | |
template<typename U , typename E2 , typename = typename std::enable_if<std::is_constructible<E,E2>::value>::type> | |
result (result< U, E2 > &&other) noexcept(std::is_nothrow_constructible< E, E2 &&>::value) | |
Converting move constructor. More... | |
constexpr | result (in_place_t) noexcept |
Constructs a result object in a value state. More... | |
template<typename... Args, typename = typename std::enable_if<std::is_constructible<E,Args...>::value>::type> | |
constexpr | result (in_place_error_t, Args &&... args) noexcept(std::is_nothrow_constructible< E, Args... >::value) |
Constructs a result object that contains an error. More... | |
template<typename U , typename... Args, typename = typename std::enable_if<std::is_constructible<E, std::initializer_list<U>&, Args...>::value>::type> | |
constexpr | result (in_place_error_t, std::initializer_list< U > ilist, Args &&...args) noexcept(std::is_nothrow_constructible< E, std::initializer_list< U >, Args... >::value) |
Constructs a result object that contains an error. More... | |
auto | operator= (const result &other) -> result &=default |
Copy assigns the result stored in other . More... | |
auto | operator= (result &&other) -> result &=default |
Move assigns the result stored in other . More... | |
template<typename E2 , typename = typename std::enable_if<std::is_nothrow_constructible<E,const E2&>::value && std::is_assignable<E&,const E2&>::value>::type> | |
auto | operator= (const result< void, E2 > &other) noexcept(std::is_nothrow_assignable< E, const E2 &>::value) -> result & |
Copy-converts the state of other . More... | |
template<typename E2 , typename = typename std::enable_if<std::is_nothrow_constructible<E,E2&&>::value && std::is_assignable<E&,E2&&>::value>::type> | |
auto | operator= (result< void, E2 > &&other) noexcept(std::is_nothrow_assignable< E, E2 &&>::value) -> result & |
Move-converts the state of other . More... | |
RESULT_WARN_UNUSED constexpr | operator bool () const noexcept |
Contextually convertible to true if *this does not contain an error. More... | |
RESULT_WARN_UNUSED constexpr auto | has_value () const noexcept -> bool |
Returns true if *this contains a value. More... | |
RESULT_WARN_UNUSED constexpr auto | has_error () const noexcept -> bool |
Returns true if *this contains an error. More... | |
template<typename U > | |
RESULT_WARN_UNUSED constexpr auto | and_then (U &&value) const -> result< typename std::decay< U >::type, E > |
Returns a result containing value if this result contains a value, otherwise returns a result containing the current error. More... | |
template<typename E2 , typename = typename std::enable_if<std::is_constructible<E,const E2&>::value>::type> | |
constexpr | result (const failure< E2 > &e) noexcept(std::is_nothrow_constructible< E, const E2 &>::value) |
Constructs the underlying error of this result. More... | |
template<typename E2 , typename = typename std::enable_if<std::is_constructible<E,E2&&>::value>::type> | |
constexpr | result (failure< E2 > &&e) noexcept(std::is_nothrow_constructible< E, E2 &&>::value) |
Constructs the underlying error of this result. More... | |
template<typename E2 , typename = typename std::enable_if<detail::result_is_failure_assignable<E,const E2&>::value>::type> | |
auto | operator= (const failure< E2 > &other) noexcept(std::is_nothrow_assignable< E, const E2 &>::value) -> result & |
Perfect-forwarded assignment. More... | |
template<typename E2 , typename = typename std::enable_if<detail::result_is_failure_assignable<E,E2&&>::value>::type> | |
auto | operator= (failure< E2 > &&other) noexcept(std::is_nothrow_assignable< E, E2 &&>::value) -> result & |
Perfect-forwarded assignment. More... | |
RESULT_CPP14_CONSTEXPR auto | value () &&-> void |
Throws an exception if (*this) is in an error state. More... | |
RESULT_CPP14_CONSTEXPR auto | value () const &-> void |
Throws an exception if (*this) is in an error state. More... | |
RESULT_WARN_UNUSED constexpr auto | error () const &noexcept(std::is_nothrow_constructible< E >::value &&std::is_nothrow_copy_constructible< E >::value) -> E |
Returns the contained error, if one exists, or a default-constructed error value. More... | |
RESULT_WARN_UNUSED RESULT_CPP14_CONSTEXPR auto | error () &&noexcept(std::is_nothrow_constructible< E >::value &&std::is_nothrow_copy_constructible< E >::value) -> E |
Returns the contained error, if one exists, or a default-constructed error value. More... | |
template<typename String , typename = typename std::enable_if<( std::is_convertible<String,const std::string&>::value && std::is_copy_constructible<E>::value )>::type> | |
RESULT_CPP14_CONSTEXPR auto | expect (String &&message) const &-> void |
} More... | |
template<typename String , typename = typename std::enable_if<( std::is_convertible<String,const std::string&>::value && std::is_move_constructible<E>::value )>::type> | |
RESULT_CPP14_CONSTEXPR auto | expect (String &&message) &&-> void |
} More... | |
template<typename U > | |
RESULT_WARN_UNUSED constexpr auto | error_or (U &&default_error) const &-> error_type |
Returns the contained error if *this has an error, otherwise returns default_error . More... | |
template<typename U > | |
RESULT_WARN_UNUSED RESULT_CPP14_CONSTEXPR auto | error_or (U &&default_error) &&-> error_type |
Returns the contained error if *this has an error, otherwise returns default_error . More... | |
template<typename Fn > | |
RESULT_WARN_UNUSED constexpr auto | flat_map (Fn &&fn) const &-> detail::invoke_result_t< Fn > |
Invokes the function fn if (*this) contains no value. More... | |
template<typename Fn > | |
RESULT_WARN_UNUSED RESULT_CPP14_CONSTEXPR auto | flat_map (Fn &&fn) &&-> detail::invoke_result_t< Fn > |
Invokes the function fn if (*this) contains no value. More... | |
template<typename Fn > | |
RESULT_WARN_UNUSED constexpr auto | map (Fn &&fn) const &-> result< detail::invoke_result_t< Fn >, E > |
Invokes the function fn if (*this) contains no value. More... | |
template<typename Fn > | |
RESULT_WARN_UNUSED RESULT_CPP14_CONSTEXPR auto | map (Fn &&fn) &&-> result< detail::invoke_result_t< Fn >, E > |
Invokes the function fn if (*this) contains no value. More... | |
template<typename Fn > | |
constexpr auto | map_error (Fn &&fn) const &-> result< void, detail::invoke_result_t< Fn, const E &>> |
Invokes the function fn with the error of this result as the argument. More... | |
template<typename Fn > | |
RESULT_CPP14_CONSTEXPR auto | map_error (Fn &&fn) &&-> result< void, detail::invoke_result_t< Fn, E &&>> |
Invokes the function fn with the error of this result as the argument. More... | |
template<typename Fn > | |
RESULT_WARN_UNUSED constexpr auto | flat_map_error (Fn &&fn) const &-> detail::invoke_result_t< Fn, const E &> |
Invokes the function fn with the error of this result as the argument. More... | |
template<typename Fn > | |
RESULT_WARN_UNUSED RESULT_CPP14_CONSTEXPR auto | flat_map_error (Fn &&fn) &&-> detail::invoke_result_t< Fn, E &&> |
Invokes the function fn with the error of this result as the argument. More... | |
Friends | |
template<typename T2 , typename E2 > | |
class | result |
Partial specialization of result<void, E>
E | the underlying error type |
Definition at line 2659 of file result.hpp.
|
noexcept |
Constructs a result
object in a value state.
Basic Usage:
|
default |
Copy constructs this result.
If other contains an error, constructs an object that contains a copy of that error.
std::is_copy_constructible<E>::value
is false
std::is_trivially_copy_constructible<E>::value
are true
Basic Usage:
other | the result to copy |
|
default |
Move constructs a result.
If other contains an error, move-constructs this result from that error.
std::is_move_constructible<E>::value
is false
std::is_trivially_move_constructible<E>::value
are true
Basic Usage:
other | the result to move |
|
explicitnoexcept |
Converting copy constructor.
If other
contains a value, constructs a result object that is not in an error state – ignoring the value.
If other
contains an error, constructs a result object that contains an error, initialized as if direct-initializing (but not direct-list-initializing) an object of type E
.
std::is_constructible_v<E, const E2&>
is true
Basic Usage:
other | the other type to convert |
|
explicitnoexcept |
Converting move constructor.
If other
contains an error, constructs a result object that contains an error, initialized as if direct-initializing (but not direct-list-initializing) an object of type E&&.
std::is_constructible_v<E, const E2&>
is true
Basic Usage:
other | the other type to convert |
|
explicitnoexcept |
Constructs a result object in a value state.
This constructor exists primarily for symmetry with the result<T,E>
constructor. Unlike the T
overload, no variadic arguments may be supplied.
Basic Usage:
|
explicitnoexcept |
Constructs a result object that contains an error.
the value is initialized as if direct-initializing (but not direct-list-initializing) an object of type E
from the arguments std::forward<Args>(args)...
Basic Usage:
args | the arguments to pass to E 's constructor |
|
explicitnoexcept |
Constructs a result object that contains an error.
The value is initialized as if direct-initializing (but not direct-list-initializing) an object of type E
from the arguments std::forward<std::initializer_list<U>>(ilist)
, std::forward<Args>(args)...
Basic Usage:
ilist | An initializer list of entries to forward |
args | the arguments to pass to Es constructor |
|
noexcept |
Constructs the underlying error of this result.
E
is constructible from e
Basic Usage:
e | the failure error |
|
noexcept |
Constructs the underlying error of this result.
E
is constructible from e
Basic Usage:
e | the failure error |
RESULT_WARN_UNUSED constexpr auto cpp::bitwizeshift::result< void, E >::and_then | ( | U && | value | ) | const -> result< typename std::decay< U >::type, E > |
Returns a result containing value
if this result contains a value, otherwise returns a result containing the current error.
Basic Usage:
value | the value to return as a result |
value
if this contains a value
|
noexcept |
Returns the contained error, if one exists, or a default-constructed error value.
The error()
function will not throw any exceptions if E
does not throw any exceptions for the copy or move construction.
This is to limit the possible scope for exceptions, and to allow the error type to be treated as a "status"-like type, where the default-constructed case is considered the "good" state.
If this function is invoked on an rvalue of a result, the error is returned via move-construction
std::is_default_constructible<E>::value
is true
std::is_copy_constructible<E>::value
or std::is_move_constructible<E>::value
is true
E{}
represents the "good" (non-error) stateBasic Usage:
|
noexcept |
Returns the contained error, if one exists, or a default-constructed error value.
The error()
function will not throw any exceptions if E
does not throw any exceptions for the copy or move construction.
This is to limit the possible scope for exceptions, and to allow the error type to be treated as a "status"-like type, where the default-constructed case is considered the "good" state.
If this function is invoked on an rvalue of a result, the error is returned via move-construction
std::is_default_constructible<E>::value
is true
std::is_copy_constructible<E>::value
or std::is_move_constructible<E>::value
is true
E{}
represents the "good" (non-error) stateBasic Usage:
RESULT_WARN_UNUSED constexpr auto cpp::bitwizeshift::result< void, E >::error_or | ( | U && | default_error | ) | const & -> error_type |
Returns the contained error if *this
has an error, otherwise returns default_error
.
Basic Usage:
default_error | the error to use in case *this is empty |
default_error
RESULT_WARN_UNUSED RESULT_CPP14_CONSTEXPR auto cpp::bitwizeshift::result< void, E >::error_or | ( | U && | default_error | ) | && -> error_type |
Returns the contained error if *this
has an error, otherwise returns default_error
.
Basic Usage:
default_error | the error to use in case *this is empty |
default_error
RESULT_CPP14_CONSTEXPR auto cpp::bitwizeshift::result< void, E >::expect | ( | String && | message | ) | const & -> void |
}
Asserts an expectation that this result contains an error, throwing a bad_result_access on failure
If this function is invoked from an rvalue of result
, then this will consume the underlying error first, if there is one.
used
without requiring directly inspecting the underlying value. This is, in effect, equivalent to assert(res.has_value())
, however it uses exceptions to ensure the stack can be unwound, and exceptions invoked.Basic Usage:
message | the message to provide to this expectation |
RESULT_CPP14_CONSTEXPR auto cpp::bitwizeshift::result< void, E >::expect | ( | String && | message | ) | && -> void |
}
Asserts an expectation that this result contains an error, throwing a bad_result_access on failure
If this function is invoked from an rvalue of result
, then this will consume the underlying error first, if there is one.
used
without requiring directly inspecting the underlying value. This is, in effect, equivalent to assert(res.has_value())
, however it uses exceptions to ensure the stack can be unwound, and exceptions invoked.Basic Usage:
message | the message to provide to this expectation |
RESULT_WARN_UNUSED constexpr auto cpp::bitwizeshift::result< void, E >::flat_map | ( | Fn && | fn | ) | const & -> detail::invoke_result_t< Fn > |
Invokes the function fn
if (*this)
contains no value.
If this result contains an error, a result of the error is returned
The function being called must return a result
type or the program is ill-formed
If this is called on an rvalue of result
which contains an error, the returned result
is constructed from an rvalue of that error.
Basic Usage:
fn | the function to invoke with this |
RESULT_WARN_UNUSED RESULT_CPP14_CONSTEXPR auto cpp::bitwizeshift::result< void, E >::flat_map | ( | Fn && | fn | ) | && -> detail::invoke_result_t< Fn > |
Invokes the function fn
if (*this)
contains no value.
If this result contains an error, a result of the error is returned
The function being called must return a result
type or the program is ill-formed
If this is called on an rvalue of result
which contains an error, the returned result
is constructed from an rvalue of that error.
Basic Usage:
fn | the function to invoke with this |
RESULT_WARN_UNUSED constexpr auto cpp::bitwizeshift::result< void, E >::flat_map_error | ( | Fn && | fn | ) | const & -> detail::invoke_result_t< Fn, const E &> |
Invokes the function fn
with the error of this result as the argument.
If this result contains a value, a result of the value is returned
The function being called must return a result
type or the program is ill-formed
If this is called on an rvalue of result
which contains an error, the returned result
is constructed from an rvalue of that error.
Basic Usage:
fn | the function to invoke with this |
RESULT_WARN_UNUSED RESULT_CPP14_CONSTEXPR auto cpp::bitwizeshift::result< void, E >::flat_map_error | ( | Fn && | fn | ) | && -> detail::invoke_result_t< Fn, E &&> |
Invokes the function fn
with the error of this result as the argument.
If this result contains a value, a result of the value is returned
The function being called must return a result
type or the program is ill-formed
If this is called on an rvalue of result
which contains an error, the returned result
is constructed from an rvalue of that error.
Basic Usage:
fn | the function to invoke with this |
|
noexcept |
Returns true
if *this
contains an error.
Basic Usage:
true
if *this
contains an error, false
if *this
contains a value
|
noexcept |
Returns true
if *this
contains a value.
Basic Usage:
true
if *this
contains a value, false
if *this
contains an error RESULT_WARN_UNUSED constexpr auto cpp::bitwizeshift::result< void, E >::map | ( | Fn && | fn | ) | const & -> result< detail::invoke_result_t< Fn >, E > |
Invokes the function fn
if (*this)
contains no value.
If this result is an error, the result of this function is that error. Otherwise this function wraps the result and returns it as an result.
If this is called on an rvalue of result
which contains an error, the returned result
is constructed from an rvalue of that error.
Basic Usage:
fn | the function to invoke with this |
RESULT_WARN_UNUSED RESULT_CPP14_CONSTEXPR auto cpp::bitwizeshift::result< void, E >::map | ( | Fn && | fn | ) | && -> result< detail::invoke_result_t< Fn >, E > |
Invokes the function fn
if (*this)
contains no value.
If this result is an error, the result of this function is that error. Otherwise this function wraps the result and returns it as an result.
If this is called on an rvalue of result
which contains an error, the returned result
is constructed from an rvalue of that error.
Basic Usage:
fn | the function to invoke with this |
constexpr auto cpp::bitwizeshift::result< void, E >::map_error | ( | Fn && | fn | ) | const & -> result< void, detail::invoke_result_t< Fn, const E &>> |
Invokes the function fn
with the error of this result as the argument.
If this result contains a value, the result of this function is that value. Otherwise the function is called with that error and returns the result as a result.
If this is called on an rvalue of result
which contains a value, the returned result
is constructed from an rvalue of that value.
Basic Usage:
fn | the function to invoke with this |
RESULT_CPP14_CONSTEXPR auto cpp::bitwizeshift::result< void, E >::map_error | ( | Fn && | fn | ) | && -> result< void, detail::invoke_result_t< Fn, E &&>> |
Invokes the function fn
with the error of this result as the argument.
If this result contains a value, the result of this function is that value. Otherwise the function is called with that error and returns the result as a result.
If this is called on an rvalue of result
which contains a value, the returned result
is constructed from an rvalue of that value.
Basic Usage:
fn | the function to invoke with this |
|
explicitnoexcept |
Contextually convertible to true
if *this
does not contain an error.
This function exists to allow for simple, terse checks for containing a value.
Basic Usage:
true
if *this
contains a value, false
if *this
does not contain a value
|
default |
Copy assigns the result stored in other
.
std::is_nothrow_copy_constructible_v<E>
is true
this restriction guarantees that no 'valueless_by_exception` state may occur.true
:std::is_trivially_copy_constructible<E>::value
std::is_trivially_copy_assignable<E>::value
std::is_trivially_destructible<E>::value
other | the other result to copy |
|
default |
Move assigns the result stored in other
.
std::is_nothrow_copy_constructible_v<E>
is true
this restriction guarantees that no 'valueless_by_exception` state may occur.true
:std::is_trivially_move_constructible<E>::value
std::is_trivially_move_assignable<E>::value
std::is_trivially_destructible<E>::value
other | the other result to copy |
|
noexcept |
Copy-converts the state of other
.
If both this and other
contain an error, the underlying error is assigned through copy-assignment.
If other
contains a value state, this result is constructed in a value state.
If other
contans an error state, and this contains a value state, the underlying error is constructed through copy-construction.
std::is_nothrow_constructible_v<E, const E2&>
, std::is_assignable_v<E&, const E2&>
are all true
.other | the other result object to convert |
(*this)
|
noexcept |
Move-converts the state of other
.
If both this and other
contain an error, the underlying error is assigned through move-assignment.
If other
contains a value state, this result is constructed in a value state.
If other
contans an error state, and this contains a value state, the underlying error is constructed through move-construction.
std::is_nothrow_constructible_v<E, E2&&>
, std::is_assignable_v<E&, E2&&>
are all true
.other | the other result object to convert |
(*this)
|
noexcept |
Perfect-forwarded assignment.
Depending on whether *this
contains an error before the call, the contained error is either direct-initialized via forwarding the error, or assigned from forwarding the error
std::is_nothrow_constructible_v<E, E2>
is true
, andstd::is_assignable_v<E&, E2>
is true
other | the failure value to assign to this |
(*this)
|
noexcept |
Perfect-forwarded assignment.
Depending on whether *this
contains an error before the call, the contained error is either direct-initialized via forwarding the error, or assigned from forwarding the error
std::is_nothrow_constructible_v<E, E2>
is true
, andstd::is_assignable_v<E&, E2>
is true
other | the failure value to assign to this |
(*this)
RESULT_CPP14_CONSTEXPR auto cpp::bitwizeshift::result< void, E >::value | ( | ) | && -> void |
Throws an exception if (*this)
is in an error state.
This function exists for symmetry with cpp::result<T,E>
objects where T
contains a value.
If this contains an error, an exception is thrown containing the underlying error. The error is consumed propagating the same constness and refness of this result.
Basic Usage:
bad_result_access<E> | if *this does not contain a value. |
RESULT_CPP14_CONSTEXPR auto cpp::bitwizeshift::result< void, E >::value | ( | ) | const & -> void |
Throws an exception if (*this)
is in an error state.
This function exists for symmetry with cpp::result<T,E>
objects where T
contains a value.
If this contains an error, an exception is thrown containing the underlying error. The error is consumed propagating the same constness and refness of this result.
Basic Usage:
bad_result_access<E> | if *this does not contain a value. |