1#ifndef FUSED_EXPECTED_H
2#define FUSED_EXPECTED_H
84template <
typename T,
typename E>
101 void destroy() noexcept
105 if constexpr (!is_trivially_destructible_v<T>)
122 Expected(T &&v)
noexcept(is_nothrow_move_constructible_v<T>)
123 : val_(
move(v)), has_value_(true)
132 : err_(u.error), has_value_(
false)
145 : has_value_(other.has_value_)
148 new (&val_) T(
move(other.val_));
164 has_value_ = other.has_value_;
166 new (&val_) T(
move(other.val_));
189 explicit operator bool() const noexcept {
return has_value_; }
202 T &
value() noexcept {
return val_; }
208 const T &
value() const noexcept {
return val_; }
240 E
error() const noexcept {
return err_; }
A discriminated union holding either a success value or an error.
Definition expected.h:86
E error() const noexcept
Access the error code.
Definition expected.h:240
~Expected() noexcept
Destructor. Destroys the active union member.
Definition expected.h:182
T & operator*() noexcept
Dereference operator — access the success value.
Definition expected.h:214
T val_
Definition expected.h:89
Expected(Expected &&other) noexcept(is_nothrow_move_constructible_v< T >)
Move constructor.
Definition expected.h:144
T * operator->() noexcept
Arrow operator — access members of the success value.
Definition expected.h:226
const T & value() const noexcept
Access the success value by const reference.
Definition expected.h:208
bool has_value() const noexcept
Returns true if the Expected holds a success value.
Definition expected.h:194
Expected & operator=(Expected &&other) noexcept(is_nothrow_move_constructible_v< T >)
Move assignment.
Definition expected.h:159
E err_
Definition expected.h:90
T & value() noexcept
Access the success value by reference.
Definition expected.h:202
Expected(Unexpected< E > u) noexcept
Construct in the error state from an Unexpected tag.
Definition expected.h:131
E error_type
Definition expected.h:114
Expected & operator=(const Expected &)=delete
Deleted — Expected is move-only to prevent accidental copies.
const T & operator*() const noexcept
Dereference operator (const) — access the success value.
Definition expected.h:220
Expected(const Expected &)=delete
Deleted — Expected is move-only to prevent accidental copies.
Expected(T &&v) noexcept(is_nothrow_move_constructible_v< T >)
Construct in the success state by moving a value in.
Definition expected.h:122
T value_type
Definition expected.h:113
const T * operator->() const noexcept
Arrow operator (const) — access members of the success value.
Definition expected.h:232
constexpr remove_reference_t< T > && move(T &&t) noexcept
Cast to rvalue reference (replacement for std::move).
Definition simple_type_traits.h:178
Tag type for constructing an Expected in the error state.
Definition expected.h:30
E error
The error value.
Definition expected.h:31