February 19, 2026
Union drama, compile-time karma
C++26: Std:Is_within_lifetime
C++26 adds an “is it alive?” check; devs clap, groan, and meme unions
TLDR: C++26 adds a compile‑time check to see if a union’s member is truly active, aiming to prevent sneaky bugs. The community split: some applaud safer code, others mock it as overkill and demand pattern matching, while memes question if all union members are “always active.”
C++ just slipped a new trick into its 2026 release: std::is_within_lifetime, a compile‑time (aka while your code is being built) check that answers the very human question: “Is this thing alive?” It’s mainly for unions—boxes that hold one value at a time—and tells you if the active member is really active. The official pitch even mentions making a super tiny “optional bool” without wasting memory. Techy details aside, the internet reacted like it always does: with drama.
One camp cheered, calling it a sensible safety check when the compiler can track what exists. Another camp rolled their eyes hard. User eptcyka snarked, “You sure are, gramps,” implying this is a boomer move to flex about memory. Meanwhile, mFixman wanted more: pattern matching (think smart switch statements) and argued this is a half‑step. Practical folks like matthewkayin asked why we needed a whole feature when a single 8‑bit number with three values could do the job. The jokes landed too: MountainTheme12 declared, “In my C++ all members of a union are always active,” as chaos memes spread. The vibe? A split between “nice guardrail” and “this solves the wrong problem.” See the proposal P2641R4 for the nitty‑gritty.
Key Points
- •C++26 introduces std::is_within_lifetime(const T* p) in <type_traits> to check at compile time if a pointer refers to an object within its lifetime.
- •The function is consteval-only, so it can be used during constant evaluation but not at runtime.
- •A primary use case is determining which member of a union is currently active without invoking undefined behavior.
- •The function takes a pointer (not a reference) to avoid issues with temporaries and lifetime extension and to express a memory-location query.
- •The feature’s general naming reflects a broader lifetime-query mechanism, motivated by implementing a minimal-overhead Optional<bool> for constant evaluation scenarios.