[expected.object.cons] (original) (raw)

22 General utilities library [utilities]

22.8 Expected objects [expected]

22.8.6 Class template expected [expected.expected]

22.8.6.2 Constructors [expected.object.cons]

The exposition-only variable template _converts-from-any-cvref_defined in [optional.ctor]is used by some constructors for expected.

Constraints: is_default_constructible_v<T> is true.

Effects: Value-initializes val.

Postconditions: has_value() is true.

Throws: Any exception thrown by the initialization of val.

constexpr expected(const expected& rhs);

Effects: If rhs.has_value() is true, direct-non-list-initializes val with *rhs.

Otherwise, direct-non-list-initializes unex with rhs.error().

Postconditions: rhs.has_value() == this->has_value().

Throws: Any exception thrown by the initialization of val or unex.

Remarks: This constructor is defined as deleted unless

This constructor is trivial if

constexpr expected(expected&& rhs) noexcept(_see below_);

Constraints:

Effects: If rhs.has_value() is true, direct-non-list-initializes val with std​::​move(*rhs).

Otherwise, 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 val or unex.

Remarks: The exception specification is equivalent tois_nothrow_move_constructible_v<T> &&is_nothrow_move_constructible_v<E>.

This constructor is trivial if

template<class U, class G> constexpr explicit(_see below_) expected(const expected<U, G>& rhs);template<class U, class G> constexpr explicit(_see below_) expected(expected<U, G>&& rhs);

Let:

Constraints:

Effects: If rhs.has_value(), direct-non-list-initializes val with std​::​forward<UF>(*rhs).

Otherwise, 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 val or unex.

Remarks: The expression inside explicit is equivalent to!is_convertible_v<UF, T> || !is_convertible_v<GF, E>.

template<class U = remove_cv_t<T>> constexpr explicit(!is_convertible_v<U, T>) expected(U&& v);

Constraints:

Effects: Direct-non-list-initializes val with std​::​forward<U>(v).

Postconditions: has_value() is true.

Throws: Any exception thrown by the initialization of val.

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 andG for the second overload.

Constraints: is_constructible_v<E, GF> is true.

Effects: Direct-non-list-initializes unex with std​::​forward<GF>(e.error()).

Postconditions: has_value() is false.

Throws: Any exception thrown by the initialization of unex.

template<class... Args> constexpr explicit expected(in_place_t, Args&&... args);

Constraints: is_constructible_v<T, Args...> is true.

Effects: Direct-non-list-initializes val with std​::​forward<Args>(args)....

Postconditions: has_value() is true.

Throws: Any exception thrown by the initialization of val.

template<class U, class... Args> constexpr explicit expected(in_place_t, initializer_list<U> il, Args&&... args);

Constraints: is_constructible_v<T, initializer_list<U>&, Args...> is true.

Effects: Direct-non-list-initializes val withil, std​::​forward<Args>(args)....

Postconditions: has_value() is true.

Throws: Any exception thrown by the initialization of val.

template<class... Args> constexpr explicit expected(unexpect_t, Args&&... args);

Constraints: is_constructible_v<E, Args...> is true.

Effects: Direct-non-list-initializes unex withstd​::​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 withil, std​::​forward<Args>(args)....

Postconditions: has_value() is false.

Throws: Any exception thrown by the initialization of unex.