close
Namespaces
Variants

std::define_static_object

From cppreference.com
< cpp | meta
 
 
Metaprogramming library
Type traits
Type categories
(C++11)
(C++11)(DR*)
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
(C++11) 
(C++11)
(C++11)
Type properties
(C++11)
(C++11)
(C++14)
(C++11)(deprecated in C++26)
(C++11)(until C++20*)
(C++11)(deprecated in C++20)
(C++11)
Type trait constants
Metafunctions
(C++17)
Supported operations
Relationships and property queries
Type modifications
(C++11)(C++11)(C++11)
Type transformations
(C++11)(deprecated in C++23)
(C++11)(deprecated in C++23)
(C++11)
(C++11)(until C++20*)(C++17)

(C++11)
(C++17)
Compile-time rational arithmetic
Compile-time integer sequences
 
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.

Example

See also

promotes compile-time array into static storage, returning a span of the static array
(function template) [edit]
promotes compile-time string to static storage, returning a pointer to the first character of the static string
(function template) [edit]
returns a reflection representing a value or object, suitable for use as a constant template argument
(function template) [edit]