On this page
std::expected<T,E>::value
|
||
|
(1) | (since C++23) |
|
(2) | (since C++23) |
|
(3) | (since C++23) |
|
(4) | (since C++23) |
|
||
|
(5) | (since C++23) |
|
(6) | (since C++23) |
If *this
contains an expected value, returns a reference to the contained value. Returns nothing if T
is (possibly cv-qualified) void.
Otherwise, throws an exception of type std::bad_expected_access<std::decay_t<E>> that contains a copy of error()
.
3,4) If
std::is_copy_constructible_v<E>
or std::is_constructible_v<E, decltype(std::move(error()))>
is false
, the program is ill-formed.
Parameters
(none)
Return value
1-4) The expected value contained in
*this
.
5,6) (none)
Exceptions
1,2,5) Throws
std::bad_expected_access(std::as_const(error()))
if *this
contains an unexpected value.
Example
Defect reports
The following behavior-changing defect reports were applied retroactively to previously published C++ standards.
DR | Applied to | Behavior as published | Correct behavior |
---|---|---|---|
LWG 3940 | C++23 | E was not required to be copy/move-constructible for overloads (5,6) |
required |
See also
returns the expected value if present, another value otherwise (public member function) |
|
accesses the expected value (public member function) |
|
returns the unexpected value (public member function) |
|
(C++23)
|
exception indicating checked access to an expected that contains an unexpected value (class template) |
© cppreference.com
Licensed under the Creative Commons Attribution-ShareAlike Unported License v3.0.
https://en.cppreference.com/w/cpp/utility/expected/value