220 22468 <dbf27d2b-f57c-49dc-ace8-63fe72149738@isocpp.org> article
Path: news.gmane.org!not-for-mail
From: leni536@gmail.com
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Re: std::vector (and other containers) to have a
 perfect forwarding constructor
Date: Wed, 11 Nov 2015 09:09:44 -0800 (PST)
Lines: 146
Approved: news@gmane.org
Message-ID: <dbf27d2b-f57c-49dc-ace8-63fe72149738@isocpp.org>
References: <14fb89ea-443b-4696-93ec-29889f642bca@isocpp.org>
 <n1vjll$vbh$1@ger.gmane.org>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: plane.gmane.org
Mime-Version: 1.0
Content-Type: multipart/mixed; 
	boundary="----=_Part_2761_1580705303.1447261784243"
X-Trace: ger.gmane.org 1447261788 3614 80.91.229.3 (11 Nov 2015 17:09:48 GMT)
X-Complaints-To: usenet@ger.gmane.org
NNTP-Posting-Date: Wed, 11 Nov 2015 17:09:48 +0000 (UTC)
Cc: mwoehlke.floss@gmail.com
To: ISO C++ Standard - Future Proposals <std-proposals@isocpp.org>
Original-X-From: std-proposals+bncBDXJR44QUQHBBWPMRWZAKGQETZKOD4Y@isocpp.org Wed Nov 11 18:09:48 2015
Return-path: <std-proposals+bncBDXJR44QUQHBBWPMRWZAKGQETZKOD4Y@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-io0-f197.google.com ([209.85.223.197])
	by plane.gmane.org with esmtp (Exim 4.69)
	(envelope-from <std-proposals+bncBDXJR44QUQHBBWPMRWZAKGQETZKOD4Y@isocpp.org>)
	id 1ZwYu3-0002jU-IV
	for gclcip-std-proposals@m.gmane.org; Wed, 11 Nov 2015 18:09:47 +0100
Original-Received: by iofh3 with SMTP id h3sf68261561iof.1
        for <gclcip-std-proposals@m.gmane.org>; Wed, 11 Nov 2015 09:09:46 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=isocpp_org.20150623.gappssmtp.com; s=20150623;
        h=date:from:to:cc:message-id:in-reply-to:references:subject
         :mime-version:content-type:x-original-sender:reply-to:precedence
         :mailing-list:list-id:x-spam-checked-in-group:list-post:list-help
         :list-archive:list-subscribe:list-unsubscribe;
        bh=tbbkvZF+dopy8CNXQtViqlL+s2BzpaKqbzX27jLd11Y=;
        b=gyOQ9NvJuknsqCECf3nc6Ucl0yoL2H/9lxDblgfoupKi1s5YrmPkKrb0cD0jUwCojg
         a9O0SZ+/vgHPglIHrffS60uMGXhdT7ltfVozXgR+vIukh5MoffuwdnI4m2lKxIkIW7Kl
         hDR5atGhPlpw37pdud2FTnXKlLwUwpLa/8bOuxKGSPqDwFbvYmMiEbOVvRQXM+oNFgun
         J5x5HlfVYdSDv+KYe2REbElimsYgs3ktROPic8FH2b1zc/d6yVpN+63S3lSdkTImJuS3
         eOSVrE7920DiTPgGQs7im+YBwgYK5mYl1hXvPF2ZVthJh6UhOnTL0N1ugbDATerZbcSE
         h6vg==
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20120113;
        h=date:from:to:cc:message-id:in-reply-to:references:subject
         :mime-version:content-type:x-original-sender:reply-to:precedence
         :mailing-list:list-id:x-spam-checked-in-group:list-post:list-help
         :list-archive:list-subscribe:list-unsubscribe;
        bh=tbbkvZF+dopy8CNXQtViqlL+s2BzpaKqbzX27jLd11Y=;
        b=cMhb3shwwdP6Z8wUAp9+D5JIr5zWPXM5q4+mti3P6DtDoq4EKBiKta+Yirgv/sGxSS
         yqFIXcH2PMeUZ3LxsuD3mu+KubvtTTrrZwPAVgKd2tyWxl+sXaAZJnI6oKjFH0IFjObS
         dCTO0WFWk5h6+ekWmV6MU+KSGgFwKAw8IDfv+EpRIEikCCAQUiQB2Z7xHF1Nm+dR61QY
         FSt/70G5R9Ze8bNmRvzKA7+lEgFFYixQt/dXOR0q2zv1wOM1wA/5V29Pa2mWGXGpFiO7
         kp14g+ZmDALzMV1cU0mzCWF2RYZD1nVB04UUUcIMlBqlWdeIYaDUBU2f4CLEeh5oUL5Q
         doXw==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20130820;
        h=x-gm-message-state:date:from:to:cc:message-id:in-reply-to
         :references:subject:mime-version:content-type:x-original-sender
         :reply-to:precedence:mailing-list:list-id:x-spam-checked-in-group
         :list-post:list-help:list-archive:list-subscribe:list-unsubscribe;
        bh=tbbkvZF+dopy8CNXQtViqlL+s2BzpaKqbzX27jLd11Y=;
        b=azcDO1KwgV0P52x8uTLfpHq4wovD45+736BsLBeCBWGH6trEwx2ZJoGDdvlH6pl1/x
         5rnbsB05tJmGIvgIKnDs6xeXgXu8+t0jGz2q39ZagmPgwMghehdR+imwxucfM0nFsUUd
         m5Ei0REI3xkEqQsoT+5BN937x++fVFSfU11YqYrtWh1jhC4m6qU6NOVcajBi7DneRDi8
         FKkhe9BNt44kdeLpVtWu4xuHW82U9N6aBPhgMWLrNIvZrbwtJD62Ih1q8O0wmwA0N/TE
         cbYDcSBnZP8C3rrtQa2MwpG63YQdXETZ87rm7ENDMSDTuvFMUyPeLwUO8JprTYG09S4D
         2W7w==
X-Gm-Message-State: ALoCoQl0hd5zAdKXNrzwCm1CfZXMUwm3O3vh9eznd+PjA2RwU2Mw1YS0wWC3Jm5AutkS8Fsw5F5t
X-Received: by 10.107.8.221 with SMTP id h90mr9663889ioi.29.1447261786534;
        Wed, 11 Nov 2015 09:09:46 -0800 (PST)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.107.2.22 with SMTP id 22ls195756ioc.58.gmail; Wed, 11 Nov 2015
 09:09:45 -0800 (PST)
X-Received: by 10.50.3.41 with SMTP id 9mr790284igz.7.1447261785150;
        Wed, 11 Nov 2015 09:09:45 -0800 (PST)
In-Reply-To: <n1vjll$vbh$1@ger.gmane.org>
X-Original-Sender: leni536@gmail.com
Precedence: list
Mailing-list: list std-proposals@isocpp.org; contact std-proposals+owners@isocpp.org
List-ID: <std-proposals.isocpp.org>
X-Spam-Checked-In-Group: std-proposals@isocpp.org
X-Google-Group-Id: 399137483710
List-Post: <http://groups.google.com/a/isocpp.org/group/std-proposals/post>, <mailto:std-proposals@isocpp.org>
List-Help: <http://support.google.com/a/isocpp.org/bin/topic.py?topic=25838>, <mailto:std-proposals+help@isocpp.org>
List-Archive: <http://groups.google.com/a/isocpp.org/group/std-proposals/>
List-Subscribe: <http://groups.google.com/a/isocpp.org/group/std-proposals/subscribe>,
 <mailto:std-proposals+subscribe@isocpp.org>
List-Unsubscribe: <mailto:googlegroups-manage+399137483710+unsubscribe@googlegroups.com>,
 <http://groups.google.com/a/isocpp.org/group/std-proposals/subscribe>
Xref: news.gmane.org gmane.comp.lang.c++.isocpp.proposals:22468
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/22468>

------=_Part_2761_1580705303.1447261784243
Content-Type: multipart/alternative; 
	boundary="----=_Part_2762_1956493067.1447261784243"

------=_Part_2762_1956493067.1447261784243
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable



On Wednesday, November 11, 2015 at 3:36:38 PM UTC+1, Matthew Woehlke wrote:
>
> On 2015-11-11 03:52, len...@gmail.com <javascript:> wrote:=20
> > I didn't find a topic like this, so here it is. Something like this=20
> would=20
> > be nice:=20
> >=20
> > template <class... Args>=20
> > vector(size_type n,Args&&... args);=20
> >=20
> > 1) It could be faster than vector(n,value_type(args)) if value_type's=
=20
> copy=20
> > constructor is more expensive than its constructor with "args"=20
> parameters=20
> > (I don't know a good example though).=20
>
> Interesting idea. And since vector(n, value_type(...)) invokes=20
> value_type's copy ctor, it is in fact a subset of the proposed syntax,=20
> i.e. that form could be deprecated / removed in favor of the proposed=20
> "emplace" version.


I don't think it's possible because of the optional "const allocator_type&"=
=20
argument. I don't know if it's explicitly forbidden or not, but my hunch is=
=20
that optional and variadic parameters don't mix well.=20

I think I made mistake in the usage of my "forward_for_copy" type trait,=20
one can use the following function instead:
template<typename T>
constexpr
decltype(auto)
forward_for_copy(std::remove_reference_t<T>& x) noexcept
{
        using ReturnType=3Dstd::conditional_t<
                std::is_rvalue_reference<T&&>{},
                const T&,=20
                T &>;=20
        return static_cast<ReturnType>(x);
}

Use similarly to "std::forward". What it does:

   1. Leaves lvalue references alone.
   2. Static casts all rvalue references to const lvalue references.

- L=C3=A9n=C3=A1rd

--=20

---=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.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposa=
ls/.

------=_Part_2762_1956493067.1447261784243
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<br><br>On Wednesday, November 11, 2015 at 3:36:38 PM UTC+1, Matthew Woehlk=
e wrote:<blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-left: 0=
..8ex;border-left: 1px #ccc solid;padding-left: 1ex;">On 2015-11-11 03:52, <=
a href=3D"javascript:" target=3D"_blank" gdf-obfuscated-mailto=3D"nEAqKGcxF=
wAJ" rel=3D"nofollow" onmousedown=3D"this.href=3D&#39;javascript:&#39;;retu=
rn true;" onclick=3D"this.href=3D&#39;javascript:&#39;;return true;">len...=
@gmail.com</a> wrote:
<br>&gt; I didn&#39;t find a topic like this, so here it is. Something like=
 this would=20
<br>&gt; be nice:
<br>&gt;=20
<br>&gt; template &lt;class... Args&gt;
<br>&gt; vector(size_type n,Args&amp;&amp;... args);
<br>&gt;=20
<br>&gt; 1) It could be faster than vector(n,value_type(args)) if value_typ=
e&#39;s copy=20
<br>&gt; constructor is more expensive than its constructor with &quot;args=
&quot; parameters=20
<br>&gt; (I don&#39;t know a good example though).
<br>
<br>Interesting idea. And since vector(n, value_type(...)) invokes
<br>value_type&#39;s copy ctor, it is in fact a subset of the proposed synt=
ax,
<br>i.e. that form could be deprecated / removed in favor of the proposed
<br>&quot;emplace&quot; version.</blockquote><div><br></div><div>I don&#39;=
t think it&#39;s possible because of the optional &quot;const allocator_typ=
e&amp;&quot; argument. I don&#39;t know if it&#39;s explicitly forbidden or=
 not, but my hunch is that optional and variadic parameters don&#39;t mix w=
ell.=C2=A0</div><div><br></div><div>I think I made mistake in the usage of =
my &quot;forward_for_copy&quot; type trait, one can use the following funct=
ion instead:</div><div><div class=3D"prettyprint" style=3D"border: 1px soli=
d rgb(187, 187, 187); word-wrap: break-word; background-color: rgb(250, 250=
, 250);"><code class=3D"prettyprint"><div class=3D"subprettyprint"><span st=
yle=3D"color: #000;" class=3D"styled-by-prettify"><div class=3D"subprettypr=
int">template&lt;typename T&gt;</div><div class=3D"subprettyprint">constexp=
r</div><div class=3D"subprettyprint">decltype(auto)</div><div class=3D"subp=
rettyprint">forward_for_copy(std::remove_reference_t&lt;T&gt;&amp; x) noexc=
ept</div><div class=3D"subprettyprint">{</div><div class=3D"subprettyprint"=
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 using ReturnType=3Dstd::conditional_t&lt;</div=
><div class=3D"subprettyprint">=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
=C2=A0 =C2=A0 std::is_rvalue_reference&lt;T&amp;&amp;&gt;{},</div><div clas=
s=3D"subprettyprint">=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
=A0 const T&amp;,=C2=A0</div><div class=3D"subprettyprint">=C2=A0 =C2=A0 =
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 T &amp;&gt;;=C2=A0</div><div clas=
s=3D"subprettyprint">=C2=A0 =C2=A0 =C2=A0 =C2=A0 return static_cast&lt;Retu=
rnType&gt;(x);</div><div class=3D"subprettyprint">}</div></span></div></cod=
e></div></div><div><br></div><div>Use similarly to &quot;std::forward&quot;=
.. What it does:</div><div><ol><li><span style=3D"line-height: normal;">Leav=
es lvalue references alone.</span></li><li><span style=3D"line-height: norm=
al;">Static casts all rvalue references to const lvalue references.</span><=
/li></ol></div><div>- L=C3=A9n=C3=A1rd</div>

<p></p>

-- <br />
<br />
--- <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 />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />

------=_Part_2762_1956493067.1447261784243--
------=_Part_2761_1580705303.1447261784243--

.
