omni::unexpected
Defined in omni/Expected.h
-
template<typename TError>
class unexpected : public omni::detail::UnexpectedImpl<TError> The unexpected value of an expected monad. This is used as a convenient mechanism to report the error case when constructing an
expected
return.expected<string, Result> foo(bool x) { // C++17: TError is deduced as `Result` return unexpected(kResultNotImplemented); }
Public Functions
-
template<typename UError, typename IsNoexcept = std::enable_if_t<carb::cpp::conjunction<std::is_same<TError, UError>, typename omni::detail::ExpectedTransformIfNonVoid<carb::cpp::is_swappable, UError, std::true_type>::type>::value, typename omni::detail::ExpectedTransformIfNonVoid<carb::cpp::is_nothrow_swappable, UError, std::true_type>::type>>
inline constexpr void swap(unexpected &other) noexcept(IsNoexcept::value) Swap the contents of this instance with other.
If
TError
isnoexcept
swappable or if it isvoid
, this operation is alsonoexcept
.Note
This function only participates in overload resolution if
TError
is swappable or isvoid
.
-
template<typename UError>
inline constexpr bool operator==(unexpected<UError> const &other) const If
TError
andUError
are notvoid
, then returnthis->error() == other.error()
if they are equality comparable (it is a compilation failure if they are not). If bothTError
andUError
arevoid
, then returntrue
. If one isvoid
and the other is not, this is a compilation failure.
Friends
-
template<typename UError, typename IsNoexcept = std::enable_if_t<omni::detail::ExpectedTransformIfNonVoid<carb::cpp::is_swappable, UError, std::true_type>::type::value, typename omni::detail::ExpectedTransformIfNonVoid<carb::cpp::is_nothrow_swappable, UError, std::true_type>::type>>
inline friend constexpr void swap(unexpected &lhs, unexpected<UError> &rhs) noexcept(IsNoexcept::value) Swap the contents of lhs with rhs.
If
UError
isnoexcept
swappable or if it isvoid
, this operation is alsonoexcept
.
-
template<typename UError>
inline friend constexpr bool operator==(unexpected const &lhs, unexpected<UError> const &rhs) If
TError
andUError
are notvoid
, then returnlhs.error() == rhs.error()
if they are equality comparable (it is a compilation failure if they are not). If bothTError
andUError
arevoid
, then returntrue
. If one isvoid
and the other is not, this is a compilation failure.
-
template<typename UError, typename IsNoexcept = std::enable_if_t<carb::cpp::conjunction<std::is_same<TError, UError>, typename omni::detail::ExpectedTransformIfNonVoid<carb::cpp::is_swappable, UError, std::true_type>::type>::value, typename omni::detail::ExpectedTransformIfNonVoid<carb::cpp::is_nothrow_swappable, UError, std::true_type>::type>>