Hasty Briefsbeta

Bilingual

C++26: Std:Is_within_lifetime

6 days ago
  • #C++26
  • #CompileTimeProgramming
  • #Unions
  • std::is_within_lifetime is a new C++26 function in <type_traits> that checks if a pointer points to an object within its lifetime during constant evaluation.
  • Primary use case is checking active union members, e.g., verifying which union alternative is currently valid.
  • Function is consteval-only (compile-time only) due to compiler's better lifetime tracking during constant evaluation.
  • Takes a pointer instead of reference for clearer semantics about memory location rather than value.
  • General name (not union-specific) allows future use beyond checking union members.
  • Motivated by implementing Optional<bool> with minimal storage, solving compile-time active member checks.
  • No compiler support yet (as of February 2026), but provides a clean solution for constexpr union handling.