Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
ah-cpp-compat.H File Reference

C++20/23 compatibility layer: feature detection + Aleph:: polyfills. More...

#include <exception>
#include <functional>
#include <memory>
#include <new>
#include <type_traits>
#include <utility>
Include dependency graph for ah-cpp-compat.H:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  Aleph::unexpect_t
 Tag type used to construct an expected holding an error in place. More...
 
class  Aleph::unexpected< E >
 Wrapper for the error value used to initialize an expected. More...
 
class  Aleph::bad_expected_access< E >
 Exception thrown by expected::value() when no value is held. More...
 
class  Aleph::expected< T, E >
 Minimal std::expected-style result type for C++20. More...
 
class  Aleph::expected< void, E >
 Specialization of expected for void value type. More...
 

Namespaces

namespace  Aleph
 Main namespace for Aleph-w library functions.
 
namespace  Aleph::cpp_compat_detail
 

Macros

#define ALEPH_HAS_STD_EXPECTED   0
 
#define ALEPH_HAS_STD_GENERATOR   0
 
#define ALEPH_HAS_STD_FLAT_MAP   0
 
#define ALEPH_HAS_STD_MDSPAN   0
 

Typedefs

template<class U >
using Aleph::cpp_compat_detail::remove_cvref_t = std::remove_cv_t< std::remove_reference_t< U > >
 C++17-safe equivalent of C++20 cpp_compat_detail::remove_cvref_t.
 

Functions

template<class E >
 Aleph::unexpected (E) -> unexpected< E >
 

Variables

constexpr unexpect_t Aleph::unexpect {}
 Tag value of type unexpect_t.
 

Detailed Description

C++20/23 compatibility layer: feature detection + Aleph:: polyfills.

Aleph-w targets C++20 as its baseline (GCC 11+, Clang 14+) and also supports C++23. (The library requires C++20 because it uses concepts throughout; this compatibility header alone happens to also compile under C++17.) This header centralizes the detection of selected C++23 library facilities and exposes them under the Aleph:: namespace: it aliases the std:: facility when the toolchain provides it, and otherwise provides a conforming-subset polyfill. The rest of the library can then use e.g. Aleph::expected unconditionally, regardless of -std.

Detection macros (each defined to 1 or 0)
  • ALEPH_HAS_STD_EXPECTED — <expected> (std::expected, C++23)
  • ALEPH_HAS_STD_GENERATOR — <generator> (std::generator, C++23)
  • ALEPH_HAS_STD_FLAT_MAP — <flat_map> (std::flat_map, C++23)
  • ALEPH_HAS_STD_MDSPAN — <mdspan> (std::mdspan, C++23)
Provided in this release
Aleph::expected<T,E>, Aleph::unexpected<E>, Aleph::bad_expected_access, and the Aleph::unexpect tag. The polyfill implements the common surface (construction, has_value/value/error/operator bool/value_or, and the monadic and_then/transform/or_else); it is not a bit-for-bit reimplementation of the standard. When ALEPH_HAS_STD_EXPECTED is 1, Aleph::expected is exactly std::expected.

Flat containers shipped natively as Aleph::FlatSet/Aleph::FlatMap (see tpl_flat_set.H/tpl_flat_map.H); they are independent of the standard library ones, so ALEPH_HAS_STD_FLAT_MAP remains detection-only. Generators and mdspan land in their own feature branches; only their detection macros are defined here for now.

Note
Thread-safety: the types are value types with no shared state; the usual "distinct objects, distinct threads" rule applies.
Author
Leandro Rabindranath Leon

Definition in file ah-cpp-compat.H.

Macro Definition Documentation

◆ ALEPH_HAS_STD_EXPECTED

#define ALEPH_HAS_STD_EXPECTED   0

Definition at line 93 of file ah-cpp-compat.H.

◆ ALEPH_HAS_STD_FLAT_MAP

#define ALEPH_HAS_STD_FLAT_MAP   0

Definition at line 105 of file ah-cpp-compat.H.

◆ ALEPH_HAS_STD_GENERATOR

#define ALEPH_HAS_STD_GENERATOR   0

Definition at line 99 of file ah-cpp-compat.H.

◆ ALEPH_HAS_STD_MDSPAN

#define ALEPH_HAS_STD_MDSPAN   0

Definition at line 111 of file ah-cpp-compat.H.