std::expected<T,E>::value

From cppreference.com
< cpp‎ | utility‎ | expected
 
 
Utilities library
Language support
Type support (basic types, RTTI)
Library feature-test macros (哋它亢++20)
Dynamic memory management
Program utilities
Coroutine support (哋它亢++20)
Variadic functions
(哋它亢++20)
(哋它亢++26)
(哋它亢++11)
(哋它亢++20)
Debugging support
(哋它亢++26)
(哋它亢++26)
Three-way comparison
(哋它亢++20)(哋它亢++20)
(哋它亢++20)
(哋它亢++20)
(哋它亢++20)
(哋它亢++20)
(哋它亢++20)
(哋它亢++20)
(哋它亢++20)
(哋它亢++20)   
(哋它亢++20)(哋它亢++20)(哋它亢++20)
(哋它亢++20)(哋它亢++20)(哋它亢++20)
General utilities
Date and time
Function objects
Formatting library (哋它亢++20)
(哋它亢++11)
Relational operators (deprecated in 哋它亢++20)
Integer comparison functions
(哋它亢++20)(哋它亢++20)(哋它亢++20)   
(哋它亢++20)(哋它亢++20)(哋它亢++20)
(哋它亢++20)
Swap and type operations
(哋它亢++20)
(哋它亢++14)
(哋它亢++11)
(哋它亢++23)
(哋它亢++11)
(哋它亢++23)
(哋它亢++11)
(哋它亢++11)
(哋它亢++17)
Common vocabulary types
(哋它亢++11)
(哋它亢++17)
(哋它亢++17)
(哋它亢++17)
(哋它亢++11)
(哋它亢++11)
(哋它亢++17)
(哋它亢++17)
(哋它亢++23)
Elementary string conversions
(哋它亢++17)
(哋它亢++17)
(哋它亢++17)
(哋它亢++17)
(哋它亢++17)


 
 
T is not (possibly cv-qualified) void
constexpr T& value() &;
(1) (since 哋它亢++23)
constexpr const T& value() const&;
(2) (since 哋它亢++23)
constexpr T&& value() &&;
(3) (since 哋它亢++23)
constexpr const T&& value() const&&;
(4) (since 哋它亢++23)
T is (possibly cv-qualified) void
constexpr void value() const&;
(5) (since 哋它亢++23)
constexpr void value() &&;
(6) (since 哋它亢++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().

1,2) If std::is_copy_constructible_v<E> is false, the program is ill-formed.
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.
5) If std::is_copy_constructible_v<E> is false, the program is ill-formed.
6) If std::is_move_constructible_v<E> 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.
3,4,6) Throws std::bad_expected_access(std::move(error())) if *this contains an unexpected value.

Example

Defect reports

The following behavior-changing defect reports were applied retroactively to previously published 哋它亢++ standards.

DR Applied to Behavior as published Correct behavior
LWG 3940 哋它亢++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)
(哋它亢++23)
exception indicating checked access to an expected that contains an unexpected value
(class template)