220 29888 <20161217192812.GA17421@manuel-ThinkPad-L440.localdomain> article
Path: news.gmane.org!.POSTED!not-for-mail
From: Manuel Bergler <berglerma@gmail.com>
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Re: New smart pointer: CopyConstructible and
 CopyAssignable flavor of unique_ptr
Date: Sat, 17 Dec 2016 20:28:12 +0100
Lines: 103
Approved: news@gmane.org
Message-ID: <20161217192812.GA17421@manuel-ThinkPad-L440.localdomain>
References: <b1c473be-03c1-e4db-f0c4-a23f182c7154@gmail.com>
 <CAFk2RUYmdj2HwRpP2HhY=xujkFP1e5LYKkg6eOGBOF_yE-3Lcg@mail.gmail.com>
 <3df7e8eb-01a0-7804-f476-504b5a25a9fe@gmail.com>
 <CAFk2RUaY3+MnXkmvaC=LxgRA_RD_XQpFfX-HT6X3iq1wD7ggCg@mail.gmail.com>
 <20161217170428.GA10214@manuel-ThinkPad-L440.localdomain>
 <20161217171633.4919375.58072.21574@gmail.com>
 <CAEddoJaAZkeJS9Maj2z0vYGnfuNnJZ+qFFdjeQyesTF5itJxHA@mail.gmail.com>
 <15884364-3238-41c7-bc5a-aa5595a64ade@isocpp.org>
 <20161217182130.GA4347@manuel-ThinkPad-L440.localdomain>
 <5eae5f16-e129-4c95-8001-fc73cc4f3d03@isocpp.org>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: blaine.gmane.org
Mime-Version: 1.0
Content-Type: multipart/signed; micalg=pgp-sha256;
	protocol="application/pgp-signature"; boundary="UlVJffcvxoiEqYs2"
X-Trace: blaine.gmane.org 1482002946 14937 195.159.176.226 (17 Dec 2016 19:29:06 GMT)
X-Complaints-To: usenet@blaine.gmane.org
NNTP-Posting-Date: Sat, 17 Dec 2016 19:29:06 +0000 (UTC)
User-Agent: Mutt/1.5.24 (2015-08-30)
To: std-proposals@isocpp.org
Original-X-From: std-proposals+bncBDOZBAUFX4MRB7FD23BAKGQELIMDPIQ@isocpp.org Sat Dec 17 20:29:02 2016
Return-path: <std-proposals+bncBDOZBAUFX4MRB7FD23BAKGQELIMDPIQ@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-lf0-f72.google.com ([209.85.215.72])
	by blaine.gmane.org with esmtp (Exim 4.84_2)
	(envelope-from <std-proposals+bncBDOZBAUFX4MRB7FD23BAKGQELIMDPIQ@isocpp.org>)
	id 1cIKfA-0002YN-KP
	for gclcip-std-proposals@m.gmane.org; Sat, 17 Dec 2016 20:28:56 +0100
Original-Received: by mail-lf0-f72.google.com with SMTP id g12sf17250569lfe.5
        for <gclcip-std-proposals@m.gmane.org>; Sat, 17 Dec 2016 11:29:01 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=isocpp-org.20150623.gappssmtp.com; s=20150623;
        h=date:from:to:subject:message-id:references:mime-version
         :content-disposition:in-reply-to:user-agent: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=fVPvxbgE0Se3wzPbrqe4fZthoOw2nM1EIMBKWdJuApA=;
        b=r3cvCrGHT6ml+cR1jjHcT8C/cDWvuSA1pKlHQ+LKEYvWn20kozehW9jy3MmXavoqNs
         /QPPhWpW2kdZ9GAe/roFJorIJ2+9ODmSo2pQVsQNXDW8kGuGHKfaiJB5S7zuc+xP0Ey7
         MAi8jC9fwpt92jGrn1WocPLyJuCRVYdW3IbAnoOY5bLzMYb2MikbCq1C9Uc2Vcy4a06J
         5i4SSaZmLJnuwuuRoJPumGC4DTWJOCyj1OucmRzsW17yB9UCXgO7UNtFKtsRrkQrdTwS
         ckqKk3aRu8sl1sCFUDOBBtt9xph1i31OfIEVjsx+6p5oyPkQdQIpbG0B8Cqk1v+woaGH
         zq 
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:subject:message-id:references
         :mime-version:content-disposition:in-reply-to:user-agent
         :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=fVPvxbgE0Se3wzPbrqe4fZthoOw2nM1EIMBKWdJuApA=;
        b=kLw7N2/xpJRRO0bwbN2RjOpswFzqNy5x5PUlUziqYWkRseoSdwNNJyTdHTdKFBUUpq
         kusHhaoyZHe4rGQV4y1uDrg+pFENOEYdmBxGHo853YFct+Li5Wa3e3sfuIJhh4veEeuD
         bXTthjWI9W5OUUW0vo5VQUXXq4tHG1i+qFjmHluVuzJsFb/cDXA8EO1QnN8G68p86O/m
         bSJQUahj6c4kU65gMONoHDnwKRRjTTqSrZJfFb+qQMnOVIYix2pK2W7ru9lH4A6Qz559
         KMFVy7kzY03jQ1EGBZeolzr8PFvSqzyhlZA8i/6K4xfxE12GgqqwjhyDe6+9vyCoMeSF
        
X-Gm-Message-State: AIkVDXJ5Gde2zJMWALqf/wnVa+nD08XCs6boNqDPQzwi+ZLwx5c9ucpzKaFN0AA8fJ8Ksg==
X-Received: by 10.46.78.9 with SMTP id c9mr863140ljb.27.1482002941180;
        Sat, 17 Dec 2016 11:29:01 -0800 (PST)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.28.26.13 with SMTP id a13ls698934wma.17.gmail; Sat, 17 Dec
 2016 11:28:59 -0800 (PST)
X-Received: by 10.28.12.80 with SMTP id 77mr8404933wmm.106.1482002939863;
        Sat, 17 Dec 2016 11:28:59 -0800 (PST)
Original-Received: from mail-wj0-x243.google.com (mail-wj0-x243.google.com. [2a00:1450:400c:c01::243])
        by mx.google.com with ESMTPS id o76si8940850wmi.60.2016.12.17.11.28.59
        for <std-proposals@isocpp.org>
        (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);
        Sat, 17 Dec 2016 11:28:59 -0800 (PST)
Received-SPF: pass (google.com: domain of berglerma@gmail.com designates 2a00:1450:400c:c01::243 as permitted sender) client-ip=2a00:1450:400c:c01::243;
Original-Received: by mail-wj0-x243.google.com with SMTP id kp2so18618192wjc.0
        for <std-proposals@isocpp.org>; Sat, 17 Dec 2016 11:28:59 -0800 (PST)
X-Received: by 10.194.178.170 with SMTP id cz10mr7599143wjc.224.1482002939096;
        Sat, 17 Dec 2016 11:28:59 -0800 (PST)
Original-Received: from localhost (x5d856f73.dyn.telefonica.de. [93.133.111.115])
        by smtp.gmail.com with ESMTPSA id x188sm9249258wmx.4.2016.12.17.11.28.57
        for <std-proposals@isocpp.org>
        (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256);
        Sat, 17 Dec 2016 11:28:58 -0800 (PST)
Content-Disposition: inline
In-Reply-To: <5eae5f16-e129-4c95-8001-fc73cc4f3d03@isocpp.org>
X-Original-Sender: berglerma@gmail.com
X-Original-Authentication-Results: mx.google.com;       dkim=pass
 header.i=@gmail.com;       spf=pass (google.com: domain of
 berglerma@gmail.com designates 2a00:1450:400c:c01::243 as permitted sender)
 smtp.mailfrom=berglerma@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-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:29888
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/29888>


--UlVJffcvxoiEqYs2
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

On Sat, Dec 17, 2016 at 10:43:08AM -0800, Nicol Bolas wrote:
>   On Saturday, December 17, 2016 at 1:22:19 PM UTC-5, Manuel Bergler wrot=
e:
>
>     On Sat, Dec 17, 2016 at 10:04:47AM -0800, Nicol Bolas wrote:
>     >
>     > =C2=A0 After all, such copying behavior won't break most standard l=
ibrary
>     types.
>     > =C2=A0 `vector<clone_ptr>` will work as expected, as will `any`,
>     > =C2=A0 `optional<clone_ptr>`, `variant<clone_ptr>`, and so forth.
>     >
>
>     It would certainly work with the STL types, but I'm fairly certain yo=
u
>     might get very different results when using these in STL algorithms.
>     With some implementations references to the pointees might be preserv=
ed
>     since the algorithm doesn't copy the clone_ptr whereas others might
>     perform a copy, hence invalidating existing references or at least
>     having them point to a different object than the one returned from th=
e
>     algorithm.
>
>   Which is no different from passing a value type that gets copied, then
>   expecting the copies to be modifying the original value.
>   =C2=A0

It is different.

Consider for example something like

    my_obj =3D std::accumulate(input.begin(), input.end(), std::move(my_obj=
),
                             some_function);

Afterwards references to my_obj will still be valid and correctly point to =
the
modified object.

On the other hand, if you have

    auto f =3D [&someObj] (auto& acc, auto const& in) -> decltype(auto) {
        acc->doSomethingModifyingThePointeeObj(in);
        someObj.doSomething(acc)  // note I really want the cloning here
                                  // so I need to pass in the clone_ptr
                                  // and not the pointee
        return std::move(acc);
    };

    my_clone_ptr =3D std::accumulate(input.begin(), input.end(), std::move(=
my_clone_ptr), f);

now suddenly all references you got by calling `*my_clone_ptr` somewhen bef=
ore
might or might not be invalid, even though I moved the original clone_ptr i=
nto
the algorithm to ensure that it doesn't get copied.

I'm aware that this is somewhat of a silly example because you'd probably d=
o
this with a handwritten for-loop, but nevertheless it shows how hard it is =
to
use this type correctly with STL algorithms.

--=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.
To view this discussion on the web visit https://groups.google.com/a/isocpp=
..org/d/msgid/std-proposals/20161217192812.GA17421%40manuel-ThinkPad-L440.lo=
caldomain.

--UlVJffcvxoiEqYs2
Content-Type: application/pgp-signature; name="signature.asc"

-----BEGIN PGP SIGNATURE-----

iQIzBAEBCAAdFiEEi3F6I6jTgMCHgGvofAJ3kFaTK3oFAlhVkcoACgkQfAJ3kFaT
K3oo+BAAoDAp81yqVbaNaoy8ySmN+V/fQix8gv8e/InMd5a/+/HEkrtKn3PqRk9I
Y9PMlAJ7Eqa6JD5lk4lGaxhsH6+6/pe3REBI1xjEzEm/fjR0A4fYfGeGlPqKYwa/
nhjneYrggX2HHhaKdbPNnwrc9Q+IBiTkQBsie4r3cqzayo3Ast/TuGDEG3kB7/Sh
LBiIUJv6pcpMbB/oJSwjt2MW3B8UULgvEy9p7acdhhaYotRY5qqytdsblOTYDqmS
N2d9a6AOzjjI4tH5CHIMSei0j2uxvtZE86rFrhXphI5wKJvUFoPajSfgXMOjHw+7
O/rsggrHLzxaLbKoLhH+sAGun93h+MWGZCwjJlVGDOAAPNorLgjJ81nefTQtNzpk
1QOYKCN+L4SBUxGrVeLrbfOIAfmHJGmiug9+ECgisYwwH6PvDGk3D+TD6N6r2PiZ
dXhO98Z/g4sbWnsNOj1X+gMr4QQ1eP6TZHGHqazZiX/TtzVGAMzAmIJBBx9I35IL
1LRHJsfMH4NXLZc/uECLkAq04NsYP7G7gMMlzpWVybbJPlLn2uU8Wwbj58GJY6gh
cJtOMaJc+RJoJLDSssFAvC187bVc6ziH4a8+btPzZOgAJzGAbAAHGfYThloFG6tf
ZvjeQ5f2kW6qiJOqx1FjRABYUiEnkh4Twr9mUvmEQf4yYs7GIns=
=9trW
-----END PGP SIGNATURE-----

--UlVJffcvxoiEqYs2--

.
