Skip to content

Commit d4d2978

Browse files
committed
New issue from Hewill: "move_iterator's default constructor should be constrained"
1 parent ac0d65d commit d4d2978

File tree

1 file changed

+77
-0
lines changed

1 file changed

+77
-0
lines changed

xml/issue4125.xml

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
<?xml version='1.0' encoding='utf-8' standalone='no'?>
2+
<!DOCTYPE issue SYSTEM "lwg-issue.dtd">
3+
4+
<issue num="4125" status="New">
5+
<title><tt>move_iterator</tt>'s default constructor should be constrained</title>
6+
<section><sref ref="[move.iterator]"/><sref ref="[move.iter.cons]"/></section>
7+
<submitter>Hewill Kang</submitter>
8+
<date>22 Jul 2024</date>
9+
<priority>99</priority>
10+
11+
<discussion>
12+
<p>
13+
Although it is unclear why <paper num="P2325"/> did not apply to <tt>move_iterator</tt>, there is
14+
implementation divergence among the current libraries (<a href="https://godbolt.org/z/WdoPcjjv4">demo</a>):
15+
</p>
16+
<blockquote><pre>
17+
#include &lt;istream&gt;
18+
#include &lt;iterator&gt;
19+
#include &lt;ranges&gt;
20+
21+
using R = std::ranges::istream_view&lt;int&gt;;
22+
using I = std::ranges::iterator_t&lt;R&gt;;
23+
using MI = std::move_iterator&lt;I&gt;;
24+
static_assert(std::default_initializable&lt;MI&gt;); // <span style="color:#C80000;font-weight:bold">libstdc++ passes, libc++ fails</span>
25+
</pre></blockquote>
26+
<p>
27+
As libc++ additionally requires that its default constructors satisfy <code>is_constructible_v&lt;Iterator&gt;</code>.
28+
<p/>
29+
Although this is not current standard-conforming behavior, such constraint does make sense since <code>move_iterator</code>
30+
only requires the underlying iterator to be <code>input_iterator</code> which may not be <code>default_initializable</code>.
31+
</p>
32+
</discussion>
33+
34+
<resolution>
35+
<p>
36+
This wording is relative to <paper num="N4986"/>.
37+
</p>
38+
39+
<ol>
40+
<li><p>Modify <sref ref="[move.iterator]"/> as indicated:</p>
41+
42+
<blockquote>
43+
<pre>
44+
namespace std {
45+
template&lt;class Iterator&gt;
46+
class move_iterator {
47+
public:
48+
[&hellip;]
49+
constexpr move_iterator() <ins>requires default_initializable&lt;Iterator&gt; = default</ins>;
50+
[&hellip;]
51+
private:
52+
Iterator current <ins>= Iterator()</ins>; // <i>exposition only</i>
53+
};
54+
}
55+
</pre>
56+
</blockquote>
57+
58+
</li>
59+
60+
<li><p>Modify <sref ref="[move.iter.cons]"/> as indicated:</p>
61+
62+
<blockquote>
63+
<pre>
64+
<del>constexpr move_iterator();</del>
65+
</pre>
66+
<blockquote>
67+
<p>
68+
<del>-1- <i>Effects</i>: Value-initializes <tt>current</tt>.</del>
69+
</p>
70+
</blockquote>
71+
</blockquote>
72+
73+
</li>
74+
</ol>
75+
</resolution>
76+
77+
</issue>

0 commit comments

Comments
 (0)