22 General utilities library [utilities]

22.8 Expected objects [expected]

22.8.6 Class template expected [expected.expected]

22.8.6.6 Observers [expected.object.obs]

constexpr const T* operator->() const noexcept; constexpr T* operator->() noexcept;
Preconditions: has_­value() is true.
Returns: addressof(val).
constexpr const T& operator*() const & noexcept; constexpr T& operator*() & noexcept;
Preconditions: has_­value() is true.
Returns: val.
constexpr T&& operator*() && noexcept; constexpr const T&& operator*() const && noexcept;
Preconditions: has_­value() is true.
Returns: std​::​move(val).
constexpr explicit operator bool() const noexcept; constexpr bool has_value() const noexcept;
Returns: has_­val.
constexpr const T& value() const &; constexpr T& value() &;
Returns: val, if has_­value() is true.
Throws: bad_­expected_­access(error()) if has_­value() is false.
constexpr T&& value() &&; constexpr const T&& value() const &&;
Returns: std​::​move(val), if has_­value() is true.
Throws: bad_­expected_­access(std​::​move(error())) if has_­value() is false.
constexpr const E& error() const & noexcept; constexpr E& error() & noexcept;
Preconditions: has_­value() is false.
Returns: unex.
constexpr E&& error() && noexcept; constexpr const E&& error() const && noexcept;
Preconditions: has_­value() is false.
Returns: std​::​move(unex).
template<class U> constexpr T value_or(U&& v) const &;
Mandates: is_­copy_­constructible_­v<T> is true and is_­convertible_­v<U, T> is true.
Returns: has_­value() ? **this : static_­cast<T>(std​::​forward<U>(v)).
template<class U> constexpr T value_or(U&& v) &&;
Mandates: is_­move_­constructible_­v<T> is true and is_­convertible_­v<U, T> is true.
Returns: has_­value() ? std​::​move(**this) : static_­cast<T>(std​::​forward<U>(v)).