Namespaces
Variants
Views
Actions

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

From cppreference.com
< cpp‎ | utility‎ | expected
 
 
Utilities library
General utilities
Date and time
Function objects
Formatting library (C++20)
(C++11)
Relational operators (deprecated in C++20)
Integer comparison functions
(C++20)(C++20)(C++20)   
(C++20)
Swap and type operations
(C++14)
(C++11)
(C++11)
(C++11)
(C++17)
Common vocabulary types
(C++11)
(C++17)
(C++17)
(C++17)
(C++11)
(C++17)
(C++23)
Elementary string conversions
(C++17)
(C++17)
 
std::expected
Member functions
Observers
expected::value
(C++23)
Modifiers
Non-member functions
(C++23)
(C++23)
Helper classes
(C++23)
(C++23)(C++23)
 
constexpr T& value() &;
(1) (since C++23)
constexpr const T& value() const&;
(2) (since C++23)
constexpr T&& value() &&;
(3) (since C++23)
constexpr const T&& value() const&&;
(4) (since C++23)
1,2) If *this contains an expected value, returns the expected value (by copy), or nothing if T is (possibly cv-qualified) void.
Otherwise, throws std::bad_expected_access containing the unexpected value contained in *this.
If std::is_copy_constructible_v<E> is false, the program is ill-formed.
3,4) If *this contains an expected value, returns the expected value (by moving), or nothing if T is (possibly cv-qualified) void.
Otherwise, throws std::bad_expected_access containing the unexpected value contained in *this.
If std::is_copy_constructible_v<E> or std::is_constructible_v<E, decltype(std::move(error()))> is false, the program is ill-formed.

Contents

[edit] Parameters

(none)

[edit] Return value

1-4) The expected value contained in *this.

[edit] Exceptions

1,2) Throws std::bad_expected_access(std::as_const(error())) if *this contain an unexpected value.
3,4) Throws std::bad_expected_access(std::move(error())) if *this contain an unexpected value.

[edit] Example

[edit] See also

(C++23)
returns the expected value if present, another value otherwise
(public member function) [edit]
accesses the expected value
(public member function) [edit]
(C++23)
returns the unexpected value
(public member function) [edit]
exception indicating checked access to an expected that contains an unexpected value
(class template) [edit]