The library is layered namespace is a faithful polyfill of standard vocabulary types and utilities as specified for C 26 available to a C 20 compiler and namespace builds the functional programming extensions on top of it Every type with a counterpart is a strict superset of it a valid program switching from to changes neither compilation nor behaviour polyfills only what C 20 lacks all of the C 23 and C 26 additions to the monadic operations iterator support in its SFINAE friendly C 26 shape together with its applicability traits and Names C 20 already has are used directly and not mirrored The polyfills track the C working draft deviating deliberately in three ways each noted on the entity it concerns where the standard leaves a member s specification unstated one is derived from the underlying types every such clause is marked in the source the draft s hardened preconditions are checked with an assertion customizable by defining before inclusion s comparison against a value is declared at namespace scope rather than as a hidden friend keeping its constraint deducible Members are not restated here A type is the standard s type member for member so each one below names its standard counterpart and links to where it is specified a second copy of that specification would only be a second thing to keep true What this page documents is what differs the deviations above and the entities adds because C 20 has no equivalent expected Defined in Its members are specified as expected over void The partial specialization serving computations which succeed with no value Its members are specified as unexpected Its members are specified as unexpect Its members are specified as bad_expected_access Its members are specified as optional Defined in Its members are specified as optional over a reference Its members are specified as apply Defined in Applicability traits The C 26 traits is specified through each also comes in its for the two predicates or for the result form invoke_r Defined in unreachable Defined in More applicability traits Comparison against a value pfn fn fn pfn pfn fn pfn <expected> std optional optional<T&> std apply std invoke_r std unreachable std nullopt std in_place std bad_optional_access noexcept extension LIBFN_ASSERT expected pfn pfn std expected in its C 26 shape a computation yielding a success T or an error E A polyfill for C 20 compilers tracking the C working draft members are as expected object specifies them including changes accepted beyond C 26 has_error P3798 Deliberate deviations a noexcept specification is derived from T E and the callable arguments wherever the standard leaves one unstated each such clause is marked extension inline the draft s hardened preconditions are checked by an assertion customizable by defining LIBFN_ASSERT before inclusion the comparison against a value is declared at namespace scope not as the specified hidden friend keeping its constraint deducible Its members are the standard s and specified where the reference page for this entity points std expected The std expected partial specialization for void success a computation yielding either nothing success or an error E Members are as expected void specifies them the noexcept and assertion deviations listed on the primary template apply here equally Its members are the standard s and specified where the reference page for this entity points std expected<void E> The wrapper marking a value as an error std unexpected as specified for C 26 expected unexpected Wraps E so that constructing or assigning an expected from it selects the error side Deviation operator carries a noexcept specification derived from E where the standard leaves one unstated marked extension inline Its members are the standard s and specified where the reference page for this entity points std unexpected Disambiguation tag selecting an expected s error side in construction and emplacement expected syn passed as the pfn unexpect value Its members are the standard s and specified where the reference page for this entity points std unexpect_t The exception thrown when expected value is called on an object holding an error expected bad Carries a copy of that error exposed through error Its members are the standard s and specified where the reference page for this entity points std bad_expected_access The base exception type of every failed expected value access expected bad void Thrown only as a bad_expected_access<E> this specialization for void is the common base for handlers that do not care about the error type Its members are the standard s and specified where the reference page for this entity points std optional in its C 26 shape a computation yielding a value T or empty A polyfill for C 20 compilers tracking the C working draft members are as optional optional specifies them including the monadic operations iterator support an engaged optional is a contiguous range of one element and hashing lvalue reference payloads are served by the optional<T&> partial specialization Deliberate deviations a noexcept specification is derived from T and the callable arguments wherever the standard leaves one unstated each such clause is marked extension inline the draft s hardened preconditions are checked by an assertion customizable by defining LIBFN_ASSERT before inclusion Its members are the standard s and specified where the reference page for this entity points std optional The std optional partial specialization for lvalue references optional optional ref a non owning reference to T or empty Specified for C 26 Copy assignment and emplace rebind the reference nothing ever assigns through it and const on the optional does not constify the referent the referent s lifetime stays the caller s responsibility The noexcept and assertion deviations of the primary template apply here equally plus one deferral the draft rejects a construction that would bind the reference to a temporary via reference_constructs_from_temporary_v a C 23 trait with no portable C 20 fallback those guards are deferred and such a construction compiles and dangles Its members are the standard s and specified where the reference page for this entity points std optional<T&> template <typename Fn detail _tuple_like Tuple> constexpr auto apply Fn &&fn Tuple &&t > apply_result_t<Fn Tuple> 1 Invokes a callable with a tuple like operand s elements as its arguments std apply in its C 26 shape tuple apply for C 20 compilers The C 26 revision P1317R2 declares the return type as apply_result_t making the overload SFINAE friendly where a deduced return is a hard error outside the immediate context and derives the exception specification from is_nothrow_applicable both are provided here Accepts the enumerated tuple like types tuple like not the general tuple protocol return The callable s result fn Fn && Callable to invoke t Tuple && Tuple like operand supplying the arguments apply _v _t Checks if Fn is invocable with the elements of the tuple like Tuple std is_applicable as adopted for C 26 by P1317R2 meta rel for C 20 compilers Tuple must be one of the enumerated tuple like specializations tuple like where the underlying standard library does not provide std complex s C 26 tuple protocol P2819 a std complex operand answers false rather than failing to compile Checks if the pfn is_applicable invocation is additionally known not to throw std is_nothrow_applicable as adopted for C 26 by P1317R2 meta rel for C 20 compilers The result type of applying Fn to the elements of the tuple like Tuple std apply_result as adopted for C 26 by P1317R2 meta trans other for C 20 compilers SFINAE friendly no member type where pfn is_applicable answers false template <class R class F class Args> constexpr auto invoke_r F &&f Args && args 1 Invokes a callable and implicitly converts its result to R std invoke_r as specified for C 23 func invoke for C 20 compilers When R is void the result is discarded so any invocable can be called for its effects alone return The callable s result converted to R f F && Callable to invoke args Args && Arguments to pass return The callable s result converted to R f F && Callable to invoke args Args && Arguments to pass auto unreachable > void 1 Marks a point of provably unreachable control flow std unreachable as specified for C 23 utility undefined for C 20 compilers Reaching a call is undefined behaviour the implementation is the compiler s own unreachability intrinsic so the optimizer may assume every path to the call site is dead template <typename Fn typename Tuple> using apply_result_t typename apply_result<Fn Tuple> type 1 Alias form of pfn apply_result template <typename Fn typename Tuple> constexpr bool is_applicable_v is_applicable<Fn Tuple> value 1 Variable form of pfn is_applicable template <typename Fn typename Tuple> constexpr bool is_nothrow_applicable_v is_nothrow_applicable<Fn Tuple> value 1 Variable form of pfn is_nothrow_applicable template <class T class E class T2> constexpr auto operator expected<T E> const &x T2 const &v > bool 1 template <class T class U> constexpr auto operator optional<T> const & optional<U> const & > bool 2 template <class T> constexpr auto operator optional<T> const & std nullopt_t > bool 3 template <class T class U> constexpr auto operator optional<T> const & U const & > bool 4 constexpr auto operator T const & optional<U> const & > bool 5