std::is_within_lifetime

From cppreference.com
< cpp‎ | types
 
 
Utilities library
General utilities
Date and time
Function objects
Formatting library (C++20)
(C++11)
Relational operators (deprecated in C++20)
Integer comparison functions
(C++20)(C++20)(C++20)   
(C++20)
Swap and type operations
(C++14)
(C++11)
(C++11)
(C++11)
(C++17)
Common vocabulary types
(C++11)
(C++17)
(C++17)
(C++17)
(C++11)
(C++17)
(C++23)
Elementary string conversions
(C++17)
(C++17)
 
Defined in header <type_traits>
template< class T >
consteval bool is_within_lifetime( const T* p ) noexcept;
(since C++26)

Determines whether the pointer p points to an object that is within its lifetime. During the evaluation of an expression E as a core constant expression, a call to is_within_lifetime is ill-formed unless p points to an object that is usable in constant expressions or whose complete object’s lifetime began within E.

Parameters

p - pointer to detect

Return value

true if pointer p points to an object that is within its lifetime; otherwise false.

Example