Namespaces
Variants

std::meta::has_static_storage_duration, std::meta::has_thread_storage_duration, std::meta::has_automatic_storage_duration

From cppreference.com
< cpp | meta
 
 
 
Reflection library
 
Reflection types and queries
Type properties
Type property queries
 
Defined in header <meta>
consteval bool has_static_storage_duration( std::meta::info r );
(1) (since C++26)
consteval bool has_thread_storage_duration( std::meta::info r );
(2) (since C++26)
consteval bool has_automatic_storage_duration( std::meta::info r );
(3) (since C++26)

Determines if r represents an object or variable that has the specified storage duration.

Returns true if r represents an entity that has

Otherwise, returns false.

Parameters

r - a reflection value

Return value

true if r represents an object or variable with respective storage duration; otherwise false.

Notes

It is not possible to have a reflection representing an object or variable having dynamic storage duration.

Example

#include <meta>

int g{'_'};
static_assert(has_static_storage_duration(^^g));
static_assert(!has_thread_storage_duration(^^g));
static_assert(!has_automatic_storage_duration(^^g));

template<class T>
struct S
{
    thread_local inline static int m{42};
};
static_assert(!has_static_storage_duration(^^S<float>::m));
static_assert(has_thread_storage_duration(^^S<float>::m));
static_assert(!has_automatic_storage_duration(^^S<float>::m));

int main(int argc, const char*[])
{
    static_assert(!has_static_storage_duration(^^argc));
    static_assert(!has_thread_storage_duration(^^argc));
    static_assert(has_automatic_storage_duration(^^argc));
}

See also

(C++26)
checks if reflection represents a static object
(function) [edit]
checks if reflection represents a variable
(function) [edit]