220 35153 <b59f31eb-2efa-71ed-5b9b-460dcf3741d3@gmail.com> article
Path: news.gmane.org!.POSTED!not-for-mail
From: =?UTF-8?Q?Jonathan_M=c3=bcller?= <jonathanmueller.dev@gmail.com>
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Re: Re: Add .emplace() method to std::unique_ptr and
 std::shared_ptr like it is in std::optional.
Date: Mon, 30 Oct 2017 20:07:45 +0100
Lines: 64
Approved: news@gmane.org
Message-ID: <b59f31eb-2efa-71ed-5b9b-460dcf3741d3@gmail.com>
References: <58eb77f6-2c2d-4ec1-85f8-08dcfe25a23e@isocpp.org>
 <db8aed18-d3b3-4df6-8e15-15f8c50e4bed@isocpp.org>
 <CAGg_6+MhHrsgMcAsqr_BiQu584PzypU+GMaRsPuo8XQ7V4RdoA@mail.gmail.com>
 <ebeab15d-5424-034b-7d86-b84b381a1977@gmail.com>
 <8d668562-154e-4d26-9605-2973bb78f699@isocpp.org>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: blaine.gmane.org
Mime-Version: 1.0
Content-Type: text/plain; charset="UTF-8"; format=flowed
X-Trace: blaine.gmane.org 1509390467 23247 195.159.176.226 (30 Oct 2017 19:07:47 GMT)
X-Complaints-To: usenet@blaine.gmane.org
NNTP-Posting-Date: Mon, 30 Oct 2017 19:07:47 +0000 (UTC)
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101
 Thunderbird/52.4.0
To: std-proposals@isocpp.org
Original-X-From: std-proposals+bncBCUMHC4Z6QGBBA7R3XHQKGQEFF6ERUQ@isocpp.org Mon Oct 30 20:07:43 2017
Return-path: <std-proposals+bncBCUMHC4Z6QGBBA7R3XHQKGQEFF6ERUQ@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-wm0-f69.google.com ([74.125.82.69])
	by blaine.gmane.org with esmtp (Exim 4.84_2)
	(envelope-from <std-proposals+bncBCUMHC4Z6QGBBA7R3XHQKGQEFF6ERUQ@isocpp.org>)
	id 1e9FPQ-0005JF-S5
	for gclcip-std-proposals@m.gmane.org; Mon, 30 Oct 2017 20:07:40 +0100
Original-Received: by mail-wm0-f69.google.com with SMTP id q127sf6599228wmd.1
        for <gclcip-std-proposals@m.gmane.org>; Mon, 30 Oct 2017 12:07:48 -0700 (PDT)
ARC-Seal: i=2; a=rsa-sha256; t=1509390468; cv=pass;
        d=google.com; s=arc-20160816;
        b=XjeEdltdFksCBf45wnLnTyjf2wvK59h3W0G867xBNl1792/yQ792W65yz5npCZB84G
         k5iK8UHi0MhpRkjkqmICgFcZXGyRcxllIdJ+ys+wrIvASpnpF/jVvupjuG2LXPwTNP5O
         Fg0TVCDndqGsykw1QiAznSsQvuChwaXwh2BpFqXi1uuamFj3yyhjZ+/WGxYogwP0Nqmv
         qhddc9+u53YrwbWVBDSJrpsveq2Akds7nAZ2jDUBHn9inhmW+Ql4v+/6M6mmYaZ9Ljla
         fExaygx3UlGu3qYhtBfYqeA6uKg+dI1vHnf/TsZPt8BQJ9miAaBLGNXgeHo4o7X/ZWl2
         cr6g==
ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816;
        h=list-unsubscribe:list-subscribe:list-archive:list-help:list-post
         :list-id:mailing-list:precedence:reply-to:content-language
         :in-reply-to:mime-version:user-agent:date:message-id:from:references
         :to:subject:arc-authentication-results:arc-message-signature
         :dkim-signature:arc-authentication-results;
        bh=P5UeGXhhYTl2Lwf5talHl0y6d/+wZM382dYPs3/LJu4=;
        b=yKJrPDkUm7EC97DdNj0clCGlb1kvYze4fDRbPFyCn54kBtK/PGBBSYqpOwFE5PsuQ6
         mP+Se2+mM+2HllD32TWLSb9DA11GS6QCARvRkcTTMkI1mjSB6CETEyZNUH9v3EsyNMD7
         eshQj3hB/u4SDW4OAOWtN0kBm01iyeLG61V20BhKfiZBvBu/U8Yg7QUWAKba9imIe0lV
         14eM1/KhCZdJFc7sc4kmH9Evp/Te7BTCSCfJu8K44KuVOuqEGnLWY2DbtPrlHRUJQK92
         iEjBkCbedsj9Nu0ZOTmCGUbZkPGpYNjsxLuEaG6jzTB9i0aiafFYDQQpXZwILhSAKQkc
         776Q==
ARC-Authentication-Results: i=2; mx.google.com;
       dkim=pass header.i=@gmail.com header.s=20161025 header.b=uhMSFA/V;
       spf=pass (google.com: domain of jonathanmueller.dev@gmail.com designates 209.85.220.41 as permitted sender) smtp.mailfrom=jonathanmueller.dev@gmail.com;
       dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gmail.com
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=isocpp-org.20150623.gappssmtp.com; s=20150623;
        h=subject:to:references:from:message-id:date:user-agent:mime-version
         :in-reply-to:content-language:x-original-sender
         :x-original-authentication-results:reply-to:precedence:mailing-list
         :list-id:list-post:list-help:list-archive:list-subscribe
         :list-unsubscribe;
        bh=P5UeGXhhYTl2Lwf5talHl0y6d/+wZM382dYPs3/LJu4=;
        b=NT8WvfCPbFLy+1+zOXvyR22295+RcsWNE10J7k0kxWs9iPs4lmh+l/zkxHcJaziFjW
         RzsKREJBe5gqz+KTCwkIjJjWPYyhymdJhvCpb+H+NkuvolOy47Emj2JVGqHOEA2CRgNy
         vBUikz/XpkiN/4bFgJSpymkXCGUbEkojFVGkpb1+4VgzH0Pr7XD8pxbEkrQkgKUWSmOC
         H8g30J33OzEIBH+cvos67nEfJsJavyK72D2r58x3GXtKBkKwHgKGY6rqOSz6VFbnCXQv
         KC2g0JUr5dnTET3A4MJqbqtSJjdgWvhke0iup9NXoSL2os5CG73ZESXUcoZmu2zKspri
         tU7g==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20161025;
        h=x-gm-message-state:subject:to:references:from:message-id:date
         :user-agent:mime-version:in-reply-to:content-language
         :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=P5UeGXhhYTl2Lwf5talHl0y6d/+wZM382dYPs3/LJu4=;
        b=bMEYlcuCHWJCDG1EUUuICyHeXvaPdqIVWK58FrRy9MaGRgITjMKv70d7pJpzeuci0/
         uCzIg5MJ8WcyR/EqCVAoPa+19kNYO2biPjst/u9gf+hE5j/1sucdVLdtILRz73g/m/QL
         7uLP6INQvDMhP4ySa32nYSeDVNXkFIW55mYkAeEn6miAp7dWsflbAGrrwYLz6y3gG4rk
         XOuI5t2QUUXlyQqDhIjUvtDYlsKGImqOQcbLknOkaUonlPPBXk3BhJaOXoPRFoQNZQyC
         DjagKo3UZNcUL1vgRlQOxUnpuNaiGnRtHJD50VKU5ah9lWiviElgnPMjqo0XbqJ3yQW1
         B 
X-Gm-Message-State: AMCzsaWO1spk7roX+erPQD4kzrMfGp9bgxlotdV1ZTFCWvtw5FyLVGCR
	vA8oUPZCrLGicfnpHhKdwWH1BA==
X-Google-Smtp-Source: ABhQp+Rl1agY3qRhukKojLTMspcVkbMB94r/Qp2yJHJbodw/0Wtc3kzY9UERWQWQQjJ+dAwo11WTMw==
X-Received: by 10.80.201.74 with SMTP id p10mr403832edh.7.1509390468564;
        Mon, 30 Oct 2017 12:07:48 -0700 (PDT)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.80.241.28 with SMTP id w28ls6825361edl.6.gmail; Mon, 30 Oct
 2017 12:07:47 -0700 (PDT)
X-Received: by 10.80.243.21 with SMTP id p21mr12986831edm.38.1509390467651;
        Mon, 30 Oct 2017 12:07:47 -0700 (PDT)
ARC-Seal: i=1; a=rsa-sha256; t=1509390467; cv=none;
        d=google.com; s=arc-20160816;
        b=G0Xuqbs4pqDzJB/nEXl/yiNNOY4UAuCPURvbN5TMbGYqpeDf255mnoWAJ5KEzwUEgf
         zn14qbNVL5I4BdMf+p3pv9jyw1W83HWx2GgDXY0W6yEp/qSnvnbPFT2y3f1GlXYZU/RG
         hg1oo7oTY0equaU3g/8+Z2fg63cdJH0mNuf7HENZ89AY1lU/Qd8fbW2Rernpk2V7Gnys
         yDuXe5G46ggiv6d8DJ9pmzqBbUwfK9zYHoK3hmeL/uG/aaVsZqrfvF84LQ3gxhhcDMo9
         +h1UpqvkVKQvd8RFPCrlQKIKiT7pqe+7mtZb2TL1jBJJiQzG0bCyh1vQgXQK80sDWenL
         DlYg==
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816;
        h=content-transfer-encoding:content-language:in-reply-to:mime-version
         :user-agent:date:message-id:from:references:to:subject
         :dkim-signature:arc-authentication-results;
        bh=OfMCSri2FHMtnWeGLydwQkkq0FR7RHvI4G7kO2Vjq/4=;
        b=UXP4/neE3JbXoN4Bl5+8VXZTD2/z2k45RynBwwupB4Ku+1zyljcMsjC+ow/U00/C4U
         O5gToKiUrIL21Bcc8cNjx2aVf+frchRppm2dJECdpyx6CBeLUdKNND5i8O/USVVvxnxf
         jpNdJvhfSOjyZvXHZ8vfRpL9hB2lWYY9r8ZkUwmjA1K9PXfRmOan+wbDgivMkzaNZZpQ
         cjejeDTBIYNVJHt+Xy6V/ozGwTxzlOJ2L8txCsHe1gg+sC05bNv5zytmOtIfjvWnmJoj
         vOkgVGT83oTa9Uff1aGOsErIkOQBsfydMgBoS8ppLNgEoM67DFztOjg/mFqiJKcZ74BV
         Mcnw==
ARC-Authentication-Results: i=1; mx.google.com;
       dkim=pass header.i=@gmail.com header.s=20161025 header.b=uhMSFA/V;
       spf=pass (google.com: domain of jonathanmueller.dev@gmail.com designates 209.85.220.41 as permitted sender) smtp.mailfrom=jonathanmueller.dev@gmail.com;
       dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gmail.com
Original-Received: from mail-sor-f41.google.com (mail-sor-f41.google.com. [209.85.220.41])
        by mx.google.com with SMTPS id p26sor2068634eda.51.2017.10.30.12.07.47
        for <std-proposals@isocpp.org>
        (Google Transport Security);
        Mon, 30 Oct 2017 12:07:47 -0700 (PDT)
Received-SPF: pass (google.com: domain of jonathanmueller.dev@gmail.com designates 209.85.220.41 as permitted sender) client-ip=209.85.220.41;
X-Received: by 10.80.153.102 with SMTP id l35mr13046481edb.183.1509390467095;
        Mon, 30 Oct 2017 12:07:47 -0700 (PDT)
Original-Received: from [192.168.1.98] (dslb-084-060-195-012.084.060.pools.vodafone-ip.de. [84.60.195.12])
        by smtp.gmail.com with ESMTPSA id d3sm9776402edd.41.2017.10.30.12.07.46
        for <std-proposals@isocpp.org>
        (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);
        Mon, 30 Oct 2017 12:07:46 -0700 (PDT)
In-Reply-To: <8d668562-154e-4d26-9605-2973bb78f699@isocpp.org>
Content-Language: en-US
X-Original-Sender: jonathanmueller.dev@gmail.com
X-Original-Authentication-Results: mx.google.com;       dkim=pass
 header.i=@gmail.com header.s=20161025 header.b=uhMSFA/V;       spf=pass
 (google.com: domain of jonathanmueller.dev@gmail.com designates 209.85.220.41
 as permitted sender) smtp.mailfrom=jonathanmueller.dev@gmail.com;
       dmarc=pass (p=NONE sp=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-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:35153
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/35153>

On 30.10.2017 20:01, antanubis@gmail.com wrote:
>  > The smart pointers and optional behave very differently: optional has
> value semantics, so it makes sense to say "create a new object".
> I don't think it makes sense to ask the same from unique_ptr.
> 
> In my experience unique_ptr is quite similar to optional.
> It is like an optional that doesn't hold the memory while there is no 
> value in it and that works nicely with forward declarations.

But they're not. optional has a copy constructor, deep comparison etc.
It just has a similar syntax because (for some reason) it was modelled 
after a pointer.

> 
>  > If we have `emplace()` what about a constructor of the same form?
> Yes, there's make_XXX but with class template argument deduction we
> don't really want make_XXX anymore.
> 
> As I understand the smart pointer make_* methods won't go anywhere after 
> the template argument deduction comes in to play because they're not a 
> helper functions for existing constructors of smart pointers. They can 
> replace "make_unique<T>(args)" with "unique_ptr(new T(args))" with 
> returning naked new to the common pattern (which is not looking good) 
> and they can't replace make_shared at all because of optimized storage 
> used in make_shared compared to "shared_ptr(new T(args))".
> 
> If we have emplace() in smart pointers perhaps we also would like to 
> have in_place constructors for smart pointers similar to optional 
> constructors with std::in_place. Those constructors would improve the 
> usage of member initialization of smart pointer fields while emplace 
> improves the usage of assigning of smart pointer variables. This will 
> allow us to use "A::A() : p(in_place, args)" instead of "A::A() : 
> p(make_unique<T>(args))" and "p.emplace(args)" instead of "p = 
> make_unique<T>(args)".
> 

This in place constructor is exactly what I meant there.
My comment is meant to be read as "will you also propose an in-place 
constructor?"

>  > If `ptr.emplace(obj)` works, what about `ptr = obj`? If you say no to
> assignment because it doesn't make sense, why allow emplace?
> 
> object.emplace(value) doesn't always say "assign this value to that 
> object" even with exactly one argument. For example std::set<T> has 
> .emplace(value), but it doesn't allow assigning this value to it. 
> emplace() methods in all standard classes say something like "create a 
> new object from all those arguments and put it inside" and it works 
> perfectly for both shared_ptr and unique_ptr.

It doesn't mean that but should you also add a corresponding `operator=`?

---

I think you are trying to turn smart pointers into indirect<T>, which is 
already proposed: 
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2016/p0201r1.pdf

-- 
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/b59f31eb-2efa-71ed-5b9b-460dcf3741d3%40gmail.com.

.
