Skip to content

Commit dc0f312

Browse files
committed
New issue from Jiang An: "Inconsistent preconditions for transparent insertion of std::flat_map/std::flat_set"
1 parent 296a740 commit dc0f312

File tree

1 file changed

+74
-0
lines changed

1 file changed

+74
-0
lines changed

xml/issue4048.xml

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
<?xml version='1.0' encoding='utf-8' standalone='no'?>
2+
<!DOCTYPE issue SYSTEM "lwg-issue.dtd">
3+
4+
<issue num="4048" status="New">
5+
<title>Inconsistent preconditions for transparent insertion of <tt>std::flat_map/std::flat_set</tt></title>
6+
<section><sref ref="[flat.set]"/><sref ref="[flat.map.overview]"/></section>
7+
<submitter>Jiang An</submitter>
8+
<date>26 Jan 2024</date>
9+
<priority>99</priority>
10+
11+
<discussion>
12+
<p>
13+
The preconditions for transparent insertion of associative containers (<sref ref="[map.modifiers]"/>/13,
14+
<sref ref="[map.modifiers]"/>/29, and <sref ref="[set.modifiers]"/>/3) detect the results of <tt>equal_range</tt>,
15+
while those for <tt>std::flat_set</tt> and <tt>std::flat_map</tt> (<sref ref="[flat.set.modifiers]"/>/2 and
16+
<sref ref="[flat.map.modifiers]"/>/20) currently detect the results of <tt>find</tt>, which is inconsistent.
17+
<p/>
18+
During implementing <tt>std::flat_set</tt> in MSVC STL, it was reported
19+
(<a href="https://github.com/microsoft/STL/issues/4105">microsoft/STL#4105</a>) that the current preconditions
20+
for <tt>std::flat_set::insert</tt> can lead to inconsistent results. Tim Song told that the current preconditions
21+
were copied from old revisions of <paper num="P2363"/>. So, presumably we should change these preconditions for
22+
flat container adaptors to consistently use <tt>equal_range</tt>.
23+
</p>
24+
</discussion>
25+
26+
<resolution>
27+
<p>
28+
This wording is relative to <paper num="N4971"/>.
29+
</p>
30+
31+
<ol>
32+
<li><p>Modify <sref ref="[flat.map.modifiers]"/> as indicated:</p>
33+
34+
<blockquote>
35+
<pre>
36+
template&lt;class K, class... Args&gt;
37+
pair&lt;iterator, bool&gt; try_emplace(K&amp;&amp; k, Args&amp;&amp;... args);
38+
template&lt;class K, class... Args&gt;
39+
iterator try_emplace(const_iterator hint, K&amp;&amp; k, Args&amp;&amp;... args);
40+
</pre>
41+
<blockquote>
42+
<p>
43+
[&hellip;]
44+
<p/>
45+
-20- <i>Preconditions</i>: The conversion from <tt>k</tt> into <tt>key_type</tt> constructs an
46+
object <tt>u</tt>, for which <tt><del>find(k) == find(u)</del><ins>equal_range(k) == equal_range(u)</ins></tt>
47+
is <tt>true</tt>.
48+
</p>
49+
</blockquote>
50+
</blockquote>
51+
</li>
52+
53+
<li><p>Modify <sref ref="[flat.set.modifiers]"/> as indicated:</p>
54+
55+
<blockquote>
56+
<pre>
57+
template&lt;class K&gt; pair&lt;iterator, bool&gt; insert(K&amp;&amp; x);
58+
template&lt;class K&gt; iterator insert(const_iterator hint, K&amp;&amp; x);
59+
</pre>
60+
<blockquote>
61+
<p>
62+
[&hellip;]
63+
<p/>
64+
-2- <i>Preconditions</i>: The conversion from <tt>x</tt> into <tt>value_type</tt> constructs an
65+
object <tt>u</tt>, for which <tt><del>find(x) == find(u)</del><ins>equal_range(x) == equal_range(u)</ins></tt>
66+
is <tt>true</tt>.
67+
</p>
68+
</blockquote>
69+
</blockquote>
70+
</li>
71+
</ol>
72+
</resolution>
73+
74+
</issue>

0 commit comments

Comments
 (0)