|
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Main template | ||
constexpr expected(); | (1) | (since C++23) |
constexpr expected(const expected& other); | (2) | (since C++23) |
constexpr expected( expected&& other)noexcept(/* see below */); | (3) | (since C++23) |
template<class U,class G> constexpr expected(const expected<U, G>& other); | (4) | (since C++23) (conditionally explicit) |
template<class U,class G> constexpr expected( expected<U, G>&& other); | (5) | (since C++23) (conditionally explicit) |
template<class U=std::remove_cv_t<T>> constexprexplicit(!std::is_convertible_v<U, T>) expected( U&& v); | (6) | (since C++23) |
template<class G> constexprexplicit(!std::is_convertible_v<const G&, E>) | (7) | (since C++23) |
template<class G> constexprexplicit(!std::is_convertible_v<G, E>) | (8) | (since C++23) |
template<class...Args> constexprexplicit expected(std::in_place_t, Args&&...args); | (9) | (since C++23) |
template<class U,class...Args> constexprexplicit | (10) | (since C++23) |
template<class...Args> constexprexplicit expected(std::unexpect_t, Args&&...args); | (11) | (since C++23) |
template<class U,class...Args> constexprexplicit | (12) | (since C++23) |
void partial specialization | ||
constexpr expected(); | (13) | (since C++23) |
constexpr expected(const expected& other); | (14) | (since C++23) |
constexpr expected( expected&& other) noexcept(std::is_nothrow_move_constructible_v<E>); | (15) | (since C++23) |
template<class U,class G> constexprexplicit(!std::is_convertible_v<const G&, E>) | (16) | (since C++23) |
template<class U,class G> constexprexplicit(!std::is_convertible_v<G, E>) | (17) | (since C++23) |
template<class G> constexprexplicit(!std::is_convertible_v<const G&, E>) | (18) | (since C++23) |
template<class G> constexprexplicit(!std::is_convertible_v<G, E>) | (19) | (since C++23) |
constexprexplicit expected(std::in_place_t); | (20) | (since C++23) |
template<class...Args> constexprexplicit expected(std::unexpect_t, Args&&...args); | (21) | (since C++23) |
template<class U,class...Args> constexprexplicit | (22) | (since C++23) |
Constructs a newexpected object.
Contents |
| other | - | anotherexpected object whose contained value is copied |
| e | - | std::unexpected object whose contained value is copied |
| v | - | value with which to initialize the contained value |
| args | - | arguments with which to initialize the contained value |
| il | - | initializer list with which to initialize the contained value |
| Overload | Initialization method | Initializer for... | has_value()after construction | |
|---|---|---|---|---|
| the expected value | the unexpected value | |||
| (1) | Value | (empty) | - | true |
| (2) | Direct (non-list) | *other | other.error() | other.has_value()
|
| (3) | std::move(*other) | std::move(other.error()) | ||
| (4) | std::forward<const U&> (*other) | std::forward<const G&> (other.error()) | ||
| (5) | std::forward<U>(*other) | std::forward<G> (other.error()) | ||
| (6) | std::forward<U>(v) | - | true | |
| (7) | - | std::forward<const G&> (e.error()) | false | |
| (8) | std::forward<G>(e.error()) | |||
| (9) | std::forward<Args>(args)... | - | true | |
| (10) | il, std::forward<Args>(args)... | |||
| (11) | - | std::forward<Args>(args)... | false | |
| (12) | il, std::forward<Args>(args)... | |||
| Overload | Initialization method | Initializer for the unexpected value | has_value() after construction |
|---|---|---|---|
| (13) | N/A | - | true |
| (14) | Direct (non-list) | rhs.error() | other.has_value()
|
| (15) | std::move(rhs.error) | ||
| (16) | std::forward<const G&>(rhs.error()) | ||
| (17) | std::forward<G>(rhs.error()) | ||
| (18) | std::forward<const G&>(e.error()) | false | |
| (19) | std::forward<G>(e.error()) | ||
| (20) | N/A | - | true |
| (21) | Direct (non-list) | std::forward<Args>(args)... | false |
| (22) | il,std::forward<Args>(args)... |
T is not (possibly cv-qualified)bool, the following 8 values are allfalse:std::unexpected.T is (possibly cv-qualified)bool,std::remove_cvref_t<U> is not a specialization ofstd::expected.| This section is incomplete Reason: no example |
The following behavior-changing defect reports were applied retroactively to previously published C++ standards.
| DR | Applied to | Behavior as published | Correct behavior |
|---|---|---|---|
| LWG 3886 | C++23 | the default template argument of overload(6) wasT | changed tostd::remove_cv_t<T> |
(C++23) | represented as an unexpected value (class template)[edit] |
| in-place construction tag (tag)[edit] | |
(C++23) | in-place construction tag for unexpected value inexpected(tag)[edit] |