std::define_static_object
Defined in header <meta> | ||
|---|---|---|
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
| t | - | a value of structural type |
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
|
(C++26) | promotes compile-time array into static storage, returning a span of the static array (function template) |
|
(C++26) | promotes compile-time string to static storage, returning a pointer to the first character of the static string (function template) |
|
(C++26) | returns a reflection representing a value or template parameter object, suitable for use as a constant template argument (function template) |
© cppreference.com
Licensed under the Creative Commons Attribution-ShareAlike Unported License v3.0.
https://en.cppreference.com/cpp/meta/define_static_object