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 from Hewill Kang: "ranges::to's copy branch is underconstra…
…ined"
- Loading branch information
Showing
1 changed file
with
90 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,90 @@ | ||
<?xml version='1.0' encoding='utf-8' standalone='no'?> | ||
<!DOCTYPE issue SYSTEM "lwg-issue.dtd"> | ||
|
||
<issue num="4018" status="New"> | ||
<title><tt>ranges::to</tt>'s copy branch is underconstrained</title> | ||
<section><sref ref="[range.utility.conv.to]"/></section> | ||
<submitter>Hewill Kang</submitter> | ||
<date>25 Nov 2023</date> | ||
<priority>99</priority> | ||
|
||
<discussion> | ||
<p> | ||
Unlike other branches that return a prvalue <tt>C</tt>, this branch's <tt>C</tt> is returned by elidable move, | ||
indicating that <tt>C</tt> needs to be move constructible (<a href="https://godbolt.org/z/dfqnx6Txq">demo</a>): | ||
</p> | ||
<blockquote><pre> | ||
#include <ranges> | ||
#include <vector> | ||
|
||
struct nonmovable { | ||
nonmovable() = default; | ||
nonmovable(const nonmovable&) = delete; | ||
nonmovable& operator=(const nonmovable&) = delete; | ||
}; | ||
|
||
template<class T> | ||
struct nonmovable_vector : std::vector<T>, nonmovable { }; | ||
|
||
int main() { | ||
int arr[] = {42}; | ||
auto v = std::ranges::to<nonmovable_vector<int>>(arr); // <span style="color:red;font-weight:bolder">hard error</span> | ||
} | ||
</pre></blockquote> | ||
</discussion> | ||
|
||
<resolution> | ||
<p> | ||
This wording is relative to <paper num="N4964"/>. | ||
</p> | ||
|
||
<ol> | ||
|
||
<li><p>Modify <sref ref="[range.utility.conv.to]"/> as indicated:</p> | ||
|
||
<blockquote> | ||
<pre> | ||
template<class C, input_range R, class... Args> requires (!view<C>) | ||
constexpr C to(R&& r, Args&&... args); | ||
</pre> | ||
<blockquote> | ||
<p> | ||
-1- <i>Mandates</i>: <tt>C</tt> is a cv-unqualified class type. | ||
</p> | ||
<p> | ||
-2- <i>Returns</i>: An object of type <tt>C</tt> constructed from the elements of <tt>r</tt> in the following manner: | ||
</p> | ||
<ol style="list-style-type: none"> | ||
<li><p>(2.1) — If <tt>C</tt> does not satisfy <tt>input_range</tt> or | ||
<tt>convertible_to<range_reference_t<R>, range_value_t<C>></tt> is <tt>true</tt>:</p> | ||
<ol style="list-style-type: none"> | ||
<li><p>(2.1.1) — […]</p></li> | ||
<li><p>(2.1.2) — […]</p></li> | ||
<li><p>(2.1.3) — […]</p></li> | ||
<li><p>(2.1.4) — Otherwise, if</p> | ||
<ol style="list-style-type: none"> | ||
<li><p><ins>(2.1.4.?) — <tt>move_constructible<C></tt> is <tt>true</tt>,</ins></p></li> | ||
<li><p>(2.1.4.1) — <tt>constructible_from<C, Args...></tt> is <tt>true</tt>, and</p></li> | ||
<li><p>(2.1.4.2) — <tt><i>container-insertable</i><C, range_reference_t<R>></tt> is <tt>true</tt>:</p> | ||
<blockquote><pre> | ||
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::copy(r, <i>container-inserter</i><range_reference_t<R>>(c)); | ||
</pre></blockquote></li> | ||
</ol> | ||
</li> | ||
<li><p>(2.1.5) — Otherwise, the program is ill-formed.</p></li> | ||
</ol></li> | ||
<li><p>(2.2) — […]</p></li> | ||
<li><p>(2.3) — Otherwise, the program is ill-formed.</p></li> | ||
</ol> | ||
|
||
</blockquote> | ||
</blockquote> | ||
</li> | ||
|
||
</ol> | ||
</resolution> | ||
|
||
</issue> |