220 22449 <n1vjll$vbh$1@ger.gmane.org> article
Path: news.gmane.org!not-for-mail
From: Matthew Woehlke <mwoehlke.floss@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:34:28 -0500
Lines: 48
Approved: news@gmane.org
Message-ID: <n1vjll$vbh$1@ger.gmane.org>
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 1447252663 3778 80.91.229.3 (11 Nov 2015 14:37:43 GMT)
X-Complaints-To: usenet@ger.gmane.org
NNTP-Posting-Date: Wed, 11 Nov 2015 14:37:43 +0000 (UTC)
To: std-proposals@isocpp.org
Original-X-From: std-proposals+bncBC37LBFWUIFBB5NERWZAKGQENKOSJ4Q@isocpp.org Wed Nov 11 15:37:35 2015
Return-path: <std-proposals+bncBC37LBFWUIFBB5NERWZAKGQENKOSJ4Q@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-lf0-f70.google.com ([209.85.215.70])
	by plane.gmane.org with esmtp (Exim 4.69)
	(envelope-from <std-proposals+bncBC37LBFWUIFBB5NERWZAKGQENKOSJ4Q@isocpp.org>)
	id 1ZwWW1-0007ZV-84
	for gclcip-std-proposals@m.gmane.org; Wed, 11 Nov 2015 15:36:49 +0100
Original-Received: by lfdo63 with SMTP id o63sf11493967lfd.2
        for <gclcip-std-proposals@m.gmane.org>; Wed, 11 Nov 2015 06:36:38 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=isocpp_org.20150623.gappssmtp.com; s=20150623;
        h=to:from:subject:date:lines:message-id:references:mime-version
         :content-type:user-agent:in-reply-to: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=1nhzKvCWIIiLhTn65/jD/l/Ewx8/1XhadyxjrpC/Aj4=;
        b=Y+5ETDfqhJP6I1SpcgR2kINVGvFdFv7Fy+w3IqG8K7x7sxAueoY6FAiSrSGMfu3616
         4snRmvA3Mk041AVJnZVWseQW+TnHOxB5gTUv099Pgucz3KVBvVyKV1DDFmVuUid/3Zh5
         jI6zw6KJiiQwIe3qy/A5zd6Qa8pORcFyAbVz9oKmwYJO37JT16NC2B/WhSBgOGPHRwGm
         T9PwkJYfMGlG54ZsU0dZx9LBhCMf0CfQodg/M4sbIhuxTUWq/7qmQIC2hDooz9U66tPC
         t+HQxCQDaccqBcxUI12CbhCJm4lNzsjVWxL9no8ocdejzyzY9Lbm8l174PatMn/ZX4Zc
         nJ3 
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20130820;
        h=x-gm-message-state:to:from:subject:date:lines:message-id:references
         :mime-version:content-type:user-agent:in-reply-to: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=1nhzKvCWIIiLhTn65/jD/l/Ewx8/1XhadyxjrpC/Aj4=;
        b=bZJXbpMP+7n5LlFdCg2XJ4NI5SQ5UiN1RJJC80h/pdN08AoUGbUY/Mt/SIH1KsV41u
         e5I0iZh6uJYUf153LBEaqIq0Sb3fC9wkrZzdcsPIE3u5SGFjZNu8XaWZWQZsLdw+tFJm
         QevK0gs6vb8anQtbXpMDt1mof/PKOTgU7U0SZB1pkzMGjgKRMFUz0NtOTLmrDx7+HvYr
         YwVucbvDbblPdAEuBP5y8H6HQrrdf2BJf8ipuhPRj3LRz9eDpVCo6TetXPi1IMt6+IKN
         N3hPKgnP0mafNby7lWYro639WGesyEM5hcLrenGfe5Gov+O61a17F84TwIW+7lzq3g//
         
X-Gm-Message-State: ALoCoQkLjx+uFodCG4qLpqN/i1+ewiMUXPlTVo26CLIvNYFsDSzBEgjLo56+OH336W8jLeFXJK+x
X-Received: by 10.112.209.73 with SMTP id mk9mr1490074lbc.14.1447252598524;
        Wed, 11 Nov 2015 06:36:38 -0800 (PST)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.25.211.77 with SMTP id k74ls711958lfg.53.gmail; Wed, 11 Nov
 2015 06:36:37 -0800 (PST)
X-Received: by 10.25.162.131 with SMTP id l125mr4608320lfe.70.1447252597125;
        Wed, 11 Nov 2015 06:36:37 -0800 (PST)
Original-Received: from plane.gmane.org (plane.gmane.org. [80.91.229.3])
        by mx.google.com with ESMTPS id 73si6291729lfr.2.2015.11.11.06.36.37
        for <std-proposals@isocpp.org>
        (version=TLSv1 cipher=RC4-SHA bits=128/128);
        Wed, 11 Nov 2015 06:36:37 -0800 (PST)
Received-SPF: pass (google.com: domain of gclcip-std-proposals@m.gmane.org designates 80.91.229.3 as permitted sender) client-ip=80.91.229.3;
Original-Received: from list by plane.gmane.org with local (Exim 4.69)
	(envelope-from <gclcip-std-proposals@m.gmane.org>)
	id 1ZwWUi-0006PW-FA
	for std-proposals@isocpp.org; Wed, 11 Nov 2015 15:35:28 +0100
Original-Received: from tripoint.kitware.com ([66.194.253.20])
        by main.gmane.org with esmtp (Gmexim 0.1 (Debian))
        id 1AlnuQ-0007hv-00
        for <std-proposals@isocpp.org>; Wed, 11 Nov 2015 15:35:28 +0100
Original-Received: from mwoehlke.floss by tripoint.kitware.com with local (Gmexim 0.1 (Debian))
        id 1AlnuQ-0007hv-00
        for <std-proposals@isocpp.org>; Wed, 11 Nov 2015 15:35:28 +0100
X-Injected-Via-Gmane: http://gmane.org/
Original-Lines: 39
Original-X-Complaints-To: usenet@ger.gmane.org
X-Gmane-NNTP-Posting-Host: tripoint.kitware.com
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.7.0
In-Reply-To: <14fb89ea-443b-4696-93ec-29889f642bca@isocpp.org>
X-Original-Sender: mwoehlke.floss@gmail.com
X-Original-Authentication-Results: mx.google.com;       spf=pass (google.com:
 domain of gclcip-std-proposals@m.gmane.org designates 80.91.229.3 as
 permitted sender) smtp.mailfrom=gclcip-std-proposals@m.gmane.org;
       dmarc=fail (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:22449
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/22449>

On 2015-11-11 03:52, leni536@gmail.com wrote:
> 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);
> 
> 1) It could be faster than vector(n,value_type(args)) if value_type's copy 
> constructor is more expensive than its constructor with "args" parameters 
> (I don't know a good example though).

Interesting idea. And since vector(n, value_type(...)) invokes
value_type's copy ctor, it is in fact a subset of the proposed syntax,
i.e. that form could be deprecated / removed in favor of the proposed
"emplace" version.

> 2) If value_type's different constructors are not deterministic then maybe 
> it's desirable to call the constructor multiple times instead of copying 
> one constructed element. One example if value_type has a constructor taking 
> a random generator as an argument.

Hmm... for this case, you are thinking that one of the arguments is e.g.
a functor? And that the value_type copy ctor copies existing data, while
the ctor taking the functor uses the functor (which isn't stored) to
generate a value? Interesting notion...

> Workarounds:
> 2) Construct an empty vector, use reserve then emplace_back newly 
> constructed elements one by one using value_type's constructor of choice. 
> I'm not sure if this would be equally efficient.

Seems like it should be at least comparably efficient; I can't think
offhand what vector's sized constructor would do differently that would
make it more efficient. (Assuming that a default-constructed data has
SOO or otherwise doesn't allocate storage that gets thrown out by the
reserve().)

-- 
Matthew

-- 

--- 
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/.

.
