Skip to content

Commit 6072fa0

Browse files
committed
New issue from Hewill: "Improve define_static_array"
1 parent 4a7f843 commit 6072fa0

File tree

1 file changed

+82
-0
lines changed

1 file changed

+82
-0
lines changed

xml/issue4537.xml

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
<?xml version='1.0' encoding='utf-8' standalone='no'?>
2+
<!DOCTYPE issue SYSTEM "lwg-issue.dtd">
3+
4+
<issue num="4537" status="New">
5+
<title>Improve `define_static_array`</title>
6+
<section>
7+
<sref ref="[meta.define.static]"/>
8+
</section>
9+
<submitter>Hewill Kang</submitter>
10+
<date>09 Mar 2026</date>
11+
<priority>99</priority>
12+
13+
<discussion>
14+
<p>
15+
`define_static_array` can transform any input range, even a non-contiguous one, into a `span`.
16+
<p/>
17+
However, the returned `span` always has a dynamic extent. If the size of the input range is known at
18+
compile time, returning a static `span` seems reasonable and may offer slight runtime efficiency.
19+
</p>
20+
</discussion>
21+
22+
<resolution>
23+
<p>
24+
This wording is relative to <paper num="N5032"/>.
25+
</p>
26+
27+
<ol>
28+
29+
<li><p>Modify <sref ref="[meta.syn]"/>, header <tt>&lt;meta&gt;</tt> synopsis, as indicated:</p>
30+
31+
<blockquote>
32+
<pre>
33+
#include &lt;compare&gt; // <i>see <sref ref="[compare.syn]"/></i>
34+
#include &lt;initializer_list&gt; // <i>see <sref ref="[initializer.list.syn]"/></i>
35+
36+
namespace std {
37+
[&hellip;]
38+
// <i><sref ref="[meta.define.static]"/>, promoting to static storage</i>
39+
[&hellip;]
40+
template&lt;ranges::input_range R&gt;
41+
consteval span&lt;const ranges::range_value_t&lt;R&gt;<ins>, <i>see below</i></ins>&gt; define_static_array(R&amp;&amp; r);
42+
[&hellip;]
43+
}
44+
</pre>
45+
</blockquote>
46+
</li>
47+
48+
<li><p>Modify <sref ref="[meta.define.static]"/> as indicated:</p>
49+
50+
<blockquote>
51+
<pre>
52+
template&lt;ranges::input_range R&gt;
53+
consteval span&lt;const ranges::range_value_t&lt;R&gt;<ins>, <i>see below</i></ins>&gt; define_static_array(R&amp;&amp; r);
54+
</pre>
55+
<blockquote>
56+
<p>
57+
-16- <i>Effects</i>: Equivalent to:
58+
</p>
59+
<blockquote>
60+
<pre>
61+
using T = ranges::range_value_t&lt;R&gt;;
62+
meta::info array = meta::reflect_constant_array(r);
63+
if (meta::is_array_type(meta::type_of(array))) {
64+
return span&lt;const T<ins>, <i>see below</i></ins>&gt;(meta::extract&lt;const T*&gt;(array), meta::extent(meta::type_of(array)));
65+
} else {
66+
return span&lt;const T<ins>, <i>see below</i></ins>&gt;();
67+
}
68+
</pre>
69+
</blockquote>
70+
<p>
71+
<ins>-?- <i>Remarks</i>: The second template argument of the returned `span` type is
72+
<code>static_cast&lt;size_t&gt;(ranges::size(r))</code> if `ranges::size(r)` is a constant
73+
expression, and `dynamic_extent` otherwise.</ins>
74+
</p>
75+
</blockquote>
76+
</blockquote>
77+
</li>
78+
79+
</ol>
80+
</resolution>
81+
82+
</issue>

0 commit comments

Comments
 (0)