This page is a snapshot from the LWG issues list, see the Library Active Issues List for more information and the meaning of New status.

4537. Improve define_static_array

Section: 21.4.3 [meta.define.static] Status: New Submitter: Hewill Kang Opened: 2026-03-09 Last modified: 2026-03-09

Priority: Not Prioritized

View other active issues in [meta.define.static].

View all other issues in [meta.define.static].

View all issues with New status.

Discussion:

define_static_array can transform any input range, even a non-contiguous one, into a span.

However, the returned span always has a dynamic extent. If the size of the input range is known at compile time, returning a static span seems reasonable and may offer slight runtime efficiency.

Proposed resolution:

This wording is relative to N5032.

  1. Modify 21.4.1 [meta.syn], header <meta> synopsis, as indicated:

    #include <compare>              // see 17.12.1 [compare.syn]
    #include <initializer_list>     // see 17.11.2 [initializer.list.syn]
    
    namespace std {
      […]
      // 21.4.3 [meta.define.static], promoting to static storage
      […]
      template<ranges::input_range R>
        consteval span<const ranges::range_value_t<R>, see below> define_static_array(R&& r);
      […]
    }
    
  2. Modify 21.4.3 [meta.define.static] as indicated:

    template<ranges::input_range R>
      consteval span<const ranges::range_value_t<R>, see below> define_static_array(R&& r);
    

    -16- Effects: Equivalent to:

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

    -?- Remarks: The second template argument of the returned span type is static_cast<size_t>(ranges::size(r)) if ranges::size(r) is a constant expression, and dynamic_extent otherwise.