ThreadSchedule 1.0.0
Modern C++ thread management library
Loading...
Searching...
No Matches
expected.hpp File Reference

Polyfill for std::expected (C++23) for pre-C++23 compilers. More...

#include <exception>
#include <functional>
#include <system_error>
#include <type_traits>
#include <utility>
Include dependency graph for expected.hpp:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  threadschedule::unexpect_t
 Tag type used to construct an expected in the error state. More...
class  threadschedule::unexpected< E >
 Exception thrown by expected::value() when the object is in the error state. More...
class  threadschedule::expected< T, E >
 A result type that holds either a value of type T or an error of type E. More...
class  threadschedule::expected< void, E >
 Specialization of expected for operations that produce no value. More...

Macros

#define THREADSCHEDULE_HAS_STD_EXPECTED   0
#define THREADSCHEDULE_EXPECTED_THROW(ex)

Functions

template<typename T, typename E>
constexpr void threadschedule::swap (expected< T, E > &lhs, expected< T, E > &rhs) noexcept(noexcept(lhs.swap(rhs)))

Variables

constexpr unexpect_t threadschedule::unexpect {}

Detailed Description

Polyfill for std::expected (C++23) for pre-C++23 compilers.

When the standard library already provides std::expected (detected via the __cpp_lib_expected feature-test macro or a C++23-or-later language mode), every type in this header is a simple alias to its std:: counterpart. Otherwise a from-scratch implementation is supplied.

Exception handling
The polyfill respects -fno-exceptions builds. When exceptions are disabled, value() calls std::terminate() instead of throwing bad_expected_access. Prefer value_or(), operator*(), or an explicit has_value() check when building without exceptions.
Monadic operations
Both the primary template and the void specialization support the four monadic combinators from P0323R12:
  • and_then – chain an operation that returns an expected
  • or_else – recover from an error, returning an expected
  • transform – map the contained value
  • transform_error – map the contained error

Definition in file expected.hpp.

Macro Definition Documentation

◆ THREADSCHEDULE_EXPECTED_THROW

#define THREADSCHEDULE_EXPECTED_THROW ( ex)
Value:
::std::terminate()

Definition at line 61 of file expected.hpp.

◆ THREADSCHEDULE_HAS_STD_EXPECTED

#define THREADSCHEDULE_HAS_STD_EXPECTED   0

Definition at line 48 of file expected.hpp.

Function Documentation

◆ swap()

template<typename T, typename E>
void threadschedule::swap ( expected< T, E > & lhs,
expected< T, E > & rhs )
constexprnoexcept

Definition at line 1035 of file expected.hpp.

Variable Documentation

◆ unexpect

unexpect_t threadschedule::unexpect {}
inlineconstexpr

Definition at line 90 of file expected.hpp.