220 35136 <db8aed18-d3b3-4df6-8e15-15f8c50e4bed@isocpp.org> article
Path: news.gmane.org!.POSTED!not-for-mail
From: antanubis@gmail.com
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Re: Add .emplace() method to std::unique_ptr and
 std::shared_ptr like it is in std::optional.
Date: Mon, 30 Oct 2017 09:05:15 -0700 (PDT)
Lines: 101
Approved: news@gmane.org
Message-ID: <db8aed18-d3b3-4df6-8e15-15f8c50e4bed@isocpp.org>
References: <58eb77f6-2c2d-4ec1-85f8-08dcfe25a23e@isocpp.org>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: blaine.gmane.org
Mime-Version: 1.0
Content-Type: multipart/mixed; 
	boundary="----=_Part_6589_877696603.1509379515759"
X-Trace: blaine.gmane.org 1509379526 4541 195.159.176.226 (30 Oct 2017 16:05:26 GMT)
X-Complaints-To: usenet@blaine.gmane.org
NNTP-Posting-Date: Mon, 30 Oct 2017 16:05:26 +0000 (UTC)
Cc: antanubis@gmail.com
To: ISO C++ Standard - Future Proposals <std-proposals@isocpp.org>
Original-X-From: std-proposals+bncBCJLPT5ZVQHBBPE33XHQKGQEPAI6AAI@isocpp.org Mon Oct 30 17:05:19 2017
Return-path: <std-proposals+bncBCJLPT5ZVQHBBPE33XHQKGQEPAI6AAI@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-ua0-f199.google.com ([209.85.217.199])
	by blaine.gmane.org with esmtp (Exim 4.84_2)
	(envelope-from <std-proposals+bncBCJLPT5ZVQHBBPE33XHQKGQEPAI6AAI@isocpp.org>)
	id 1e9CYo-00004y-CS
	for gclcip-std-proposals@m.gmane.org; Mon, 30 Oct 2017 17:05:10 +0100
Original-Received: by mail-ua0-f199.google.com with SMTP id b11sf10037680uae.0
        for <gclcip-std-proposals@m.gmane.org>; Mon, 30 Oct 2017 09:05:18 -0700 (PDT)
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:x-original-sender:reply-to:precedence:mailing-list
         :list-id:list-post:list-help:list-archive:list-subscribe
         :list-unsubscribe;
        bh=wFxWaElvaJgLHaGz2Kh0yOs6X3C5XoSL5r7sdkh89Oc=;
        b=YIbQv3D+oM/35T+q2r79+JsiliD9qHhRDLP8Wvcj1kyRDORTneeeOEPY7pZ1LLmbAF
         nCJrcGMKixRbkjiOI1Gwc59s3Pkx6F6W8NIE2r7mdJe3zYkzxfxoIFlR0ResjdMByDOu
         fJ7jReKoYdFs0xUDyd/AUdXKnly5UygTlZ4T2SwTv8r/lcYWHtaGjow497kUNxUMi0DY
         1q/rCvg3jV6/t09u3A7jWL7Mwchg6cldfEFGnw2MOsG+qmSWh6R7cwJQmlSjLgHrNk4Y
         6tHRP+jm/aTpN5dYKoxWvfqY/5lEFlc1Hy/Ba37V1NCDGC9hctHmJuBJ70fLZ0WMYyEh
         O4Zw==
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20161025;
        h=date:from:to:cc:message-id:in-reply-to:references:subject
         :mime-version:x-original-sender:reply-to:precedence:mailing-list
         :list-id:list-post:list-help:list-archive:list-subscribe
         :list-unsubscribe;
        bh=wFxWaElvaJgLHaGz2Kh0yOs6X3C5XoSL5r7sdkh89Oc=;
        b=WT1+HmcBgTh+SDlIJ7ZcPVx6z1lldZxaEOQoxgM5zv1cEeapTFgOJq/jzBzCwmkmVU
         bv9iK2v4tUUuOgjpsRScWN6aDgMmY/8dbJcpBQjl6w9q5qJfgi5gU0BmdZo4Tchkobqs
         eEmdq4sqoU8IVqzwV0h8CTekx4lf+NauJswAFmZzPrX282PRxaJf+lMfh1ui4ku/i9ig
         iwDOISC7V6GJ0X8VbPGgDFU1GG180W6Vrk+JZOShYmKphDH2RBp61DxKgbo3QKrVFN2q
         T3VwWfsXaeNgUOmNOwmWh6azmRhh00sjABuBK/i3FILCOH7rvedotQA7SpGyGjDPDNfc
         brog==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20161025;
        h=x-gm-message-state:date:from:to:cc:message-id:in-reply-to
         :references:subject:mime-version: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=wFxWaElvaJgLHaGz2Kh0yOs6X3C5XoSL5r7sdkh89Oc=;
        b=VkI/HxmbO0j8f/eCO4btuoRCoyygRV+x87kbaK9tYi5ALkcrCfYzM1JeHlGT5qeN3S
         wjX87zAxbadEOouQqAGiYVCSMu9kTOBXEKR5RhAGHxaRd6nDOdf0nY5hJITkDjvVRfrn
         5kEgXcku43OgWxEJaHgVYuoWIM307oU3S+XFnKWBU6iq+UEbBqJFHTffnpELQXJeX86i
         TOSOJGwN5fDQPypu7+hvA8mMgbqbvugdDsDoOUjdk1vWvRsaXhf9ISKW9rAwSxuJExC9
         SxXFxo6YQiQWuZv73PhLg/FwSM3IebLQ+OlPGSW4SKrNHE3JSihhsKuhXHZNUHpq+rA8
         iAIw==
X-Gm-Message-State: AMCzsaV95SGNgWK0CaP6Dx/UAx8jCmUegupmTtmFLJhPON9biCKMydIr
	5LPpENNxUxYU8ZjCHgScL0L2VA==
X-Google-Smtp-Source: ABhQp+Tp206ynkHclfBMdhNLfTJQADaO9g1oy68Tqtq5gWZakMhz6aOtY9cs5cwRjpYThFpJ3eBtxw==
X-Received: by 10.31.137.131 with SMTP id l125mr8725179vkd.98.1509379517638;
        Mon, 30 Oct 2017 09:05:17 -0700 (PDT)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.159.53.238 with SMTP id u43ls4296849uad.11.gmail; Mon, 30 Oct
 2017 09:05:16 -0700 (PDT)
X-Received: by 10.31.142.13 with SMTP id q13mr1655480vkd.1.1509379516173;
        Mon, 30 Oct 2017 09:05:16 -0700 (PDT)
In-Reply-To: <58eb77f6-2c2d-4ec1-85f8-08dcfe25a23e@isocpp.org>
X-Original-Sender: antanubis@gmail.com
Precedence: list
Mailing-list: list std-proposals@isocpp.org; contact std-proposals+owners@isocpp.org
List-ID: <std-proposals.isocpp.org>
X-Google-Group-Id: 399137483710
List-Post: <https://groups.google.com/a/isocpp.org/group/std-proposals/post>, <mailto:std-proposals@isocpp.org>
List-Help: <https://support.google.com/a/isocpp.org/bin/topic.py?topic=25838>, <mailto:std-proposals+help@isocpp.org>
List-Archive: <https://groups.google.com/a/isocpp.org/group/std-proposals/>
List-Subscribe: <https://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>,
 <https://groups.google.com/a/isocpp.org/group/std-proposals/subscribe>
Xref: news.gmane.org gmane.comp.lang.c++.isocpp.proposals:35136
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/35136>

------=_Part_6589_877696603.1509379515759
Content-Type: multipart/alternative; 
	boundary="----=_Part_6590_1388151577.1509379515759"

------=_Part_6590_1388151577.1509379515759
Content-Type: text/plain; charset="UTF-8"

Perhaps being a nice substitution for "= make_...<T>(...)" the return type 
should be the reference to smart pointer and the return value should be 
*this.

On Monday, October 30, 2017 at 8:01:25 PM UTC+4, anta...@gmail.com wrote:
>
> I've found really helpful in my own smart pointer classes to have 
> something like .create(Args &&..args) method that creates an object for an 
> owning shared pointer without the necessity for repeating the type in the 
> make_* non-member function.
>
> It's a shame that standard smart pointers don't have such method, so in 
> order to create a value you always need to repeat the type name, while it 
> is contained in the pointer type itself.
>
> After that I realized, that std::optional<> has such method named 
> .emplace() together with a free function make_optional<>. In some way 
> std::optional<> is a lot like "in-place std::unique_ptr<>" with 
> deep-copying by default.
>
> So I thought that proposing a member function "ptr.emplace(Args&&... 
> args)" for both std::unique_ptr and std::shared_ptr will be a really good 
> idea, it will also fit well with std::optional. The naive (but working) 
> implementation would be just:
>
> void(?) unique_ptr<T>::emplace(Args &&... args) { *this = 
> make_unique<T>(std::forward<Args>(args)...); }
> void(?) shared_ptr<T>::emplace(Args &&... args) { *this = 
> make_shared<T>(std::forward<Args>(args)...); }
>
> What do you think? Are there reasons not to add such methods? Or was this 
> discussed / proposed already?
>
> Vasilii Babich.
>

-- 
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.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/db8aed18-d3b3-4df6-8e15-15f8c50e4bed%40isocpp.org.

------=_Part_6590_1388151577.1509379515759
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">Perhaps being a nice substitution for &quot;=3D make_...&l=
t;T&gt;(...)&quot; the return type should be the reference to smart pointer=
 and the return value should be *this.<br><br>On Monday, October 30, 2017 a=
t 8:01:25 PM UTC+4, anta...@gmail.com wrote:<blockquote class=3D"gmail_quot=
e" style=3D"margin: 0;margin-left: 0.8ex;border-left: 1px #ccc solid;paddin=
g-left: 1ex;"><div dir=3D"ltr"><div>I&#39;ve found really helpful in my own=
 smart pointer classes to have something like .create(Args &amp;&amp;..args=
) method that creates an object for an owning shared pointer without the ne=
cessity for repeating the type in the make_* non-member function.</div><div=
><br></div><div>It&#39;s a shame that standard smart pointers don&#39;t hav=
e such method, so in order to create a value you always need to repeat the =
type name, while it is contained in the pointer type itself.</div><div><br>=
</div><div>After that I realized, that std::optional&lt;&gt; has such metho=
d named .emplace() together with a free function make_optional&lt;&gt;. In =
some way std::optional&lt;&gt; is a lot like &quot;in-place std::unique_ptr=
&lt;&gt;&quot; with deep-copying by default.</div><div><br></div><div>So I =
thought that proposing a member function &quot;ptr.emplace(Args&amp;&amp;..=
.. args)&quot; for both std::unique_ptr and std::shared_ptr will be a really=
 good idea, it will also fit well with std::optional. The naive (but workin=
g) implementation would be just:</div><div><br></div><div>void(?) unique_pt=
r&lt;T&gt;::emplace(Args &amp;&amp;... args) { *this =3D make_unique&lt;T&g=
t;(std::forward&lt;<wbr>Args&gt;(args)...); }</div><div>void(?) shared_ptr&=
lt;T&gt;::emplace(Args &amp;&amp;... args) { *this =3D make_shared&lt;T&gt;=
(std::forward&lt;<wbr>Args&gt;(args)...); }</div><div><br></div><div>What d=
o you think? Are there reasons not to add such methods? Or was this discuss=
ed / proposed already?</div><div><br></div><div>Vasilii Babich.</div></div>=
</blockquote></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/db8aed18-d3b3-4df6-8e15-15f8c50e4bed%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/db8aed18-d3b3-4df6-8e15-15f8c50e4bed=
%40isocpp.org</a>.<br />

------=_Part_6590_1388151577.1509379515759--

------=_Part_6589_877696603.1509379515759--

.
