220 22436 <CAGNvRgBEn=wGT0Z3Wq+Pq4eKXinwEgsO66eQS6bw8WoCrgqC1A@mail.gmail.com> article
Path: news.gmane.org!not-for-mail
From: =?UTF-8?Q?Daniel_Kr=C3=BCgler?= <daniel.kruegler@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 10:01:55 +0100
Lines: 40
Approved: news@gmane.org
Message-ID: <CAGNvRgBEn=wGT0Z3Wq+Pq4eKXinwEgsO66eQS6bw8WoCrgqC1A@mail.gmail.com>
References: <14fb89ea-443b-4696-93ec-29889f642bca@isocpp.org>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: plane.gmane.org
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
X-Trace: ger.gmane.org 1447232527 26641 80.91.229.3 (11 Nov 2015 09:02:07 GMT)
X-Complaints-To: usenet@ger.gmane.org
NNTP-Posting-Date: Wed, 11 Nov 2015 09:02:07 +0000 (UTC)
To: std-proposals@isocpp.org
Original-X-From: std-proposals+bncBCT7RVFA4QORBA4IRSZAKGQEIXKDIRY@isocpp.org Wed Nov 11 10:01:58 2015
Return-path: <std-proposals+bncBCT7RVFA4QORBA4IRSZAKGQEIXKDIRY@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-lb0-f199.google.com ([209.85.217.199])
	by plane.gmane.org with esmtp (Exim 4.69)
	(envelope-from <std-proposals+bncBCT7RVFA4QORBA4IRSZAKGQEIXKDIRY@isocpp.org>)
	id 1ZwRHx-0001c7-64
	for gclcip-std-proposals@m.gmane.org; Wed, 11 Nov 2015 10:01:57 +0100
Original-Received: by lbbko8 with SMTP id ko8sf7026701lbb.2
        for <gclcip-std-proposals@m.gmane.org>; Wed, 11 Nov 2015 01:01:56 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=isocpp_org.20150623.gappssmtp.com; s=20150623;
        h=mime-version:in-reply-to:references:date:message-id:subject:from:to
         :content-type:x-original-sender:x-original-authentication-results
         :reply-to:precedence:mailing-list:list-id:x-spam-checked-in-group
         :list-post:list-help:list-archive:list-subscribe:list-unsubscribe;
        bh=2qbdV6FCdf1dAjpUm4p296UALTWkVmCv5NOs8dijdNk=;
        b=DYafqVbp52/eI5VTXX4AXNt+Mgnw/tSx2nKAKV8oHqaySP29+CbrLPxbX/ZdFzHcYc
         PkIIAKbD/osP9/bLYUpNVQF1J4QvJ/aWQ7TZfOXZ4oCK0h8vyaB45LSZCBL0fLe3BcZP
         lGkhDI5rkUd2EwOLASbK8/SuJg4WuTzVu6CKQ1iCqVOgaY1fJSNR6IN4ZQtCWiYVhhi0
         AnLRU9V9/z1yd6tDTyyjArVPJtzSe/m9bjv/lSLQSoo+ROi1oFv2E1Vht12ATX2uwsb8
         W0vHLhZb83ZZ/JQI+Guol2a/L+ZlxGtz8PLa43dXeXvC7WWAuBt7uCWpBe6EObpvrdBz
         jAiw==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20130820;
        h=x-gm-message-state:mime-version:in-reply-to:references:date
         :message-id:subject:from:to:content-type:x-original-sender
         :x-original-authentication-results:reply-to:precedence:mailing-list
         :list-id:x-spam-checked-in-group:list-post:list-help:list-archive
         :list-subscribe:list-unsubscribe;
        bh=2qbdV6FCdf1dAjpUm4p296UALTWkVmCv5NOs8dijdNk=;
        b=WgL3HZh0/uQ+fQo0XFhohPjRFHWpMS7TcTIdBVq7l6noThNuj9JUSI74DuIQLnTpyZ
         Xh6UBfX1wJ9vprdQp9Zsg6NP2ZZEVxVXsKMbyrcXGwc9p87fNzNGoFkgFVkf6PH4Rwyh
         tPYsHDKfVSTsJOhbeNP8+e5Tb0Axiof+MPNskZQj1i6ulgY4T8DxwDFOTNAYt+ioDiC6
         SNR6u7lM+aCW6N5/Eg6vgiNB+O3T8QGM2PXgQ06iJJDbPnEBNXJey3sU0EXqZewjNoFV
         Os7vAEktjE9ugnawC6lMxT4hGkFoxlcjSjtpNORrUi50ElfT8Kp1Nli43E7uh5Eph+Hh
         cVEQ==
X-Gm-Message-State: ALoCoQnch0Xn4g0K9DYU8SeB7jVxnfxL8yp181ATlINaUlBiVl/1d6+E9/CRUo/1R87sH0FzfMyG
X-Received: by 10.194.176.2 with SMTP id ce2mr1254371wjc.0.1447232516544;
        Wed, 11 Nov 2015 01:01:56 -0800 (PST)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.28.170.10 with SMTP id t10ls1278362wme.8.canary; Wed, 11 Nov
 2015 01:01:55 -0800 (PST)
X-Received: by 10.194.202.163 with SMTP id kj3mr9846324wjc.93.1447232515560;
        Wed, 11 Nov 2015 01:01:55 -0800 (PST)
Original-Received: from mail-wm0-x235.google.com (mail-wm0-x235.google.com. [2a00:1450:400c:c09::235])
        by mx.google.com with ESMTPS id g9si29760926wmd.73.2015.11.11.01.01.55
        for <std-proposals@isocpp.org>
        (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);
        Wed, 11 Nov 2015 01:01:55 -0800 (PST)
Received-SPF: pass (google.com: domain of daniel.kruegler@gmail.com designates 2a00:1450:400c:c09::235 as permitted sender) client-ip=2a00:1450:400c:c09::235;
Original-Received: by wmec201 with SMTP id c201so37389814wme.1
        for <std-proposals@isocpp.org>; Wed, 11 Nov 2015 01:01:55 -0800 (PST)
X-Received: by 10.194.171.69 with SMTP id as5mr8804854wjc.137.1447232515152;
 Wed, 11 Nov 2015 01:01:55 -0800 (PST)
Original-Received: by 10.28.18.129 with HTTP; Wed, 11 Nov 2015 01:01:55 -0800 (PST)
In-Reply-To: <14fb89ea-443b-4696-93ec-29889f642bca@isocpp.org>
X-Original-Sender: daniel.kruegler@gmail.com
X-Original-Authentication-Results: mx.google.com;       spf=pass (google.com:
 domain of daniel.kruegler@gmail.com designates 2a00:1450:400c:c09::235 as
 permitted sender) smtp.mailfrom=daniel.kruegler@gmail.com;       dkim=pass
 header.i=@gmail.com;       dmarc=pass (p=NONE dis=NONE) header.from=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:22436
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/22436>

2015-11-11 9:52 GMT+01:00  <leni536@gmail.com>:
> Hi,
>
> I didn't find a topic like this, so here it is. Something like this would be
> nice:
>
> template <class... Args>
> vector(size_type n,Args&&... args);
>
> It would perfect forward args to value_type's constructor. Since vector uses
> its allocator to construct, and in C++11 std::allocator already has a
> perfect forwarding "construct" member function, it could use that. The only
> problem I see that it would hijack other constructors so maybe it would need
> tag dispatching to work.
>
> vector(size_type n,vector::perfect_forward_type,Args&&... args);
>
> I see that this is a bit uglier, but at least it would work.

I consider the combination of "perfect forwarding" and the additional
size information as a potential dangerous combination. If a
constructor with size information would get any rvalues via args, the
first vector element construction might move the arguments into the
target and the second, third, etc. vector element constructed from the
same argument pack would try to become constructed from already moved
arguments. For exactly this reason any existing container member
function that provides a size information and a "prototype" value
expects that value as const value_type& and not as a potentially
movable argument.

- Daniel

-- 

--- 
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 email 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-proposals/.

.
