220 22439 <5cd9879e-a6e7-447f-8475-edc6b52d9716@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 02:53:15 -0800 (PST)
Lines: 156
Approved: news@gmane.org
Message-ID: <5cd9879e-a6e7-447f-8475-edc6b52d9716@isocpp.org>
References: <14fb89ea-443b-4696-93ec-29889f642bca@isocpp.org>
 <CAGNvRgBEn=wGT0Z3Wq+Pq4eKXinwEgsO66eQS6bw8WoCrgqC1A@mail.gmail.com>
 <cf9b040c-5008-4f40-bd53-0bf898f95ac2@isocpp.org>
 <CAGNvRgCgeNDgcJXUWQtqpR=eF=uVZpmHpDsZwm0QHXDd6jxdGw@mail.gmail.com>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: plane.gmane.org
Mime-Version: 1.0
Content-Type: multipart/mixed; 
	boundary="----=_Part_3216_194931952.1447239196036"
X-Trace: ger.gmane.org 1447239200 6357 80.91.229.3 (11 Nov 2015 10:53:20 GMT)
X-Complaints-To: usenet@ger.gmane.org
NNTP-Posting-Date: Wed, 11 Nov 2015 10:53:20 +0000 (UTC)
To: ISO C++ Standard - Future Proposals <std-proposals@isocpp.org>
Original-X-From: std-proposals+bncBDXJR44QUQHBBHN4RSZAKGQEQMEODDY@isocpp.org Wed Nov 11 11:53:20 2015
Return-path: <std-proposals+bncBDXJR44QUQHBBHN4RSZAKGQEQMEODDY@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-qg0-f69.google.com ([209.85.192.69])
	by plane.gmane.org with esmtp (Exim 4.69)
	(envelope-from <std-proposals+bncBDXJR44QUQHBBHN4RSZAKGQEQMEODDY@isocpp.org>)
	id 1ZwT1j-00019F-0C
	for gclcip-std-proposals@m.gmane.org; Wed, 11 Nov 2015 11:53:19 +0100
Original-Received: by qgdy74 with SMTP id y74sf29369636qgd.2
        for <gclcip-std-proposals@m.gmane.org>; Wed, 11 Nov 2015 02:53:18 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=isocpp_org.20150623.gappssmtp.com; s=20150623;
        h=date:from:to: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=eC3R9zBCV/hqio/5hJp8lICWNH6l8ki1LN4ZSKFiSss=;
        b=wCEWHjtR8Y9/BwtWyVYBa/FXgUzkTMNuC1E8GeqayolTcRxX99hmPxDeImK3opLhzP
         /JW8O9RAdfyf+yGsa3Q5uzU0v7qLBmixZsZKMvcKYzw0C7x5MCDR2Z7xWn2NBYO7/oUO
         qwHh1Kk4i495xZZAs+IAnPMTEOkYuCDrVl+SpvJhJsEGTY82QpUw4KPLV3wJyMQh7Svt
         E4eeDpi0ayAgLjO/7mUF9qQGfWKjSAG8Nt3+U75ZtRNrDwjAA5865wq4vFGZxgOwySUi
         rJ4OU/cdtKDsSFzwV7dYyuMttvAKXSB2dtezLDTMoywUoSogF44sEDHVvXZF7TxAmk5v
         45ZA==
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20120113;
        h=date:from:to: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=eC3R9zBCV/hqio/5hJp8lICWNH6l8ki1LN4ZSKFiSss=;
        b=JeUTkRdeWceoKae/jF6rH462Wfsep/v1FxhnN8A/Er5iV3EfDwnCmDK7CI22AIoini
         Mt2rcRJStPABGhqaOU2BGDjqr96wlLZFdU16e6h4pfQiHBrZWNpG0XnSe+RZgpSExpRD
         hwWfNkLTUP+m2IDFae7qM6QrxizffYvXjZJLFScBmuw7QlurRmzvNMCqilkb2TxZdBMV
         zvYykrmneqP6dK3mIWeFtYdti2b09eMKMSydEN02AzFRt3jxX68u+6OtiHgo8NtJPd1C
         kCvaCPMS0fKbrb6qndm/jl8hyJH0vFUsXoCLz6HTzD84jUpE7T140kvGReILbhOwC7St
         O8hQ==
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: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=eC3R9zBCV/hqio/5hJp8lICWNH6l8ki1LN4ZSKFiSss=;
        b=Sx37s8e8uP4KDLjnI2oPGdLjc+jwqo2diVQ/kbUOSueUc/edQqeVXMkpNiP2l7CiAF
         AUpd7dCuJr/WTEkCnGLLnljGuiH6NBCP7A5VFiPTDAReNxEm6B/CtdO8S8sdxwo4D4cR
         qHu8h/FY2CX1GKERVPiRhU0KSI9GFmsT6uuaJIcrjhAlxT2QkUvjk8I+A/QIuJ34GZTz
         oETI2timcqaFIZWJKConrtWHXp1TXZgm6cKaExMeqbLGRXwmGJQkn67ohPgQUAGSGXSp
         8YjK1qtvHCFLWDBQg6KP3FMOKntqQ9y+yXq7u1dR4yy+dWs8qrMFBwpBa/mu1b8W/EyK
         +Qcg==
X-Gm-Message-State: ALoCoQkkw1Bu+m6uAsl9V+V6EsvIvtpNtO1Nb6cvDx6R0bMHsNy4D1mGNyVm0bX8xiSzh9XbaZp+
X-Received: by 10.13.192.134 with SMTP id b128mr7223609ywd.43.1447239198100;
        Wed, 11 Nov 2015 02:53:18 -0800 (PST)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.50.73.199 with SMTP id n7ls148749igv.9.gmail; Wed, 11 Nov 2015
 02:53:16 -0800 (PST)
X-Received: by 10.50.126.99 with SMTP id mx3mr211942igb.1.1447239196834;
        Wed, 11 Nov 2015 02:53:16 -0800 (PST)
In-Reply-To: <CAGNvRgCgeNDgcJXUWQtqpR=eF=uVZpmHpDsZwm0QHXDd6jxdGw@mail.gmail.com>
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:22439
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/22439>

------=_Part_3216_194931952.1447239196036
Content-Type: multipart/alternative; 
	boundary="----=_Part_3217_812763143.1447239196036"

------=_Part_3217_812763143.1447239196036
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

Ok, this is my last try :).

What if we use the first declaration:

vector(size_type n,vector::forward_args_type,Args&&... args);

But inside vector's constructor we convert every rvalue references in args=
=20
to const ref. Of course this behavior should be well documented and I maybe=
=20
this can be confusing.

About converting rvalue references one can define the following type:

template<typename T>
using forward_for_copy=3Dstd::conditional_t< std::is_rvalue_reference<T>{},
                                           const T&,
                                           T >;

Can be used this way:
template<class... Args>
int f(Args&&... args)
{
        h(static_cast<forward_for_copy<Args>>(args)...);
        return 0;
}

(Maybe "forward for copy" is not the best name though.) The main idea that=
=20
vector's constructor would forward args this way to std::allocator's=20
"construct" member function. The constructor would accept literals, but it=
=20
wouldn't move objects even if they are movable.

I'm getting a little bit lost here though, maybe this suggestion adds even=
=20
more problems than what it solves.

- 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_3217_812763143.1447239196036
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">Ok, this is my last try :).<div><br></div><div>What if we =
use the first declaration:</div><div><br></div><div><div class=3D"prettypri=
nt" style=3D"border: 1px solid rgb(187, 187, 187); word-wrap: break-word; b=
ackground-color: rgb(250, 250, 250);"><code class=3D"prettyprint"><div clas=
s=3D"subprettyprint"><span style=3D"color: rgb(0, 0, 0);"><span style=3D"co=
lor: #000;" class=3D"styled-by-prettify">vector</span></span><span style=3D=
"color: rgb(102, 102, 0);"><span style=3D"color: #660;" class=3D"styled-by-=
prettify">(</span></span><span style=3D"color: rgb(0, 0, 0);"><span style=
=3D"color: #000;" class=3D"styled-by-prettify">size_type n</span></span><sp=
an style=3D"color: rgb(102, 102, 0);"><span style=3D"color: #660;" class=3D=
"styled-by-prettify">,</span></span><span style=3D"color: rgb(0, 0, 0);"><s=
pan style=3D"color: #000;" class=3D"styled-by-prettify">vector</span></span=
><span style=3D"color: rgb(102, 102, 0);"><span style=3D"color: #660;" clas=
s=3D"styled-by-prettify">::</span><span style=3D"color: #000;" class=3D"sty=
led-by-prettify">forward_args</span></span><span style=3D"color: rgb(0, 0, =
0);"><span style=3D"color: #000;" class=3D"styled-by-prettify">_type</span>=
</span><span style=3D"color: rgb(102, 102, 0);"><wbr><span style=3D"color: =
#660;" class=3D"styled-by-prettify">,</span></span><span style=3D"color: rg=
b(102, 0, 102);"><span style=3D"color: #606;" class=3D"styled-by-prettify">=
Args</span></span><span style=3D"color: rgb(102, 102, 0);"><span style=3D"c=
olor: #660;" class=3D"styled-by-prettify">&amp;&amp;...</span></span><span =
style=3D"color: rgb(0, 0, 0);"><span style=3D"color: #000;" class=3D"styled=
-by-prettify"> args</span></span><span style=3D"color: rgb(102, 102, 0);"><=
span style=3D"color: #660;" class=3D"styled-by-prettify">);</span></span><s=
pan style=3D"color: #000;" class=3D"styled-by-prettify"><br></span></div></=
code></div><br>But inside vector&#39;s constructor we convert every rvalue =
references in args to const ref. Of course this behavior should be well doc=
umented and I maybe this can be confusing.</div><div><br></div><div>About c=
onverting rvalue references one can define the following type:</div><div><b=
r></div><div><div class=3D"prettyprint" style=3D"border: 1px solid rgb(187,=
 187, 187); word-wrap: break-word; background-color: rgb(250, 250, 250);"><=
code class=3D"prettyprint"><div class=3D"subprettyprint"><span style=3D"fon=
t-family: Arial, Helvetica, sans-serif;"><span style=3D"color: #008;" class=
=3D"styled-by-prettify">template</span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">&lt;</span><span style=3D"color: #008;" class=3D"st=
yled-by-prettify">typename</span><span style=3D"color: #000;" class=3D"styl=
ed-by-prettify"> T</span><span style=3D"color: #660;" class=3D"styled-by-pr=
ettify">&gt;</span></span></div></code><div class=3D"subprettyprint">using =
forward_for_copy=3Dstd::conditional_t&lt; std::is_rvalue_reference&lt;T&gt;=
{},</div><div class=3D"subprettyprint">=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0const T&amp;,</div><div class=
=3D"subprettyprint">=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0=
 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
=A0 =C2=A0 =C2=A0 =C2=A0T &gt;;</div></div><br>Can be used this way:</div><=
div><div class=3D"prettyprint" style=3D"border: 1px solid rgb(187, 187, 187=
); word-wrap: break-word; background-color: rgb(250, 250, 250);"><code clas=
s=3D"prettyprint"><div class=3D"subprettyprint"><span style=3D"font-family:=
 Arial, Helvetica, sans-serif;"><span style=3D"color: #008;" class=3D"style=
d-by-prettify">template</span><span style=3D"color: #660;" class=3D"styled-=
by-prettify">&lt;</span><span style=3D"color: #008;" class=3D"styled-by-pre=
ttify">class</span><span style=3D"color: #660;" class=3D"styled-by-prettify=
">...</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </sp=
an><span style=3D"color: #606;" class=3D"styled-by-prettify">Args</span><sp=
an style=3D"color: #660;" class=3D"styled-by-prettify">&gt;</span><span sty=
le=3D"color: #000;" class=3D"styled-by-prettify"><br></span><span style=3D"=
color: #008;" class=3D"styled-by-prettify">int</span><span style=3D"color: =
#000;" class=3D"styled-by-prettify"> f</span><span style=3D"color: #660;" c=
lass=3D"styled-by-prettify">(</span><span style=3D"color: #606;" class=3D"s=
tyled-by-prettify">Args</span><span style=3D"color: #660;" class=3D"styled-=
by-prettify">&amp;&amp;...</span><span style=3D"color: #000;" class=3D"styl=
ed-by-prettify"> args</span><span style=3D"color: #660;" class=3D"styled-by=
-prettify">)</span></span></div></code><div class=3D"subprettyprint">{</div=
><div class=3D"subprettyprint">=C2=A0 =C2=A0 =C2=A0 =C2=A0 h(static_cast&lt=
;forward_for_copy&lt;Args&gt;&gt;(args)...);</div><div class=3D"subprettypr=
int">=C2=A0 =C2=A0 =C2=A0 =C2=A0 return 0;</div><div class=3D"subprettyprin=
t">}</div></div><br>(Maybe &quot;forward for copy&quot; is not the best nam=
e though.) The main idea that vector&#39;s constructor would forward args t=
his way to std::allocator&#39;s &quot;construct&quot; member function. The =
constructor would accept literals, but it wouldn&#39;t move objects even if=
 they are movable.</div><div><br></div><div>I&#39;m getting a little bit lo=
st here though, maybe this suggestion adds even more problems than what it =
solves.</div><div><br></div><div>- L=C3=A9n=C3=A1rd</div></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_3217_812763143.1447239196036--
------=_Part_3216_194931952.1447239196036--

.
