Namespaces
Variants

std::define_static_array

From cppreference.com
< cpp | meta
Revision as of 02:04, 1 May 2026 by D41D8CD98F (talk | contribs) (+)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
 
 
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< ranges::input_range R >
consteval std::span<const ranges::range_value_t<R>> define_static_array( R&& r );
(since C++26)

Promotes array to static storage.

Equivalent to:

using T = ranges::range_value_t<R>;
std::meta::info array = std::meta::reflect_constant_array(r);
std::meta::info type = std::meta::type_of(array);
if (std::meta::is_array_type(type)) {
    return std::span<const T>(std::meta::extract<const T*>(array), std::meta::extent(type));
} else {
    return std::span<const T>();
}

Parameters

r - a input_range whose elements are copy-constructible and have structural type

Return value

If the size of r is not zero, a span constructed from an array of type const T[N] (where T is ranges::range_value_t<R> and N is the size of r). Each element of the array is initialized from the value or object represented by std::meta::reflect_constant(static_cast<T>(*it)), where it is an iterator to the corresponding element of r.

Otherwise (the size of r is zero), an empty span.

Notes

As a template parameter object, the resulting array object (if present) has static storage duration. Ranges with template-argument-equivalent contents correspond to the same array object.

The array object is a potentially non-unique object.

Example

See also