22 General utilities library [utilities]

22.8 Expected objects [expected]

22.8.7 Partial specialization of expected for void types [expected.void]

22.8.7.2 Constructors [expected.void.ctor]

constexpr expected() noexcept;
Postconditions: has_­value() is true.
constexpr expected(const expected& rhs);
Effects: If rhs.has_­value() is false, direct-non-list-initializes unex with rhs.error().
Postconditions: rhs.has_­value() == this->has_­value().
Throws: Any exception thrown by the initialization of unex.
Remarks: This constructor is defined as deleted unless is_­copy_­constructible_­v<E> is true.
This constructor is trivial if is_­trivially_­copy_­constructible_­v<E> is true.
constexpr expected(expected&& rhs) noexcept(is_nothrow_move_constructible_v<E>);
Constraints: is_­move_­constructible_­v<E> is true.
Effects: If rhs.has_­value() is false, direct-non-list-initializes unex with std​::​move(rhs.error()).
Postconditions: rhs.has_­value() is unchanged; rhs.has_­value() == this->has_­value() is true.
Throws: Any exception thrown by the initialization of unex.
Remarks: This constructor is trivial if is_­trivially_­move_­constructible_­v<E> is true.
template<class U, class G> constexpr explicit(!is_convertible_v<const G&, E>) expected(const expected<U, G>& rhs); template<class U, class G> constexpr explicit(!is_convertible_v<G, E>) expected(expected<U, G>&& rhs);
Let GF be const G& for the first overload and G for the second overload.
Constraints:
  • is_­void_­v<U> is true; and
  • is_­constructible_­v<E, GF> is true; and
  • is_­constructible_­v<unexpected<E>, expected<U, G>&> is false; and
  • is_­constructible_­v<unexpected<E>, expected<U, G>> is false; and
  • is_­constructible_­v<unexpected<E>, const expected<U, G>&> is false; and
  • is_­constructible_­v<unexpected<E>, const expected<U, G>> is false.
Effects: If rhs.has_­value() is false, direct-non-list-initializes unex with std​::​forward<GF>(rhs.error()).
Postconditions: rhs.has_­value() is unchanged; rhs.has_­value() == this->has_­value() is true.
Throws: Any exception thrown by the initialization of unex.
template<class G> constexpr explicit(!is_convertible_v<const G&, E>) expected(const unexpected<G>& e); template<class G> constexpr explicit(!is_convertible_v<G, E>) expected(unexpected<G>&& e);
Let GF be const G& for the first overload and G for the second overload.
Constraints: is_­constructible_­v<E, GF> is true.
Effects: Direct-non-list-initializes unex with std​::​forward<GF>(e.value()).
Postconditions: has_­value() is false.
Throws: Any exception thrown by the initialization of unex.
constexpr explicit expected(in_place_t) noexcept;
Postconditions: has_­value() is true.
template<class... Args> constexpr explicit expected(unexpect_t, Args&&... args);
Constraints: is_­constructible_­v<E, Args...> is true.
Effects: Direct-non-list-initializes unex with std​::​forward<Args>(args)....
Postconditions: has_­value() is false.
Throws: Any exception thrown by the initialization of unex.
template<class U, class... Args> constexpr explicit expected(unexpect_t, initializer_list<U> il, Args&&... args);
Constraints: is_­constructible_­v<E, initializer_­list<U>&, Args...> is true.
Effects: Direct-non-list-initializes unex with il, std​::​forward<Args>(args)....
Postconditions: has_­value() is false.
Throws: Any exception thrown by the initialization of unex.