|
| 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<class K, class... Args> |
| 37 | + pair<iterator, bool> try_emplace(K&& k, Args&&... args); |
| 38 | +template<class K, class... Args> |
| 39 | + iterator try_emplace(const_iterator hint, K&& k, Args&&... args); |
| 40 | +</pre> |
| 41 | +<blockquote> |
| 42 | +<p> |
| 43 | +[…] |
| 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<class K> pair<iterator, bool> insert(K&& x); |
| 58 | +template<class K> iterator insert(const_iterator hint, K&& x); |
| 59 | +</pre> |
| 60 | +<blockquote> |
| 61 | +<p> |
| 62 | +[…] |
| 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