◐ Shell
clean mode source ↗

std::define_static_object - cppreference.com

From cppreference.com

template< class T >
consteval const remove_cvref_t<T>* define_static_object( T&& t );
(since C++26)

Promotes value to static storage.

Equivalent to:

using U = std::remove_cvref_t<T>;
if constexpr (std::meta::is_class_type(^^U) || std::meta::is_union_type(^^U))
{
    std::meta::info obj = std::meta::reflect_constant(std::forward<T>(t));
    return std::addressof(std::meta::extract<const U&>(obj));
}
else if constexpr (std::meta::is_array_type(^^U))
{
    std::meta::info obj = std::meta::reflect_constant_array(std::forward<T>(t));
    return std::addressof(std::meta::extract<const U&>(obj));
}
else
{
    return std::define_static_array(std::span(std::addressof(t), 1)).data();
}

Parameters

Return value

A pointer to the template parameter object with value t.

Notes

As a template parameter object, the resulting object has static storage duration. Template-argument-equivalent values correspond to the same object.

The resulting object is a potentially non-unique object if std::remove_cvref_t<T> is a scalar type.

If t is a template parameter object, the result points to the same object.

Feature-test macro Value Std Feature
__cpp_lib_define_static 202506L (C++26) std::define_static_object

Example

See also