Holds either a success value or an error value.
More...
#include <expected.h>
|
| | Expected (const Expected &other)=default |
| | Copies the contained alternative. More...
|
| |
| | Expected (Expected &&other)=default |
| | Moves the contained alternative. More...
|
| |
| template<typename U > |
| requires std::is_convertible_v< U, T > std::is_convertible_v< U, E > | Expected (U &&value) |
| | Constructs the variant alternative selected by std::variant<T, E>. More...
|
| |
| template<typename U > |
| requires std::is_convertible_v< U, E > | Expected (Unexpected< U > &&unex) |
| | Constructs an error result from an unexpected value. More...
|
| |
| constexpr bool | has_value () const noexcept |
| |
| constexpr | operator bool () const noexcept |
| |
| const T & | value () const |
| |
| const E & | error () const |
| |
| constexpr const T * | operator-> () const noexcept |
| |
template<typename T, typename E>
class quicr::Expected< T, E >
Holds either a success value or an error value.
- Template Parameters
-
| T | Success type. |
| E | Error type. |
- Note
- This class is not internally synchronized. References and pointers returned by accessors are invalidated when the
Expected object is destroyed or moved.
- Examples
- simple_publish/main.cpp, and simple_subscribe/main.cpp.
◆ Expected() [1/4]
template<typename T , typename E >
Copies the contained alternative.
- Parameters
-
◆ Expected() [2/4]
template<typename T , typename E >
Moves the contained alternative.
- Parameters
-
◆ Expected() [3/4]
template<typename T , typename E >
template<typename U >
Constructs the variant alternative selected by std::variant<T, E>.
- Template Parameters
-
| U | Type convertible to T or E. |
- Parameters
-
| value | Value forwarded to the variant. |
- Exceptions
-
| Any | exception thrown while constructing the selected alternative. |
◆ Expected() [4/4]
template<typename T , typename E >
template<typename U >
Constructs an error result from an unexpected value.
- Template Parameters
-
| U | Error source type convertible to E. |
- Parameters
-
| unex | Wrapper whose error is copied into this result. |
◆ error()
template<typename T , typename E >
- Returns
- A reference to the error value.
- Exceptions
-
| std::bad_variant_access | If this object contains a success value. |
◆ has_value()
template<typename T , typename E >
- Returns
true when the success alternative is active.
◆ operator bool()
template<typename T , typename E >
|
|
inlineexplicitconstexprnoexcept |
◆ operator->()
template<typename T , typename E >
- Returns
- A pointer to the success value.
- Warning
- Calling this while the object contains an error terminates the process because the function is
noexcept and its internal value access throws.
◆ value()
template<typename T , typename E >
- Returns
- A reference to the success value.
- Exceptions
-
| std::bad_variant_access | If this object contains an error. |
The documentation for this class was generated from the following file: