forked from lwg/issues
-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New issue: container-insertable checks do not match what container-in…
…serter does
- Loading branch information
Showing
1 changed file
with
100 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
<?xml version='1.0' encoding='utf-8' standalone='no'?> | ||
<!DOCTYPE issue SYSTEM "lwg-issue.dtd"> | ||
|
||
<issue num="4016" status="New"> | ||
<title><code><i>container-insertable</i></code> checks do not match what <code><i>container-inserter</i></code> does</title> | ||
<section><sref ref="[range.utility.conv]"/></section> | ||
<submitter>Jonathan Wakely</submitter> | ||
<date>24 Nov 2023</date> | ||
<priority>99</priority> | ||
|
||
<discussion> | ||
<p> | ||
The exposition-only helper <code><i>container-inserter</i></code> uses either | ||
<code>std::back_inserter</code> or <code>std::inserter</code>. Both | ||
<code>std::back_insert_iterator</code> and <code>std::insert_iterator</code> | ||
require <code>C::value_type</code> to be a valid type. | ||
They also incur a conversion to that <code>value_type</code> which has to | ||
be moved into the container. | ||
It's also possible (although arguably not worth caring about) that | ||
<code>range_value_t<C></code> is not the same type as | ||
<code>C::value_type</code>, and that conversion to <code>C::value_type</code> | ||
could be ill-formed (we only check that conversion from | ||
<code>range_reference_t<R></code> to <code>range_value_t<C></code> | ||
is well-formed). | ||
</p> | ||
<p> | ||
It seems preferable to remove the use of insert iterators, so that we don't | ||
need to check their requirements at all. | ||
</p> | ||
</discussion> | ||
|
||
<resolution> | ||
<p> | ||
This wording is relative to <paper num="N4964"/>. | ||
</p> | ||
|
||
<ol> | ||
|
||
<li><p>Modify <sref ref="[range.utility.conv.general]"/> as indicated:</p> | ||
|
||
<blockquote> | ||
<p>-4- Let <code><i>container-insertable</i></code> be defined as follows: | ||
<blockquote> | ||
<pre><code>template<class Container, class Ref> | ||
constexpr bool <i>container-insertable</i> = <i>// exposition only</i> | ||
requires(Container& c, Ref&& ref) { | ||
requires (<ins>requires { c.emplace_back(std::forward<Ref>(ref)); } ||</ins> | ||
requires { c.push_back(std::forward<Ref>(ref)); } || | ||
<ins>requires { c.emplace(c.end(), std::forward<Ref>(ref)); } ||</ins> | ||
requires { c.insert(c.end(), std::forward<Ref>(ref)); }); | ||
}; | ||
</code></pre> | ||
</blockquote> | ||
</p> | ||
<p>-5- Let <code><i>container-inserter</i></code> be defined as follows: | ||
<blockquote> | ||
<pre><code>template<class Container<del>, class Ref</del>> | ||
constexpr auto <i>container-inserter</i>(Container& c) { <i>// exposition only</i> | ||
<del> if constexpr (requires { c.push_back(declval<Ref>()); }) | ||
return back_inserter(c); | ||
else | ||
return inserter(c, c.end());</del> | ||
<ins> return [&c]<class Ref>(Ref&& ref) { | ||
if constexpr (requires { c.emplace_back(declval<Ref>()); }) | ||
c.emplace_back(std::forward<Ref>(ref)); | ||
else if constexpr (requires { c.push_back(declval<Ref>()); }) | ||
c.push_back(std::forward<Ref>(ref)); | ||
else if constexpr (requires { c.emplace(c.end(), declval<Ref>()); }) | ||
c.emplace(c.end(), std::forward<Ref>(ref)); | ||
else | ||
c.insert(c.end(), std::forward<Ref>(ref)); | ||
};</ins> | ||
}; | ||
</code></pre> | ||
</blockquote> | ||
</p> | ||
</blockquote> | ||
</li> | ||
<li><p>Modify <sref ref="[range.utility.conv.to]"/> as indicated:</p> | ||
<blockquote> | ||
<p>(2.1.4) Otherwise, if | ||
<ul style="list-style-type: none"> | ||
<li>— <code>constructible_from<C, Args...></code> is <code>true</code>, and</li> | ||
<li>— <code><i>container-insertable</i><C, range_reference_t<R>></code> is <code>true</code>:</li> | ||
</ul> | ||
<blockquote> | ||
<pre><code> | ||
C c(std::forward<Args>(args)...); | ||
if constexpr (sized_range<R> && <i>reservable-container</i><C>) | ||
c.reserve(static_cast<range_size_t<C>>(ranges::size(r))); | ||
ranges::<del>copy</del><ins>for_each</ins>(r, <i>container-inserter</i><del><range_reference_t<R>></del>(c)); | ||
</code></pre> | ||
</blockquote> | ||
</p> | ||
</blockquote> | ||
</li> | ||
</ol> | ||
</resolution> | ||
|
||
</issue> |