Skip to content

Commit 2c0bbee

Browse files
committed
New issue from Hewill: "Improve inplace_vector(from_range_t, R&& rg)"
1 parent 52013d7 commit 2c0bbee

File tree

1 file changed

+75
-0
lines changed

1 file changed

+75
-0
lines changed

xml/issue4396.xml

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
<?xml version='1.0' encoding='utf-8' standalone='no'?>
2+
<!DOCTYPE issue SYSTEM "lwg-issue.dtd">
3+
4+
<issue num="4396" status="New">
5+
<title>Improve <code>inplace_vector(from_range_t, R&amp;&amp; rg)</code></title>
6+
<section><sref ref="[sequence.reqmts]"/><sref ref="[inplace.vector.cons]"/></section>
7+
<submitter>Hewill Kang</submitter>
8+
<date>01 Oct 2025</date>
9+
<priority>99</priority>
10+
11+
<discussion>
12+
<p>
13+
Consider:
14+
</p>
15+
<blockquote><pre>
16+
std::array&lt;int, 42&gt; a;
17+
std::inplace_vector&lt;int, 5&gt; v(std::from_range, a);
18+
</pre></blockquote>
19+
<p>
20+
The above throws `std::bad_alloc` at runtime because the size of `array` is larger than
21+
capacity of `inplace_vector`. However, we should reject it at compile time since the
22+
`array` size is a constant expression.
23+
<p/>
24+
Given that we do a lot of compile-time size checking in <code>&lt;simd&gt;</code>,
25+
it's worth applying that here as well. Compile-time errors are better than runtime ones.
26+
</p>
27+
</discussion>
28+
29+
<resolution>
30+
<p>
31+
This wording is relative to <paper num="N5014"/>.
32+
</p>
33+
34+
<ol>
35+
36+
<li><p>Modify <sref ref="[sequence.reqmts]"/> as indicated:</p>
37+
38+
<blockquote>
39+
<pre>
40+
a.assign_range(rg)
41+
</pre>
42+
<blockquote>
43+
<p>
44+
-60- <i>Result</i>: <code>void</code>
45+
<p/>
46+
-61- <i>Mandates</i>: <code>assignable_from&lt;T&amp;, ranges::range_reference_t&lt;R&gt;&gt;</code> is modeled.
47+
<ins>For `inplace_vector`, if `ranges::size(rg)` is a constant expression then `ranges::size(rg)` ≤ `a.max_size()`</ins>.
48+
</p>
49+
</blockquote>
50+
</blockquote>
51+
</li>
52+
53+
<li><p>Modify <sref ref="[inplace.vector.cons]"/> as indicated:</p>
54+
55+
<blockquote>
56+
<pre>
57+
template&lt;<i>container-compatible-range</i>&lt;T&gt; R&gt;
58+
constexpr inplace_vector(from_range_t, R&amp;&amp; rg);
59+
</pre>
60+
<blockquote>
61+
<p>
62+
<ins>-?- <i>Mandates</i>: If `ranges::size(rg)` is a constant expression then `ranges::size(rg)` ≤ `N`.</ins>
63+
<p/>
64+
-9- <i>Effects</i>: Constructs an `inplace_vector` with the elements of the range `rg`.
65+
<p/>
66+
-10- <i>Complexity</i>: Linear in `ranges::distance(rg)`.
67+
</p>
68+
</blockquote>
69+
</blockquote>
70+
</li>
71+
</ol>
72+
73+
</resolution>
74+
75+
</issue>

0 commit comments

Comments
 (0)