cpp/meta/reflect constant array: Difference between revisions
D41D8CD98F (talk | contribs) →See also: + |
D41D8CD98F (talk | contribs) m ~ |
||
| Line 7: | Line 7: | ||
Returns a reflection that represents an array object whose elements are corresponding elements of {{tt|r}}. | Returns a reflection that represents an array object whose elements are corresponding elements of {{tt|r}}. | ||
Let {{tt|T}} be {{c|ranges::range_value_t<R>}}. | Let {{tt|T}} be {{c|ranges::range_value_t<R>}}. | ||
| Line 26: | Line 30: | ||
===Notes=== | ===Notes=== | ||
The result of {{tt|std::meta::reflect_constant_array}} is suitable for use with {{ltt|cpp/meta/substitute|std::meta::substitute}}. If the caller wants a span of a static array, as opposite to a reflection value, {{ltt|cpp/meta/define_static_string|std::define_static_array}} is usually more suitable. | The result of {{tt|std::meta::reflect_constant_array}} is suitable for use with {{ltt|cpp/meta/substitute|std::meta::substitute}}. If the caller wants a span of a static array, as opposite to a reflection value, {{ltt|cpp/meta/define_static_string|std::define_static_array}} is usually more suitable. | ||
Latest revision as of 14:03, 1 May 2026
| Defined in header <meta>
|
||
template< ranges::input_range R >
consteval std::meta::info reflect_constant_array( R&& r );
|
(since C++26) | |
Returns a reflection that represents an array object whose elements are corresponding elements of r.
The resulting object is a template parameter object: it has static storage duration, and ranges with template-argument-equivalent contents correspond to the same object.
If the size of r is not zero, the resulting array object is a potentially non-unique object.
Let T be ranges::range_value_t<R>.
The program is ill-formed if T is not a structural type, if std::is_constructible_v<T, ranges::range_reference_t<R>> is false, or if T does not satisfy copy_constructible.
Parameters
| r | - | an input_range
|
Return value
If the size of r is not zero, a reflection that represents a template parameter object of type const T[N] (where N is the size of r). Each element of the template parameter object 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), a reflection that represents the template parameter object of type const std::array<T, 0> initialized with {}.
Exceptions
Throws any exception thrown by the evaluation of static_cast<T>(*it), or std::meta::exception if the evaluation of std::reflect_constant would exit via an exception.
Notes
The result of std::meta::reflect_constant_array is suitable for use with std::meta::substitute. If the caller wants a span of a static array, as opposite to a reflection value, std::define_static_array is usually more suitable.
Example
| This section is incomplete Reason: no example |
See also
(C++26) |
promotes compile-time array into static storage, returning a span of the static array (function template) |
(C++26) |
promotes a compile-time string to static storage, returning a reflection representing the static string (function template) |
(C++26) |
returns a reflection representing a value or object, suitable for use as a constant template argument (function template) |