|
| constexpr | expected (expected const &other) |
| constexpr | expected (expected &&other) noexcept(std::is_nothrow_move_constructible_v< T > &&std::is_nothrow_move_constructible_v< E >) |
| template<typename U = T, typename = std::enable_if_t< !std::is_same_v<std::decay_t<U>, expected> && !std::is_same_v<std::decay_t<U>, std::in_place_t> && !std::is_same_v<std::decay_t<U>, unexpected<E>> && std::is_constructible_v<T, U>>> |
| constexpr | expected (U &&value, std::enable_if_t< std::is_convertible_v< U, T >, int >=0) |
| template<typename U = T, typename = std::enable_if_t<!std::is_same_v<std::decay_t<U>, expected> && !std::is_same_v<std::decay_t<U>, std::in_place_t> && !std::is_same_v<std::decay_t<U>, unexpected<E>> && std::is_constructible_v<T, U> && !std::is_convertible_v<U, T>>> |
| constexpr | expected (U &&value) |
| template<typename... Args, typename = std::enable_if_t<std::is_constructible_v<T, Args...>>> |
| constexpr | expected (std::in_place_t, Args &&... args) |
| constexpr | expected (unexpected< E > const &ue) |
| constexpr | expected (unexpected< E > &&ue) |
| template<typename... Args> |
| constexpr | expected (unexpect_t, Args &&... args) |
| constexpr auto | operator= (expected const &other) -> expected & |
| constexpr auto | operator= (expected &&other) noexcept(std::is_nothrow_move_constructible_v< T > &&std::is_nothrow_move_constructible_v< E >) -> expected & |
| template<typename U = T, typename = std::enable_if_t<!std::is_same_v<std::decay_t<U>, expected> && std::is_constructible_v<T, U>>> |
| constexpr auto | operator= (U &&value) -> expected & |
| constexpr auto | operator= (unexpected< E > const &ue) -> expected & |
| constexpr auto | operator= (unexpected< E > &&ue) -> expected & |
| constexpr auto | operator-> () const noexcept -> T const * |
| constexpr auto | operator-> () noexcept -> T * |
| constexpr auto | operator* () const &noexcept -> T const & |
| constexpr auto | operator* () &noexcept -> T & |
| constexpr auto | operator* () const &&noexcept -> T const && |
| constexpr auto | operator* () &&noexcept -> T && |
| constexpr | operator bool () const noexcept |
| constexpr auto | has_value () const noexcept -> bool |
| constexpr auto | value () const &-> T const & |
| constexpr auto | value () &-> T & |
| constexpr auto | value () const &&-> T const && |
| constexpr auto | value () &&-> T && |
| constexpr auto | error () const &noexcept -> E const & |
| constexpr auto | error () &noexcept -> E & |
| constexpr auto | error () const &&noexcept -> E const && |
| constexpr auto | error () &&noexcept -> E && |
| template<typename U> |
| constexpr auto | value_or (U &&default_value) const &-> T |
| template<typename U> |
| constexpr auto | value_or (U &&default_value) &&-> T |
| template<typename... Args> |
| constexpr auto | emplace (Args &&... args) -> T & |
| constexpr void | swap (expected &other) noexcept(std::is_nothrow_move_constructible_v< T > &&std::is_nothrow_move_constructible_v< E > &&std::is_nothrow_swappable_v< T > &&std::is_nothrow_swappable_v< E >) |
| template<typename F> |
| constexpr auto | and_then (F &&f) & |
| template<typename F> |
| constexpr auto | and_then (F &&f) const & |
| template<typename F> |
| constexpr auto | and_then (F &&f) && |
| template<typename F> |
| constexpr auto | and_then (F &&f) const && |
| template<typename F> |
| constexpr auto | or_else (F &&f) & |
| template<typename F> |
| constexpr auto | or_else (F &&f) const & |
| template<typename F> |
| constexpr auto | or_else (F &&f) && |
| template<typename F> |
| constexpr auto | or_else (F &&f) const && |
| template<typename F> |
| constexpr auto | transform (F &&f) & |
| template<typename F> |
| constexpr auto | transform (F &&f) const & |
| template<typename F> |
| constexpr auto | transform (F &&f) && |
| template<typename F> |
| constexpr auto | transform (F &&f) const && |
| template<typename F> |
| constexpr auto | transform_error (F &&f) & |
| template<typename F> |
| constexpr auto | transform_error (F &&f) const & |
| template<typename F> |
| constexpr auto | transform_error (F &&f) && |
| template<typename F> |
| constexpr auto | transform_error (F &&f) const && |
|
| template<typename T2, typename E2> |
| constexpr friend auto | operator== (expected const &lhs, expected< T2, E2 > const &rhs) -> bool |
| template<typename T2, typename E2> |
| constexpr friend auto | operator!= (expected const &lhs, expected< T2, E2 > const &rhs) -> bool |
| template<typename T2, typename = std::enable_if_t<!std::is_same_v<expected, std::decay_t<T2>>>> |
| constexpr friend auto | operator== (expected const &lhs, const T2 &rhs) -> bool |
| template<typename T2, typename = std::enable_if_t<!std::is_same_v<expected, std::decay_t<T2>>>> |
| constexpr friend auto | operator== (const T2 &lhs, expected const &rhs) -> bool |
| template<typename T2, typename = std::enable_if_t<!std::is_same_v<expected, std::decay_t<T2>>>> |
| constexpr friend auto | operator!= (expected const &lhs, const T2 &rhs) -> bool |
| template<typename T2, typename = std::enable_if_t<!std::is_same_v<expected, std::decay_t<T2>>>> |
| constexpr friend auto | operator!= (const T2 &lhs, expected const &rhs) -> bool |
| template<typename E2> |
| constexpr friend auto | operator== (expected const &lhs, unexpected< E2 > const &rhs) -> bool |
| template<typename E2> |
| constexpr friend auto | operator== (unexpected< E2 > const &lhs, expected const &rhs) -> bool |
| template<typename E2> |
| constexpr friend auto | operator!= (expected const &lhs, unexpected< E2 > const &rhs) -> bool |
| template<typename E2> |
| constexpr friend auto | operator!= (unexpected< E2 > const &lhs, expected const &rhs) -> bool |
template<typename T, typename E = std::error_code>
class threadschedule::expected< T, E >
A result type that holds either a value of type T or an error of type E.
This is a polyfill for std::expected<T,E> (C++23). It provides value-semantic storage: copyable when both T and E are copyable, movable when both are movable.
- Template Parameters
-
| T | The value type. Must be destructible. The default constructor is available only when T is default-constructible. |
| E | The error type. Defaults to std::error_code. |
- Thread safety
- This is a plain value type with no internal synchronization. Concurrent access from multiple threads requires external locking.
- Implementation notes
- Storage is implemented as a union with placement new / manual destructor calls to avoid requiring default-constructibility of either
T or E.
- Monadic operations
- The following combinators are provided (matching the C++23 specification):
and_then(f) – if has_value(), invoke f with the value and return the result
or_else(f) – if in error state, invoke f with the error and return the result
transform(f) – if has_value(), apply f to the value and wrap the result
transform_error(f) – if in error state, apply f to the error and wrap the result
Definition at line 214 of file expected.hpp.
template<typename T, typename E = std::error_code>
template<typename U = T, typename = std::enable_if_t< !std::is_same_v<std::decay_t<U>, expected> && !std::is_same_v<std::decay_t<U>, std::in_place_t> && !std::is_same_v<std::decay_t<U>, unexpected<E>> && std::is_constructible_v<T, U>>>
template<typename T, typename E = std::error_code>
template<typename U = T, typename = std::enable_if_t<!std::is_same_v<std::decay_t<U>, expected> && !std::is_same_v<std::decay_t<U>, std::in_place_t> && !std::is_same_v<std::decay_t<U>, unexpected<E>> && std::is_constructible_v<T, U> && !std::is_convertible_v<U, T>>>