Topic: Perfectly forwarding initializer_list, in cases other


Author: Arthur O'Dwyer <arthur.j.odwyer@gmail.com>
Date: Sun, 27 Nov 2016 01:33:38 -0800 (PST)
Raw View
------=_Part_187_1080890751.1480239218659
Content-Type: multipart/alternative;
 boundary="----=_Part_188_594114577.1480239218659"

------=_Part_188_594114577.1480239218659
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

Now that std::any, std::optional, and std::variant have blessed the idea of=
=20
splitting each "perfectly forwarding emplacement function" into a pair of=
=20
functions, one taking initializer_list and the other not, I wonder if=20
there's any significant interest in retrofitting that solution onto the=20
rest of the STL containers.

For example, to take this current wording in [forwardlist.modifiers]

template <class... Args> reference emplace_front(Args&&... args);

Effects: Inserts an object of type value_type constructed with value_type(s=
td::forward<Args>(=20
args)...) at the beginning of the list.=20

and replace it with this wording instead:

template <class... Args> reference emplace_front(Args&&... args);

Effects: Inserts an object of type value_type constructed with value_type(s=
td::forward<Args>(=20
args)...) at the beginning of the list.=20

Remarks: This function shall not participate in overload resolution unless =
is_constructible_v<T,=20
Args...> is true.


template <class U, class... Args> reference emplace_front(initializer_list<=
U> il, Args&&... args);

Effects: Inserts an object of type value_type constructed with value_type(i=
l,=20
std::forward<Args>( args)...) at the beginning of the list.=20
Remarks: This function shall not participate in overload resolution unless =
is_constructible_v<T,=20
std::initializer_list<U>&, Args...> is true.


and so on for std::vector, std::list, std::deque,...
Is there a technical reason this retrofitting hasn't happened, or is it=20
just one of those "nobody's written the paper yet" cases?

Ville's N4462=20
<http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2015/n4462.html> seems=
=20
to be a discussion of the "how to forward initializer_list" problem in=20
general, but AFAICT it dates from before the adoption of the two-function=
=20
approach. I don't know where the two-function approach originally came from=
=20
=E2=80=94 not that I've tried very hard to find out.

=E2=80=93Arthur

--=20
You received this message because you are subscribed to the Google Groups "=
ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp=
..org/d/msgid/std-proposals/2adcd4e7-8711-4a6c-b5b6-8ea910e8b8bc%40isocpp.or=
g.

------=_Part_188_594114577.1480239218659
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><div>Now that std::any, std::optional, and std::variant ha=
ve blessed the idea of splitting each &quot;perfectly forwarding emplacemen=
t function&quot; into a pair of functions, one taking initializer_list and =
the other not, I wonder if there&#39;s any significant interest in retrofit=
ting that solution onto the rest of the STL containers.</div><div><br></div=
><div>For example, to take this current wording in [forwardlist.modifiers]<=
/div><div><br></div><div>
 =09
=09
=09
  <div class=3D"page" title=3D"Page 899">
   <div class=3D"layoutArea">
    <div class=3D"column">
     <pre><span style=3D"font-family: LMMono9;"><font size=3D"4">template &=
lt;class... Args&gt; reference emplace_front(Args&amp;&amp;... args);
</font></span></pre>
    </div>
   </div>
  </div></div><div>
 =09
=09
=09
  <div class=3D"page" title=3D"Page 899">
   <div class=3D"layoutArea">
    <div class=3D"column">
     <p><font size=3D"4"><span style=3D"font-family: LMRoman10; font-style:=
 italic;">Effects: </span><span style=3D"font-family: LMRoman10;">Inserts a=
n object of type </span><span style=3D"font-family: LMMono10;">value_type <=
/span><span style=3D"font-family: LMRoman10;">constructed with </span><span=
 style=3D"font-family: LMMono10;">value_type(std::forward&lt;Args&gt;(
args)...) </span><span style=3D"font-family: LMRoman10;">at the beginning o=
f the list.=C2=A0</span></font></p>
    </div>
   </div>
  </div></div><div><br></div><div>and replace it with this wording instead:=
</div><div><br></div><div><div><div class=3D"page" title=3D"Page 899"><div =
class=3D"layoutArea"><div class=3D"column"><pre><span style=3D"font-family:=
 LMMono9;"><font size=3D"4">template &lt;class... Args&gt; reference emplac=
e_front(Args&amp;&amp;... args);
</font></span></pre></div></div></div></div><div><div class=3D"page" title=
=3D"Page 899"><div class=3D"layoutArea"><div class=3D"column"><p><font size=
=3D"4"><span style=3D"font-family: LMRoman10; font-style: italic;">Effects:=
=C2=A0</span><span style=3D"font-family: LMRoman10;">Inserts an object of t=
ype=C2=A0</span><span style=3D"font-family: LMMono10;">value_type=C2=A0</sp=
an><span style=3D"font-family: LMRoman10;">constructed with=C2=A0</span><sp=
an style=3D"font-family: LMMono10;">value_type(std::forward&lt;Args&gt;( ar=
gs)...)=C2=A0</span><span style=3D"font-family: LMRoman10;">at the beginnin=
g of the list.=C2=A0</span></font></p><div>
 =09
=09
=09
  <div class=3D"page" title=3D"Page 589">
   <div class=3D"layoutArea">
    <div class=3D"column">
    =09
 =09
=09
=09
  <p><font size=3D"4"><span style=3D"font-family: LMRoman10; font-style: it=
alic;">Remarks:=C2=A0</span><span style=3D"font-family: LMRoman10;">This fu=
nction shall not participate in overload resolution unless </span><span sty=
le=3D"font-family: LMMono10;">is_constructible_v&lt;T,
Args...&gt; </span><span style=3D"font-family: LMRoman10;">is </span><span =
style=3D"font-family: LMMono10;">true.</span></font></p><p><span style=3D"f=
ont-family: LMMono10;"><font size=3D"4"><br></font></span></p>
    </div>
   </div>
  </div></div><div><div><div class=3D"page" title=3D"Page 899"><div class=
=3D"layoutArea"><div class=3D"column"><pre><span style=3D"font-family: LMMo=
no9;"><font size=3D"4">template &lt;class U, class... Args&gt; reference em=
place_front(initializer_list&lt;U&gt; il, Args&amp;&amp;... args);
</font></span></pre></div></div></div></div><div><div class=3D"page" title=
=3D"Page 899"><div class=3D"layoutArea"><div class=3D"column"><p><font size=
=3D"4"><span style=3D"font-family: LMRoman10; font-style: italic;">Effects:=
=C2=A0</span><span style=3D"font-family: LMRoman10;">Inserts an object of t=
ype=C2=A0</span><span style=3D"font-family: LMMono10;">value_type=C2=A0</sp=
an><span style=3D"font-family: LMRoman10;">constructed with=C2=A0</span><sp=
an style=3D"font-family: LMMono10;">value_type(il, std::forward&lt;Args&gt;=
( args)...)=C2=A0</span><span style=3D"font-family: LMRoman10;">at the begi=
nning of the list.=C2=A0</span></font></p><div><font size=3D"4"><span style=
=3D"font-family: LMRoman10; font-style: italic;">Remarks:=C2=A0</span><span=
 style=3D"font-family: LMRoman10;">This function shall not participate in o=
verload resolution unless=C2=A0</span><span style=3D"font-family: LMMono10;=
">is_constructible_v&lt;T, std::initializer_list&lt;U&gt;&amp;, Args...&gt;=
=C2=A0</span><span style=3D"font-family: LMRoman10;">is=C2=A0</span><span s=
tyle=3D"font-family: LMMono10;">true.</span><span style=3D"font-family: LMR=
oman10;"><br></span></font></div><div><br><br>and so on for std::vector, st=
d::list, std::deque,...<br>Is there a technical reason this retrofitting ha=
sn&#39;t happened, or is it just one of those &quot;nobody&#39;s written th=
e paper yet&quot; cases?<br></div></div></div></div></div></div></div></div=
></div></div></div><div><br></div><div>Ville&#39;s <a href=3D"http://www.op=
en-std.org/jtc1/sc22/wg21/docs/papers/2015/n4462.html">N4462</a>=C2=A0seems=
 to be a discussion of the &quot;how to forward initializer_list&quot; prob=
lem in general, but AFAICT it dates from before the adoption of the two-fun=
ction approach. I don&#39;t know where the two-function approach originally=
 came from =E2=80=94 not that I&#39;ve tried very hard to find out.</div><d=
iv><br></div><div>=E2=80=93Arthur</div></div>

<p></p>

-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/2adcd4e7-8711-4a6c-b5b6-8ea910e8b8bc%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/2adcd4e7-8711-4a6c-b5b6-8ea910e8b8bc=
%40isocpp.org</a>.<br />

------=_Part_188_594114577.1480239218659--

------=_Part_187_1080890751.1480239218659--

.