34 : error_{ std::forward<T>(value) }
43 template<
typename... Args>
45 : error_{ std::forward<Args>(args)... }
50 const E&
error()
const {
return error_; }
63 template<
typename T,
typename E>
80 requires std::is_convertible_v<U, T> || std::is_convertible_v<U, E>
82 : data_(std::forward<U>(
value))
92 requires std::is_convertible_v<U, E>
99 constexpr
bool has_value() const noexcept {
return data_.index() == 0; }
102 constexpr
explicit operator bool() const noexcept {
return has_value(); }
108 const T&
value()
const {
return std::get<0>(data_); }
114 const E&
error()
const {
return std::get<1>(data_); }
124 std::variant<T, E> data_;
145 : error_(std::forward<U>(
value))
155 requires std::is_convertible_v<U, E>
157 : error_(unex.
error())
162 bool has_value() const noexcept {
return !error_.has_value(); }
165 explicit operator bool() const noexcept {
return has_value(); }
171 const E&
error()
const {
return error_.value(); }
174 std::optional<E> error_;
requires std::is_convertible_v< U, E > Expected(Unexpected< U > &&unex)
Constructs an error result from an unexpected value.
Definition: expected.h:156
Expected(U &&value)
Constructs an error result.
Definition: expected.h:144
bool has_value() const noexcept
Definition: expected.h:162
Expected()=default
Constructs a successful result.
const E & error() const
Definition: expected.h:171
Holds either a success value or an error value.
Definition: expected.h:65
const E & error() const
Definition: expected.h:114
const T & value() const
Definition: expected.h:108
requires std::is_convertible_v< U, T > std::is_convertible_v< U, E > Expected(U &&value)
Constructs the variant alternative selected by std::variant<T, E>.
Definition: expected.h:81
Expected(const Expected &other)=default
Copies the contained alternative.
Expected(Expected &&other)=default
Moves the contained alternative.
constexpr bool has_value() const noexcept
Definition: expected.h:99
constexpr const T * operator->() const noexcept
Definition: expected.h:121
requires std::is_convertible_v< U, E > Expected(Unexpected< U > &&unex)
Constructs an error result from an unexpected value.
Definition: expected.h:93
Wrapper that explicitly marks a value as an error.
Definition: expected.h:19
const E & error() const
Definition: expected.h:50
Unexpected(const Unexpected &other)=default
Copies an error wrapper.
Unexpected(Args &&... args)
Constructs the error in place from arguments.
Definition: expected.h:44
Unexpected(Unexpected &&other)=default
Moves an error wrapper.
Unexpected(T &&value)
Constructs the error from a forwarded value.
Definition: expected.h:33
Definition: attributes.h:13