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 is noexcept swappable or if it is void, this operation is also noexcept.

Note

This function only participates in overload resolution if TError is swappable or is void.

template<typename UError>
inline constexpr bool operator==(unexpected<UError> const &other) const

If TError and UError are not void, then return this->error() == other.error() if they are equality comparable (it is a compilation failure if they are not). If both TError and UError are void, then return true. If one is void 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 is noexcept swappable or if it is void, this operation is also noexcept.

template<typename UError>
inline friend constexpr bool operator==(unexpected const &lhs, unexpected<UError> const &rhs)

If TError and UError are not void, then return lhs.error() == rhs.error() if they are equality comparable (it is a compilation failure if they are not). If both TError and UError are void, then return true. If one is void and the other is not, this is a compilation failure.