Skip to content

C++23 compatibility tier #5

Description

@MihaiStreames

Context

The core API is stable on C++20. This issue tracks the C++23 tier -- features that only make sense with std::expected in the standard library and where type-erasure overhead is justified.

Already landed (C++20)

  • std::any payload on ErrorInfo -- attach a typed value via fail_with(payload, msg, domain)
  • Failure::downcast<T>() -- recover the payload as T* / const T* (returns null on mismatch or empty payload)
  • domain string tag for cheaper string-based discrimination when a typed payload is not needed

Changes required

std::expected aliasing

  • Expected<T, E> aliases std::expected<T, E> when __cplusplus >= 202302L; Unexpected aliases std::unexpected
  • Evaluate whether aliasing is cleaner than a thin compatibility shim over our own Expected

AnyhowError concept (C++20 prerequisite)

template <typename E>
concept AnyhowError = requires(E e) {
    { e.message() } -> std::convertible_to<std::string_view>;
};

Expected<T> accepts any E satisfying the concept, not just anyhow::Failure.

From-style conversion

  • From-style conversion for std::error_code, exception types, and third-party errors (mirrors anyhow's impl From<E> for Error)

CI

Add -std=c++23 to the build matrix.

Metadata

Metadata

Assignees

No one assigned

    Labels

    compatC++17/20 compatibility, portabilityenhancementNew functionality

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions