220 29861 <731cb931-eb89-41e0-8c1b-bfccd6329eaa@isocpp.org> article
Path: news.gmane.org!.POSTED!not-for-mail
From: jgottman6@gmail.com
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Re: New smart pointer: CopyConstructible and
 CopyAssignable flavor of unique_ptr
Date: Fri, 16 Dec 2016 18:45:38 -0800 (PST)
Lines: 421
Approved: news@gmane.org
Message-ID: <731cb931-eb89-41e0-8c1b-bfccd6329eaa@isocpp.org>
References: <13702f32-32c2-447f-9996-3624fd678675@isocpp.org>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: blaine.gmane.org
Mime-Version: 1.0
Content-Type: multipart/mixed; 
	boundary="----=_Part_349_817252494.1481942738584"
X-Trace: blaine.gmane.org 1481942745 12761 195.159.176.226 (17 Dec 2016 02:45:45 GMT)
X-Complaints-To: usenet@blaine.gmane.org
NNTP-Posting-Date: Sat, 17 Dec 2016 02:45:45 +0000 (UTC)
To: ISO C++ Standard - Future Proposals <std-proposals@isocpp.org>
Original-X-From: std-proposals+bncBD7LHGWIQEPRBU6N2LBAKGQEJ6IPLVQ@isocpp.org Sat Dec 17 03:45:40 2016
Return-path: <std-proposals+bncBD7LHGWIQEPRBU6N2LBAKGQEJ6IPLVQ@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-pg0-f69.google.com ([74.125.83.69])
	by blaine.gmane.org with esmtp (Exim 4.84_2)
	(envelope-from <std-proposals+bncBD7LHGWIQEPRBU6N2LBAKGQEJ6IPLVQ@isocpp.org>)
	id 1cI50C-0001ox-A7
	for gclcip-std-proposals@m.gmane.org; Sat, 17 Dec 2016 03:45:37 +0100
Original-Received: by mail-pg0-f69.google.com with SMTP id 3sf233099331pgd.3
        for <gclcip-std-proposals@m.gmane.org>; Fri, 16 Dec 2016 18:45:40 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=isocpp-org.20150623.gappssmtp.com; s=20150623;
        h=date:from:to: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=zg0E8VH7RmoqRJsO7qiuScB3WQxppz3ISNlwF3Nb6WU=;
        b=cK7RCAIt4ZV2a6zT6lQf3I7hMjPEve59FQGF1EiwtwVKASUNXNpKPfidRUIIcVicuq
         DSF7vy35ndyeHEpgiQ9ELOJEKA7Uw2bLQ9j1xd5HwwFRblQ6xMhsqaYh6xkE4xwHjp+w
         k4uDfH4XBWPA7YvggLZdM3mt9ea4hDzx7RvkuQYcGdhubsIWUBsMlYOFtnANxpVj0asA
         ICy8Yjtl0eQSPCa87iudzxSNh+fM/f5taHtk6e+WzfXTVYP+U7YSaoxD3IA/X3cPzNKp
         hFgujtFCjMT4y3cXSLkhLBX4XdP/g9TnPG8I39CS+ztlU7CouJkkKiQYv8gwgxNBitQo
         MF1A==
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20161025;
        h=date:from:to: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=zg0E8VH7RmoqRJsO7qiuScB3WQxppz3ISNlwF3Nb6WU=;
        b=Bz5bl/Ll5KUhgraV7yZcjuBwBNT2hcRX7KjY7JmN4hwilJYl7IWlV6i7M1mq5wvIX9
         PQJWI9Ocjsha04YIgs1qF+blnc4/qKX2lh9Ufam7c54mN7izx1u+kt6H95upCFJ30CgB
         zOPJlCvqvroWTXcQR6acuvDrN8fI22WPYVENwx288jPyNvO6apErHa5QcrxdToCKRSZc
         lONZltpoOKYWDiqZaw6mFN465ct2P62r0vFWQCvHh1Jw8W3GkQDuOPM/aG5o7Bto/qBW
         GtyG/YGI4VICcE31s2oTQEORoO5mq8Y3bTFrS9VNUUwF+X40Jp0Uhev1QpVNajr/QY7V
         lJHQ==
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: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=zg0E8VH7RmoqRJsO7qiuScB3WQxppz3ISNlwF3Nb6WU=;
        b=Hmy3RJ8E5ClnnnP0mhnI9zZWrKkx/79Zas/ftOZx3vr2YFE9Fx36VD2VsGSW8CO0m8
         TCq0OPvzq3YXiLvN+koh4dDgNrdoyon154zW27mcfOYxPp2iHG2Cjjgm6g6GWJOr5m9b
         etht9zhAg9DDLii7f/STgtEEP9doi0nyJwTr8SsjX0+zCVEmWvyODhbPy9drCRcOmAo4
         P9FxIjFpOTzAeFV+mnDQZuQm2RAB+TudjkegABoWZ2p1OVH9yu5M/bwNn426aURmqeoe
         mEmJ1mo/13rtDF9p6jbSLp5k2hMgFX80WWXmfsC9tPgNFTptIUcMel+xDtHa0zYPNp8d
         orxQ==
X-Gm-Message-State: AKaTC03U++DoklpClOtGcnCxQKw/fg3GROfkJX3X9xRBaT6fDM6cbGw6c7xcx82WV42rZQ==
X-Received: by 10.99.124.13 with SMTP id x13mr2888203pgc.97.1481942739885;
        Fri, 16 Dec 2016 18:45:39 -0800 (PST)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.157.43.168 with SMTP id u37ls1983496ota.29.gmail; Fri, 16 Dec
 2016 18:45:39 -0800 (PST)
X-Received: by 10.157.45.49 with SMTP id v46mr283594ota.10.1481942739124;
        Fri, 16 Dec 2016 18:45:39 -0800 (PST)
In-Reply-To: <13702f32-32c2-447f-9996-3624fd678675@isocpp.org>
X-Original-Sender: jgottman6@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:29861
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/29861>

------=_Part_349_817252494.1481942738584
Content-Type: multipart/alternative; 
	boundary="----=_Part_350_483177092.1481942738585"

------=_Part_350_483177092.1481942738585
Content-Type: text/plain; charset=UTF-8

Please don't define any relational operators for this class. If the 
relational operators are defined to compare the contained pointers, then 
given the code

clone_ptr<int> foo(new int(7));
clone_ptr<int> bar = foo;
assert(foo == bar);


the assertion will fail.  This means that code using clone_ptr's in 
associative containers will compile but completely fail to work at runtime.

Joe Gottman


On Friday, December 16, 2016 at 6:32:25 AM UTC-5, Alexandre Isoard wrote:
>
> *Proposal*
>
> template<class T,
>     class Cloner = std::default_clone<T>,
>     class Deleter = std::default_delete 
> <http://en.cppreference.com/w/cpp/memory/default_delete><T>
> > class copy_ptr
>
> std::copy_ptr is a smart pointer that owns and manages another object 
> through a pointer and disposes of that object when the copy_ptr goes out 
> of scope.
> Additionally, it allocates a clone of the underlying object when it is 
> copied from, ensuring one copy_ptr manages each allocated object.
>
> The object is disposed of using the associated deleter when either of the 
> following happens:
>
>    - the managing copy_ptr object is destroyed
>    - the managing copy_ptr object is assigned another pointer via 
>    operator= 
>    <http://en.cppreference.com/w/cpp/memory/unique_ptr/operator%3D> or 
>    reset() <http://en.cppreference.com/w/cpp/memory/unique_ptr/reset>.
>
> The object is disposed of using a potentially user-supplied deleter by 
> calling get_deleter()(ptr). The default deleter uses the delete operator, 
> which destroys the object and deallocates the memory.
>
> The object is cloned using the associated cloner when either of the 
> following happens:
>
>    - an other copy_ptr object is copy constructed from the managing 
>    copy_ptr
>    - an other copy_ptr object is copy assigned from the managing copy_ptr
>
> The object is cloned using a potentially user-supplied cloner by calling 
> get_cloner()(ptr). The default cloner uses the new operator and the copy 
> constructor of the underlying type, which allocate a new object and copy 
> its original content.
>
> A copy_ptr may alternatively own no object, in which case it is called 
> empty.
>
> The class satisfies the requirements of MoveConstructible 
> <http://en.cppreference.com/w/cpp/concept/MoveConstructible>, 
> MoveAssignable <http://en.cppreference.com/w/cpp/concept/MoveAssignable>, 
> CopyConstructible 
> <http://en.cppreference.com/w/cpp/concept/CopyConstructible> and 
> CopyAssignable <http://en.cppreference.com/w/cpp/concept/CopyAssignable> (the 
> later two may require T to be CopyConstructible).
>
> *Member Types*
>
>    - pointer: T*
>    - element_type: T, the type of the object managed by this copy_ptr
>    - cloner_type: Cloner, the function object or lvalue reference to 
>    function or to function object, to be called from the copy constructor and 
>    copy assignment operators
>    - deleter_type: Deleter, the function object or lvalue reference to 
>    function or to function object, to be called from the destructor
>
>
> *Member Functions*
>
>    - operator=: assigns the copy_ptr
>    - release: returns a pointer to the managed object and releases 
>    ownership
>    - reset: replaces the managed object
>    - swap: swaps the managed objects
>    - get: returns a pointer to the managed object
>    - get_cloner: returns the cloner that is used for copy the managed 
>    object
>    - get_deleter: returns the deleter that is used for destruction of the 
>    managed object
>    - operator bool: checks if there is an associated managed object
>    - operator*, operator->: dereferences pointer to the managed object
>    - make_copy: creates a copy pointer that manages a new object
>    - operator==, operator!=, etc: compares to an other copy_ptr or with 
>    nullptr
>    - std::swap: specializes the std::swap algorithm
>    - std::hash<std::copy_ptr>: hash support for std::copy_ptr
>
> *Example*
>
> #include<iostream>
> #include<memory>
>
> struct Foo
> {
>     Foo()             { std::cout << "Foo::Foo()\n"; }
>     Foo(const Foo& o) { std::cout << "Foo::Foo(const Foo&)\n"; }
>     ~Foo()            { std::cout << "Foo::~Foo()\n"; }
>     void bar()        { std::cout << "Foo::bar()\n"; }
> }
>
> void f(const Foo&)
> {
>     std::cout << "f(const Foo&)\n";
> }
>
> int main()
> {
>     std::copy_ptr<Foo> p1(new Foo);  // p1 owns Foo
>     if (p1) p1->bar();
>  
>     {
>         std::copy_ptr<Foo> p2(std::move(p1));  // now p2 owns Foo
>         f(*p2);
>  
>         p1 = p2;  // cloned into p1
>         std::cout << "destroying p2...\n";
>     }
>  
>     if (p1) p1->bar();
>  
>     // Second Foo instance is destroyed when p1 goes out of scope
> }
>
> Output:
>
> Foo::Foo()
> Foo::bar()
> f(const Foo&)
> Foo::Foo(const Foo&)
> destroying p2...
> Foo::~Foo()
> Foo::bar()
> Foo::~Foo()
>
>

-- 
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/731cb931-eb89-41e0-8c1b-bfccd6329eaa%40isocpp.org.

------=_Part_350_483177092.1481942738585
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">Please don&#39;t define any relational operators for this =
class. If the relational operators are defined to compare the contained poi=
nters, then given the code<br><br><div style=3D"background-color: rgb(250, =
250, 250); border-color: rgb(187, 187, 187); border-style: solid; border-wi=
dth: 1px; overflow-wrap: break-word;" class=3D"prettyprint"><code class=3D"=
prettyprint"><div class=3D"subprettyprint"><span style=3D"color: #000;" cla=
ss=3D"styled-by-prettify">clone_ptr</span><span style=3D"color: #080;" clas=
s=3D"styled-by-prettify">&lt;int&gt;</span><span style=3D"color: #000;" cla=
ss=3D"styled-by-prettify"> foo</span><span style=3D"color: #660;" class=3D"=
styled-by-prettify">(</span><span style=3D"color: #008;" class=3D"styled-by=
-prettify">new</span><span style=3D"color: #000;" class=3D"styled-by-pretti=
fy"> </span><span style=3D"color: #008;" class=3D"styled-by-prettify">int</=
span><span style=3D"color: #660;" class=3D"styled-by-prettify">(</span><spa=
n style=3D"color: #066;" class=3D"styled-by-prettify">7</span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">));</span><span style=3D"col=
or: #000;" class=3D"styled-by-prettify"><br>clone_ptr</span><span style=3D"=
color: #080;" class=3D"styled-by-prettify">&lt;int&gt;</span><span style=3D=
"color: #000;" class=3D"styled-by-prettify"> bar </span><span style=3D"colo=
r: #660;" class=3D"styled-by-prettify">=3D</span><span style=3D"color: #000=
;" class=3D"styled-by-prettify"> foo</span><span style=3D"color: #660;" cla=
ss=3D"styled-by-prettify">;</span><span style=3D"color: #000;" class=3D"sty=
led-by-prettify"><br></span><span style=3D"color: #008;" class=3D"styled-by=
-prettify">assert</span><span style=3D"color: #660;" class=3D"styled-by-pre=
ttify">(</span><span style=3D"color: #000;" class=3D"styled-by-prettify">fo=
o </span><span style=3D"color: #660;" class=3D"styled-by-prettify">=3D=3D</=
span><span style=3D"color: #000;" class=3D"styled-by-prettify"> bar</span><=
span style=3D"color: #660;" class=3D"styled-by-prettify">);</span></div></c=
ode></div><br><br>the assertion will fail.=C2=A0 This means that code using=
 clone_ptr&#39;s in associative containers will compile but completely fail=
 to work at runtime.<br><br>Joe Gottman<br><br><br>On Friday, December 16, =
2016 at 6:32:25 AM UTC-5, Alexandre Isoard wrote:<blockquote class=3D"gmail=
_quote" style=3D"margin: 0;margin-left: 0.8ex;border-left: 1px #ccc solid;p=
adding-left: 1ex;"><div dir=3D"ltr"><b>Proposal</b><div><br></div><div styl=
e=3D"background-color:rgb(250,250,250);border-color:rgb(187,187,187);border=
-style:solid;border-width:1px;word-wrap:break-word"><code><div><span style=
=3D"color:#008">template</span><span style=3D"color:#660">&lt;</span><span =
style=3D"color:#008">class</span><span style=3D"color:#000"> T</span><span =
style=3D"color:#660">,</span><span style=3D"color:#000"><br>=C2=A0 =C2=A0 <=
/span><span style=3D"color:#008">class</span><span style=3D"color:#000"> </=
span><span style=3D"color:#606">Cloner</span><span style=3D"color:#000"> </=
span><span style=3D"color:#660">=3D</span><span style=3D"color:#000"> std</=
span><span style=3D"color:#660">::</span><span style=3D"color:#000">default=
_clone</span><span style=3D"color:#660">&lt;</span><span style=3D"color:#00=
0">T</span><span style=3D"color:#660">&gt;,</span><span style=3D"color:#000=
"><br>=C2=A0 =C2=A0 </span><span style=3D"color:#008">class</span><span sty=
le=3D"color:#000"> </span><span style=3D"color:#606">Deleter</span><span st=
yle=3D"color:#000"> </span><span style=3D"color:#660">=3D</span><span style=
=3D"color:#000"> </span><a href=3D"http://en.cppreference.com/w/cpp/memory/=
default_delete" target=3D"_blank" rel=3D"nofollow" onmousedown=3D"this.href=
=3D&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fen.cppreference.com%2Fw=
%2Fcpp%2Fmemory%2Fdefault_delete\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNHt=
NWhNDR8JsARzrVNyDZKv9uIz6Q&#39;;return true;" onclick=3D"this.href=3D&#39;h=
ttp://www.google.com/url?q\x3dhttp%3A%2F%2Fen.cppreference.com%2Fw%2Fcpp%2F=
memory%2Fdefault_delete\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNHtNWhNDR8Js=
ARzrVNyDZKv9uIz6Q&#39;;return true;"><span style=3D"color:#000">std</span><=
span style=3D"color:#660">::</span><span style=3D"color:#000">default_delet=
e</span></a><span style=3D"color:#660">&lt;</span><span style=3D"color:#000=
">T</span><span style=3D"color:#660">&gt;</span><span style=3D"color:#000">=
<br></span><span style=3D"color:#660">&gt;</span><span style=3D"color:#000"=
> </span><span style=3D"color:#008">class</span><span style=3D"color:#000">=
 copy_ptr</span></div></code></div><br><font face=3D"courier new, monospace=
">std::copy_ptr</font> is a smart pointer that owns and manages another obj=
ect through a pointer and disposes of that object when the <font face=3D"co=
urier new, monospace">copy_ptr </font>goes out of scope.<div>Additionally, =
it allocates a clone of the underlying object when it is copied from, ensur=
ing one <font face=3D"courier new, monospace">copy_ptr </font>manages each =
allocated object.<br><br>The object is disposed of using the associated del=
eter when either of the following happens:<br><ul><li>the managing <font fa=
ce=3D"courier new, monospace">copy_ptr </font>object is destroyed<br></li><=
li>the managing <font face=3D"courier new, monospace">copy_ptr </font>objec=
t is assigned another pointer via <a href=3D"http://en.cppreference.com/w/c=
pp/memory/unique_ptr/operator%3D" target=3D"_blank" rel=3D"nofollow" onmous=
edown=3D"this.href=3D&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fen.cp=
preference.com%2Fw%2Fcpp%2Fmemory%2Funique_ptr%2Foperator%253D\x26sa\x3dD\x=
26sntz\x3d1\x26usg\x3dAFQjCNFkMowHwWb-CXJYRuER8z4Vdi0Qtg&#39;;return true;"=
 onclick=3D"this.href=3D&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fen=
..cppreference.com%2Fw%2Fcpp%2Fmemory%2Funique_ptr%2Foperator%253D\x26sa\x3d=
D\x26sntz\x3d1\x26usg\x3dAFQjCNFkMowHwWb-CXJYRuER8z4Vdi0Qtg&#39;;return tru=
e;">operator=3D</a> or <a href=3D"http://en.cppreference.com/w/cpp/memory/u=
nique_ptr/reset" target=3D"_blank" rel=3D"nofollow" onmousedown=3D"this.hre=
f=3D&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fen.cppreference.com%2F=
w%2Fcpp%2Fmemory%2Funique_ptr%2Freset\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQ=
jCNGzmYfVvPXt1P7rhK2lyVW-j6bH8A&#39;;return true;" onclick=3D"this.href=3D&=
#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fen.cppreference.com%2Fw%2Fc=
pp%2Fmemory%2Funique_ptr%2Freset\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNGz=
mYfVvPXt1P7rhK2lyVW-j6bH8A&#39;;return true;">reset()</a>.</li></ul>The obj=
ect is disposed of using a potentially user-supplied deleter by calling <fo=
nt face=3D"courier new, monospace">get_deleter()(ptr)</font>. The default d=
eleter uses the <font face=3D"courier new, monospace">delete </font>operato=
r, which destroys the object and deallocates the memory.</div><div><br></di=
v><div>The object is cloned using the associated cloner when either of the =
following happens:</div><div><ul><li>an other <font face=3D"courier new, mo=
nospace">copy_ptr </font>object is copy constructed from the managing copy_=
ptr</li><li>an other <font face=3D"courier new, monospace">copy_ptr </font>=
object is copy assigned from the managing copy_ptr</li></ul><div>The object=
 is cloned using a potentially user-supplied cloner by calling <font face=
=3D"courier new, monospace">get_cloner()(ptr)</font>. The default cloner us=
es the <font face=3D"courier new, monospace">new </font>operator and the co=
py constructor of the underlying type, which allocate a new object and copy=
 its original content.</div><br>A <font face=3D"courier new, monospace">cop=
y_ptr </font>may alternatively own no object, in which case it is called em=
pty.<div><br></div>The class satisfies the requirements of <a href=3D"http:=
//en.cppreference.com/w/cpp/concept/MoveConstructible" target=3D"_blank" re=
l=3D"nofollow" onmousedown=3D"this.href=3D&#39;http://www.google.com/url?q\=
x3dhttp%3A%2F%2Fen.cppreference.com%2Fw%2Fcpp%2Fconcept%2FMoveConstructible=
\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNG9q1JBaTNiZ7Vh_C9K1hefbHQWoA&#39;;=
return true;" onclick=3D"this.href=3D&#39;http://www.google.com/url?q\x3dht=
tp%3A%2F%2Fen.cppreference.com%2Fw%2Fcpp%2Fconcept%2FMoveConstructible\x26s=
a\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNG9q1JBaTNiZ7Vh_C9K1hefbHQWoA&#39;;retur=
n true;">MoveConstructible</a>,=C2=A0<a href=3D"http://en.cppreference.com/=
w/cpp/concept/MoveAssignable" target=3D"_blank" rel=3D"nofollow" onmousedow=
n=3D"this.href=3D&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fen.cppref=
erence.com%2Fw%2Fcpp%2Fconcept%2FMoveAssignable\x26sa\x3dD\x26sntz\x3d1\x26=
usg\x3dAFQjCNF6GrlYRYGOufFABxI-2LHYYuUHzA&#39;;return true;" onclick=3D"thi=
s.href=3D&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fen.cppreference.c=
om%2Fw%2Fcpp%2Fconcept%2FMoveAssignable\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dA=
FQjCNF6GrlYRYGOufFABxI-2LHYYuUHzA&#39;;return true;">MoveAssigna<wbr>ble</a=
>, <a href=3D"http://en.cppreference.com/w/cpp/concept/CopyConstructible" t=
arget=3D"_blank" rel=3D"nofollow" onmousedown=3D"this.href=3D&#39;http://ww=
w.google.com/url?q\x3dhttp%3A%2F%2Fen.cppreference.com%2Fw%2Fcpp%2Fconcept%=
2FCopyConstructible\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNG-iAn9ftcEFUQ6N=
fvI6mNqhZH_Aw&#39;;return true;" onclick=3D"this.href=3D&#39;http://www.goo=
gle.com/url?q\x3dhttp%3A%2F%2Fen.cppreference.com%2Fw%2Fcpp%2Fconcept%2FCop=
yConstructible\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNG-iAn9ftcEFUQ6NfvI6m=
NqhZH_Aw&#39;;return true;">CopyConstructible</a> and=C2=A0<a href=3D"http:=
//en.cppreference.com/w/cpp/concept/CopyAssignable" target=3D"_blank" rel=
=3D"nofollow" onmousedown=3D"this.href=3D&#39;http://www.google.com/url?q\x=
3dhttp%3A%2F%2Fen.cppreference.com%2Fw%2Fcpp%2Fconcept%2FCopyAssignable\x26=
sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNHv92JdHik3TE576sBvuu5aQBH_9g&#39;;retu=
rn true;" onclick=3D"this.href=3D&#39;http://www.google.com/url?q\x3dhttp%3=
A%2F%2Fen.cppreference.com%2Fw%2Fcpp%2Fconcept%2FCopyAssignable\x26sa\x3dD\=
x26sntz\x3d1\x26usg\x3dAFQjCNHv92JdHik3TE576sBvuu5aQBH_9g&#39;;return true;=
">CopyAssignable</a>=C2=A0(the later two may require T to be CopyConstructi=
ble).<br></div><div><br></div><div><b>Member Types</b></div><div><ul><li><f=
ont face=3D"courier new, monospace">pointer</font>: <font face=3D"courier n=
ew, monospace">T*</font></li><li><font face=3D"courier new, monospace">elem=
ent_type</font>: <font face=3D"courier new, monospace">T</font>, the type o=
f the object managed by this <font face=3D"courier new, monospace">copy_ptr=
</font></li><li><font face=3D"courier new, monospace">cloner_type</font>:=
=C2=A0<font face=3D"courier new, monospace">Cloner</font>, the function obj=
ect or lvalue reference to function or to function object, to be called fro=
m the copy constructor and copy assignment operators</li><li><font face=3D"=
courier new, monospace">deleter_type</font>:=C2=A0<font face=3D"courier new=
, monospace">Deleter</font>, the function object or lvalue reference to fun=
ction or to function object, to be called from the destructor</li></ul></di=
v><div><br></div><div><b>Member Functions</b></div><div><ul><li>operator=3D=
: assigns the copy_ptr</li><li>release: returns a pointer to the managed ob=
ject and releases ownership</li><li>reset: replaces the managed object</li>=
<li>swap: swaps the managed objects</li><li>get: returns a pointer to the m=
anaged object</li><li>get_cloner: returns the cloner that is used for copy =
the managed object</li><li>get_deleter: returns the deleter that is used fo=
r destruction of the managed object</li><li>operator bool: checks if there =
is an associated managed object</li><li>operator*, operator-&gt;: dereferen=
ces pointer to the managed object</li><li>make_copy: creates a copy pointer=
 that manages a new object</li><li>operator=3D=3D, operator!=3D, etc: compa=
res to an other copy_ptr or with nullptr</li><li>std::swap: specializes the=
 std::swap algorithm</li><li>std::hash&lt;std::copy_ptr&gt;: hash support f=
or std::copy_ptr</li></ul></div><div><b>Example</b></div><div><br></div><di=
v><div style=3D"background-color:rgb(250,250,250);border-color:rgb(187,187,=
187);border-style:solid;border-width:1px;word-wrap:break-word"><code><div><=
font color=3D"#660066"><span style=3D"color:#800">#include</span><span styl=
e=3D"color:#080">&lt;iostream&gt;</span><span style=3D"color:#000"><br></sp=
an><span style=3D"color:#800">#include</span><span style=3D"color:#080">&lt=
;memory&gt;</span><span style=3D"color:#000"><br><br></span><span style=3D"=
color:#008">struct</span><span style=3D"color:#000"> </span><span style=3D"=
color:#606">Foo</span><span style=3D"color:#000"><br></span><span style=3D"=
color:#660">{</span><span style=3D"color:#000"><br>=C2=A0 =C2=A0 </span><sp=
an style=3D"color:#606">Foo</span><span style=3D"color:#660">()</span><span=
 style=3D"color:#000"> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 </span><sp=
an style=3D"color:#660">{</span><span style=3D"color:#000"> std</span><span=
 style=3D"color:#660">::</span><span style=3D"color:#000">cout </span><span=
 style=3D"color:#660">&lt;&lt;</span><span style=3D"color:#000"> </span><sp=
an style=3D"color:#080">&quot;Foo::Foo()\n&quot;</span><span style=3D"color=
:#660">;</span><span style=3D"color:#000"> </span><span style=3D"color:#660=
">}</span><span style=3D"color:#000"><br>=C2=A0 =C2=A0 </span><span style=
=3D"color:#606">Foo</span><span style=3D"color:#660">(</span><span style=3D=
"color:#008">const</span><span style=3D"color:#000"> </span><span style=3D"=
color:#606">Foo</span><span style=3D"color:#660">&amp;</span><span style=3D=
"color:#000"> o</span><span style=3D"color:#660">)</span><span style=3D"col=
or:#000"> </span><span style=3D"color:#660">{</span><span style=3D"color:#0=
00"> std</span><span style=3D"color:#660">::</span><span style=3D"color:#00=
0">cout </span><span style=3D"color:#660">&lt;&lt;</span><span style=3D"col=
or:#000"> </span><span style=3D"color:#080">&quot;Foo::Foo(const Foo&amp;)\=
n&quot;</span><span style=3D"color:#660">;</span><span style=3D"color:#000"=
> </span><span style=3D"color:#660">}</span><span style=3D"color:#000"><br>=
=C2=A0 =C2=A0 </span><span style=3D"color:#660">~</span><span style=3D"colo=
r:#606">Foo</span><span style=3D"color:#660">()</span><span style=3D"color:=
#000"> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0</span><span style=3D"color=
:#660">{</span><span style=3D"color:#000"> std</span><span style=3D"color:#=
660">::</span><span style=3D"color:#000">cout </span><span style=3D"color:#=
660">&lt;&lt;</span><span style=3D"color:#000"> </span><span style=3D"color=
:#080">&quot;Foo::~Foo()\n&quot;</span><span style=3D"color:#660">;</span><=
span style=3D"color:#000"> </span><span style=3D"color:#660">}</span><span =
style=3D"color:#000"><br>=C2=A0 =C2=A0 </span><span style=3D"color:#008">vo=
id</span><span style=3D"color:#000"> bar</span><span style=3D"color:#660">(=
)</span><span style=3D"color:#000"> =C2=A0 =C2=A0 =C2=A0 =C2=A0</span><span=
 style=3D"color:#660">{</span><span style=3D"color:#000"> std</span><span s=
tyle=3D"color:#660">::</span><span style=3D"color:#000">cout </span><span s=
tyle=3D"color:#660">&lt;&lt;</span><span style=3D"color:#000"> </span><span=
 style=3D"color:#080">&quot;Foo::bar()\n&quot;</span><span style=3D"color:#=
660">;</span><span style=3D"color:#000"> </span><span style=3D"color:#660">=
}</span><span style=3D"color:#000"><br></span><span style=3D"color:#660">}<=
/span><span style=3D"color:#000"><br><br></span><span style=3D"color:#008">=
void</span><span style=3D"color:#000"> f</span><span style=3D"color:#660">(=
</span><span style=3D"color:#008">const</span><span style=3D"color:#000"> <=
/span><span style=3D"color:#606">Foo</span><span style=3D"color:#660">&amp;=
)</span><span style=3D"color:#000"><br></span><span style=3D"color:#660">{<=
/span><span style=3D"color:#000"><br>=C2=A0 =C2=A0 std</span><span style=3D=
"color:#660">::</span><span style=3D"color:#000">cout </span><span style=3D=
"color:#660">&lt;&lt;</span><span style=3D"color:#000"> </span><span style=
=3D"color:#080">&quot;f(const Foo&amp;)\n&quot;</span><span style=3D"color:=
#660">;</span><span style=3D"color:#000"><br></span><span style=3D"color:#6=
60">}</span><span style=3D"color:#000"><br><br></span><span style=3D"color:=
#008">int</span><span style=3D"color:#000"> main</span><span style=3D"color=
:#660">()</span><span style=3D"color:#000"><br></span><span style=3D"color:=
#660">{</span><span style=3D"color:#000"><br></span><span style=3D"color:#0=
00"><div>=C2=A0 =C2=A0 std::copy_ptr&lt;Foo&gt; p1(new Foo); =C2=A0// p1 ow=
ns Foo</div><div>=C2=A0 =C2=A0 if (p1) p1-&gt;bar();</div><div>=C2=A0</div>=
<div>=C2=A0 =C2=A0 {</div><div>=C2=A0 =C2=A0 =C2=A0 =C2=A0 std::copy_ptr&lt=
;Foo&gt; p2(std::move(p1)); =C2=A0// now p2 owns Foo</div><div>=C2=A0 =C2=
=A0 =C2=A0 =C2=A0 f(*p2);</div><div>=C2=A0</div><div>=C2=A0 =C2=A0 =C2=A0 =
=C2=A0 p1 =3D p2; =C2=A0// cloned into p1</div><div>=C2=A0 =C2=A0 =C2=A0 =
=C2=A0 std::cout &lt;&lt; &quot;destroying p2...\n&quot;;</div><div>=C2=A0 =
=C2=A0 }</div><div>=C2=A0</div><div>=C2=A0 =C2=A0 if (p1) p1-&gt;bar();</di=
v><div>=C2=A0</div><div>=C2=A0 =C2=A0 // Second Foo instance is destroyed w=
hen p1 goes out of scope</div></span><span style=3D"color:#660">}</span><sp=
an style=3D"color:#000"><br></span></font></div></code></div><br>Output:</d=
iv><div><br></div><font face=3D"courier new, monospace">Foo::Foo()</font><d=
iv><font face=3D"courier new, monospace">Foo::bar()</font></div><div><font =
face=3D"courier new, monospace">f(const Foo&amp;)</font></div><div><font fa=
ce=3D"courier new, monospace">Foo::Foo(const Foo&amp;)</font></div><div><fo=
nt face=3D"courier new, monospace">destroying p2...</font></div><div><font =
face=3D"courier new, monospace">Foo::~Foo()</font></div><div><font face=3D"=
courier new, monospace">Foo::bar()</font></div><div><font face=3D"courier n=
ew, monospace">Foo::~Foo()</font><br><div><br></div></div></div></blockquot=
e></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/731cb931-eb89-41e0-8c1b-bfccd6329eaa%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/731cb931-eb89-41e0-8c1b-bfccd6329eaa=
%40isocpp.org</a>.<br />

------=_Part_350_483177092.1481942738585--

------=_Part_349_817252494.1481942738584--

.
