C++26: std::is_within_lifetime -- Sandor Dargo

SANDOR_DARGO_ROUND.JPGWhen I first came across std::is_within_lifetime, I expected another small type-traits utility — not a feature tied to checking whether a union alternative is active. But once you look closer, this seemingly narrow addition turns out to solve a surprisingly fundamental problem in constant evaluation.

C++26: std::is_within_lifetime

by Sandor Dargo

From the article:

When I was looking for the next topic for my posts, my eyes stopped on std::is_within_lifetime. Dealing with lifetime issues is a quite common source of bugs, after all. Then I clicked on the link and I read Checking if a union alternative is active. I scratched my head. Is the link correct?

It is — and it totally makes sense.

Let’s get into the details and first check what P2641R4 is about.

What does std::is_within_lifetime do?

C++26 adds bool std::is_within_lifetime(const T* p) to the <type_traits> header. This function checks whether p points to an object that is currently within its lifetime during constant evaluation.

Add a Comment

Comments are closed.

Comments (0)

There are currently no comments on this entry.