220 29816 <13702f32-32c2-447f-9996-3624fd678675@isocpp.org> article
Path: news.gmane.org!.POSTED!not-for-mail
From: alexandre.isoard@gmail.com
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: New smart pointer: CopyConstructible and
 CopyAssignable flavor of unique_ptr
Date: Fri, 16 Dec 2016 03:32:25 -0800 (PST)
Lines: 385
Approved: news@gmane.org
Message-ID: <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_415_597689489.1481887945418"
X-Trace: blaine.gmane.org 1481887948 4023 195.159.176.226 (16 Dec 2016 11:32:28 GMT)
X-Complaints-To: usenet@blaine.gmane.org
NNTP-Posting-Date: Fri, 16 Dec 2016 11:32:28 +0000 (UTC)
To: ISO C++ Standard - Future Proposals <std-proposals@isocpp.org>
Original-X-From: std-proposals+bncBDXMXE5S7EMRBSVBZ7BAKGQER5XNNMI@isocpp.org Fri Dec 16 12:32:23 2016
Return-path: <std-proposals+bncBDXMXE5S7EMRBSVBZ7BAKGQER5XNNMI@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-pg0-f72.google.com ([74.125.83.72])
	by blaine.gmane.org with esmtp (Exim 4.84_2)
	(envelope-from <std-proposals+bncBDXMXE5S7EMRBSVBZ7BAKGQER5XNNMI@isocpp.org>)
	id 1cHqkQ-0000B8-W0
	for gclcip-std-proposals@m.gmane.org; Fri, 16 Dec 2016 12:32:23 +0100
Original-Received: by mail-pg0-f72.google.com with SMTP id f188sf177216689pgc.1
        for <gclcip-std-proposals@m.gmane.org>; Fri, 16 Dec 2016 03:32:27 -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: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=e+t+G0pPVB9sFLLn251wH3470wS3q6AFPoauFGcecUc=;
        b=xaUOvdsD7LUmFQxFtN/FGMNWrKeH6F9kEfP7qRs7hC6FpJB/VFmWuSBvT40ySqBNjv
         FyDZG4+u8cASsNIkgeD7zGbbS5nc24NCAsXM3S6byigJUUdxU7y82BZq0GaqqExgz0g3
         0fwUOKOK4HTeRA6h6uMqDPDQIFjr4+8Rynv5122Vzhlxptm9XWsCcdPxTTci4dt6Z1LR
         hcT1+z/mi0OiCOSfVRgZdAvZNfl9AEs+73HA8cEx7gdYf7T1ob4B2ga4h6U+nYVLYGdm
         qAcS3VmGS7ibOyuAaVsYPO1WsLPxYfyrw/+nzTPfMWvg9sSx01bs3EYQQJ/vPPJ6EF6B
         ReJg==
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20161025;
        h=date:from:to:message-id: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=e+t+G0pPVB9sFLLn251wH3470wS3q6AFPoauFGcecUc=;
        b=O3FD3bfgr06Bhr99Ruokm5y+c/NFTPOGIeylyCP9dbJlmlp1fUYhZ3ITrQhUwISCII
         ucvt78f632Z/FkG+EOgUrC2FfiSuvb7gS3lTrLdzovp9EZBkVD5um5BW8bQaMJcPjI0I
         rs2+hR+9Kdkr/tj7rgRG6oRd8puj0SedqTd6E7qHi4Y9sVjQUsyKdTPvH1geeZnY/syc
         43+2eB2OcavN8B+Ov2M3uObDIfoMpnNBFrhj/2+EqqzqzD/ff4ek9Fw7nueObbqkv0Cj
         KVYRafIsMt/JBbpSsLZNACFy8p1G4NLIebYVfxW0NPxvS8BAIteMoSVH5NGDZh+3dR1G
         QaEA==
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: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=e+t+G0pPVB9sFLLn251wH3470wS3q6AFPoauFGcecUc=;
        b=hKBE43CUGAThChvuEVUg7ccmHG/HoJlNQTUmt7Hff9o12rcBDzP0BnEg1tFYCq50S4
         bGz4bQB890w/8NJ7+Di1HR8/jyK5b2wI6Z220/TQnbMPVoMyNyrEKNIzMyorG5Xgxp4k
         dAIafFQSXeS4BpVV+BgnsPRf3EgoFrZVc44HsykNvPOUXKPGM+bSbqzfbFJB3f0a3O6t
         bwAkU6mVlSdoH4udKMRM08XD0PYi/ZZHVf1ebu5SQbeeck4xML4ymTVHg+8URSXJ/Kd3
         v9wPPKH8OTwex41SkuthrdcR7kaNx/L7OJBj2xxpisRBLtuH1Sz3DTfy/IhQ9nsaT+qB
         UP/w==
X-Gm-Message-State: AKaTC03QxzcCAXKRsADd9WmHrW8aHT0QRYUR7k41kM5H6J4pect/shP2oBah6Pw+F7b8Ag==
X-Received: by 10.99.56.69 with SMTP id h5mr1072130pgn.113.1481887946772;
        Fri, 16 Dec 2016 03:32:26 -0800 (PST)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.157.41.209 with SMTP id g17ls8337664otd.46.gmail; Fri, 16 Dec
 2016 03:32:25 -0800 (PST)
X-Received: by 10.157.20.197 with SMTP id r5mr85866otr.9.1481887945888;
        Fri, 16 Dec 2016 03:32:25 -0800 (PST)
X-Original-Sender: alexandre.isoard@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:29816
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/29816>

------=_Part_415_597689489.1481887945418
Content-Type: multipart/alternative; 
	boundary="----=_Part_416_1112300632.1481887945419"

------=_Part_416_1112300632.1481887945419
Content-Type: text/plain; charset=UTF-8

*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/13702f32-32c2-447f-9996-3624fd678675%40isocpp.org.

------=_Part_416_1112300632.1481887945419
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><b>Proposal</b><div><br></div><div class=3D"prettyprint" s=
tyle=3D"background-color: rgb(250, 250, 250); border-color: rgb(187, 187, 1=
87); border-style: solid; border-width: 1px; word-wrap: break-word;"><code =
class=3D"prettyprint"><div class=3D"subprettyprint"><span style=3D"color: #=
008;" class=3D"styled-by-prettify">template</span><span style=3D"color: #66=
0;" class=3D"styled-by-prettify">&lt;</span><span style=3D"color: #008;" cl=
ass=3D"styled-by-prettify">class</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"> T</span><span style=3D"color: #660;" class=3D"styl=
ed-by-prettify">,</span><span style=3D"color: #000;" class=3D"styled-by-pre=
ttify"><br>=C2=A0 =C2=A0 </span><span style=3D"color: #008;" class=3D"style=
d-by-prettify">class</span><span style=3D"color: #000;" class=3D"styled-by-=
prettify"> </span><span style=3D"color: #606;" class=3D"styled-by-prettify"=
>Cloner</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </=
span><span style=3D"color: #660;" class=3D"styled-by-prettify">=3D</span><s=
pan style=3D"color: #000;" class=3D"styled-by-prettify"> std</span><span st=
yle=3D"color: #660;" class=3D"styled-by-prettify">::</span><span style=3D"c=
olor: #000;" class=3D"styled-by-prettify">default_clone</span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">&lt;</span><span style=3D"co=
lor: #000;" class=3D"styled-by-prettify">T</span><span style=3D"color: #660=
;" class=3D"styled-by-prettify">&gt;,</span><span style=3D"color: #000;" cl=
ass=3D"styled-by-prettify"><br>=C2=A0 =C2=A0 </span><span style=3D"color: #=
008;" class=3D"styled-by-prettify">class</span><span style=3D"color: #000;"=
 class=3D"styled-by-prettify"> </span><span style=3D"color: #606;" class=3D=
"styled-by-prettify">Deleter</span><span style=3D"color: #000;" class=3D"st=
yled-by-prettify"> </span><span style=3D"color: #660;" class=3D"styled-by-p=
rettify">=3D</span><span style=3D"color: #000;" class=3D"styled-by-prettify=
"> </span><a href=3D"http://en.cppreference.com/w/cpp/memory/default_delete=
"><span style=3D"color: #000;" class=3D"styled-by-prettify">std</span><span=
 style=3D"color: #660;" class=3D"styled-by-prettify">::</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify">default_delete</span></a><sp=
an style=3D"color: #660;" class=3D"styled-by-prettify">&lt;</span><span sty=
le=3D"color: #000;" class=3D"styled-by-prettify">T</span><span style=3D"col=
or: #660;" class=3D"styled-by-prettify">&gt;</span><span style=3D"color: #0=
00;" class=3D"styled-by-prettify"><br></span><span style=3D"color: #660;" c=
lass=3D"styled-by-prettify">&gt;</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"> </span><span style=3D"color: #008;" class=3D"style=
d-by-prettify">class</span><span style=3D"color: #000;" class=3D"styled-by-=
prettify"> 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 a=
nother object through a pointer and disposes of that object when the <font =
face=3D"courier new, monospace">copy_ptr </font>goes out of scope.<div>Addi=
tionally, it allocates a clone of the underlying object when it is copied f=
rom, ensuring one <font face=3D"courier new, monospace">copy_ptr </font>man=
ages each allocated object.<br><br>The object is disposed of using the asso=
ciated deleter when either of the following happens:<br><ul><li>the managin=
g <font face=3D"courier new, monospace">copy_ptr </font>object is destroyed=
<br></li><li>the managing <font face=3D"courier new, monospace">copy_ptr </=
font>object is assigned another pointer via <a href=3D"http://en.cppreferen=
ce.com/w/cpp/memory/unique_ptr/operator%3D">operator=3D</a> or <a href=3D"h=
ttp://en.cppreference.com/w/cpp/memory/unique_ptr/reset">reset()</a>.</li><=
/ul>The object is disposed of using a potentially user-supplied deleter by =
calling <font face=3D"courier new, monospace">get_deleter()(ptr)</font>. Th=
e default deleter uses the <font face=3D"courier new, monospace">delete </f=
ont>operator, which destroys the object and deallocates the memory.</div><d=
iv><br></div><div>The object is cloned using the associated cloner when eit=
her of the following happens:</div><div><ul><li>an other <font face=3D"cour=
ier new, monospace">copy_ptr </font>object is copy constructed from the man=
aging 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 uses the <font face=3D"courier new, monospace">new </font>operator a=
nd the copy constructor of the underlying type, which allocate a new object=
 and copy its original content.</div><br>A <font face=3D"courier new, monos=
pace">copy_ptr </font>may alternatively own no object, in which case it is =
called empty.<div><br></div>The class satisfies the requirements of <a href=
=3D"http://en.cppreference.com/w/cpp/concept/MoveConstructible">MoveConstru=
ctible</a>,=C2=A0<a href=3D"http://en.cppreference.com/w/cpp/concept/MoveAs=
signable">MoveAssignable</a>, <a href=3D"http://en.cppreference.com/w/cpp/c=
oncept/CopyConstructible">CopyConstructible</a> and=C2=A0<a href=3D"http://=
en.cppreference.com/w/cpp/concept/CopyAssignable">CopyAssignable</a>=C2=A0(=
the later two may require T to be CopyConstructible).<br></div><div><br></d=
iv><div><b>Member Types</b></div><div><ul><li><font face=3D"courier new, mo=
nospace">pointer</font>: <font face=3D"courier new, monospace">T*</font></l=
i><li><font face=3D"courier new, monospace">element_type</font>: <font face=
=3D"courier new, monospace">T</font>, the type of the object managed by thi=
s <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 object or lvalue reference to f=
unction or to function object, to be called from the copy constructor and c=
opy assignment operators</li><li><font face=3D"courier new, monospace">dele=
ter_type</font>:=C2=A0<font face=3D"courier new, monospace">Deleter</font>,=
 the function object or lvalue reference to function or to function object,=
 to be called from the destructor</li></ul></div><div><br></div><div><b>Mem=
ber Functions</b></div><div><ul><li>operator=3D: assigns the copy_ptr</li><=
li>release: returns a pointer to the managed object 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 managed object</li><li>get_cl=
oner: returns the cloner that is used for copy the managed object</li><li>g=
et_deleter: returns the deleter that is used for destruction of the managed=
 object</li><li>operator bool: checks if there is an associated managed obj=
ect</li><li>operator*, operator-&gt;: dereferences pointer to the managed o=
bject</li><li>make_copy: creates a copy pointer that manages a new object</=
li><li>operator=3D=3D, operator!=3D, etc: compares 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 for std::copy_ptr</li></ul></=
div><div><b>Example</b></div><div><br></div><div><div class=3D"prettyprint"=
 style=3D"background-color: rgb(250, 250, 250); border-color: rgb(187, 187,=
 187); border-style: solid; border-width: 1px; word-wrap: break-word;"><cod=
e class=3D"prettyprint"><div class=3D"subprettyprint"><font color=3D"#66006=
6"><span style=3D"color: #800;" class=3D"styled-by-prettify">#include</span=
><span style=3D"color: #080;" class=3D"styled-by-prettify">&lt;iostream&gt;=
</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br></span=
><span style=3D"color: #800;" class=3D"styled-by-prettify">#include</span><=
span style=3D"color: #080;" class=3D"styled-by-prettify">&lt;memory&gt;</sp=
an><span style=3D"color: #000;" class=3D"styled-by-prettify"><br><br></span=
><span style=3D"color: #008;" class=3D"styled-by-prettify">struct</span><sp=
an style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=
=3D"color: #606;" class=3D"styled-by-prettify">Foo</span><span style=3D"col=
or: #000;" class=3D"styled-by-prettify"><br></span><span style=3D"color: #6=
60;" class=3D"styled-by-prettify">{</span><span style=3D"color: #000;" clas=
s=3D"styled-by-prettify"><br>=C2=A0 =C2=A0 </span><span style=3D"color: #60=
6;" 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"st=
yled-by-prettify"> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 </span><span s=
tyle=3D"color: #660;" class=3D"styled-by-prettify">{</span><span style=3D"c=
olor: #000;" class=3D"styled-by-prettify"> std</span><span style=3D"color: =
#660;" class=3D"styled-by-prettify">::</span><span style=3D"color: #000;" c=
lass=3D"styled-by-prettify">cout </span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">&lt;&lt;</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"> </span><span style=3D"color: #080;" class=3D"style=
d-by-prettify">&quot;Foo::Foo()\n&quot;</span><span style=3D"color: #660;" =
class=3D"styled-by-prettify">;</span><span style=3D"color: #000;" class=3D"=
styled-by-prettify"> </span><span style=3D"color: #660;" class=3D"styled-by=
-prettify">}</span><span style=3D"color: #000;" class=3D"styled-by-prettify=
"><br>=C2=A0 =C2=A0 </span><span style=3D"color: #606;" class=3D"styled-by-=
prettify">Foo</span><span style=3D"color: #660;" class=3D"styled-by-prettif=
y">(</span><span style=3D"color: #008;" class=3D"styled-by-prettify">const<=
/span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><sp=
an style=3D"color: #606;" class=3D"styled-by-prettify">Foo</span><span styl=
e=3D"color: #660;" class=3D"styled-by-prettify">&amp;</span><span style=3D"=
color: #000;" class=3D"styled-by-prettify"> o</span><span style=3D"color: #=
660;" class=3D"styled-by-prettify">)</span><span style=3D"color: #000;" cla=
ss=3D"styled-by-prettify"> </span><span style=3D"color: #660;" class=3D"sty=
led-by-prettify">{</span><span style=3D"color: #000;" class=3D"styled-by-pr=
ettify"> std</span><span style=3D"color: #660;" class=3D"styled-by-prettify=
">::</span><span style=3D"color: #000;" class=3D"styled-by-prettify">cout <=
/span><span style=3D"color: #660;" class=3D"styled-by-prettify">&lt;&lt;</s=
pan><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span=
 style=3D"color: #080;" class=3D"styled-by-prettify">&quot;Foo::Foo(const F=
oo&amp;)\n&quot;</span><span style=3D"color: #660;" class=3D"styled-by-pret=
tify">;</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </=
span><span style=3D"color: #660;" class=3D"styled-by-prettify">}</span><spa=
n style=3D"color: #000;" class=3D"styled-by-prettify"><br>=C2=A0 =C2=A0 </s=
pan><span style=3D"color: #660;" class=3D"styled-by-prettify">~</span><span=
 style=3D"color: #606;" class=3D"styled-by-prettify">Foo</span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">()</span><span style=3D"colo=
r: #000;" class=3D"styled-by-prettify"> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
=C2=A0</span><span style=3D"color: #660;" class=3D"styled-by-prettify">{</s=
pan><span style=3D"color: #000;" class=3D"styled-by-prettify"> std</span><s=
pan style=3D"color: #660;" class=3D"styled-by-prettify">::</span><span styl=
e=3D"color: #000;" class=3D"styled-by-prettify">cout </span><span style=3D"=
color: #660;" class=3D"styled-by-prettify">&lt;&lt;</span><span style=3D"co=
lor: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #080=
;" class=3D"styled-by-prettify">&quot;Foo::~Foo()\n&quot;</span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">;</span><span style=3D"color=
: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #660;" =
class=3D"styled-by-prettify">}</span><span style=3D"color: #000;" class=3D"=
styled-by-prettify"><br>=C2=A0 =C2=A0 </span><span style=3D"color: #008;" c=
lass=3D"styled-by-prettify">void</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"> bar</span><span style=3D"color: #660;" class=3D"st=
yled-by-prettify">()</span><span style=3D"color: #000;" class=3D"styled-by-=
prettify"> =C2=A0 =C2=A0 =C2=A0 =C2=A0</span><span style=3D"color: #660;" c=
lass=3D"styled-by-prettify">{</span><span style=3D"color: #000;" class=3D"s=
tyled-by-prettify"> std</span><span style=3D"color: #660;" class=3D"styled-=
by-prettify">::</span><span style=3D"color: #000;" class=3D"styled-by-prett=
ify">cout </span><span style=3D"color: #660;" class=3D"styled-by-prettify">=
&lt;&lt;</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> <=
/span><span style=3D"color: #080;" class=3D"styled-by-prettify">&quot;Foo::=
bar()\n&quot;</span><span style=3D"color: #660;" class=3D"styled-by-prettif=
y">;</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </spa=
n><span style=3D"color: #660;" class=3D"styled-by-prettify">}</span><span s=
tyle=3D"color: #000;" class=3D"styled-by-prettify"><br></span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">}</span><span style=3D"color=
: #000;" class=3D"styled-by-prettify"><br><br></span><span style=3D"color: =
#008;" class=3D"styled-by-prettify">void</span><span style=3D"color: #000;"=
 class=3D"styled-by-prettify"> f</span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">(</span><span style=3D"color: #008;" class=3D"style=
d-by-prettify">const</span><span style=3D"color: #000;" class=3D"styled-by-=
prettify"> </span><span style=3D"color: #606;" class=3D"styled-by-prettify"=
>Foo</span><span style=3D"color: #660;" class=3D"styled-by-prettify">&amp;)=
</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br></span=
><span style=3D"color: #660;" class=3D"styled-by-prettify">{</span><span st=
yle=3D"color: #000;" class=3D"styled-by-prettify"><br>=C2=A0 =C2=A0 std</sp=
an><span style=3D"color: #660;" class=3D"styled-by-prettify">::</span><span=
 style=3D"color: #000;" class=3D"styled-by-prettify">cout </span><span styl=
e=3D"color: #660;" class=3D"styled-by-prettify">&lt;&lt;</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color=
: #080;" class=3D"styled-by-prettify">&quot;f(const Foo&amp;)\n&quot;</span=
><span style=3D"color: #660;" class=3D"styled-by-prettify">;</span><span st=
yle=3D"color: #000;" class=3D"styled-by-prettify"><br></span><span style=3D=
"color: #660;" class=3D"styled-by-prettify">}</span><span style=3D"color: #=
000;" class=3D"styled-by-prettify"><br><br></span><span style=3D"color: #00=
8;" class=3D"styled-by-prettify">int</span><span style=3D"color: #000;" cla=
ss=3D"styled-by-prettify"> main</span><span style=3D"color: #660;" class=3D=
"styled-by-prettify">()</span><span style=3D"color: #000;" class=3D"styled-=
by-prettify"><br></span><span style=3D"color: #660;" class=3D"styled-by-pre=
ttify">{</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><b=
r></span><span style=3D"color: #000;" class=3D"styled-by-prettify"><div cla=
ss=3D"subprettyprint">=C2=A0 =C2=A0 std::copy_ptr&lt;Foo&gt; p1(new Foo); =
=C2=A0// p1 owns Foo</div><div class=3D"subprettyprint">=C2=A0 =C2=A0 if (p=
1) p1-&gt;bar();</div><div class=3D"subprettyprint">=C2=A0</div><div class=
=3D"subprettyprint">=C2=A0 =C2=A0 {</div><div class=3D"subprettyprint">=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 class=3D"subprettyprint">=C2=A0 =C2=A0 =C2=A0 =
=C2=A0 f(*p2);</div><div class=3D"subprettyprint">=C2=A0</div><div class=3D=
"subprettyprint">=C2=A0 =C2=A0 =C2=A0 =C2=A0 p1 =3D p2; =C2=A0// cloned int=
o p1</div><div class=3D"subprettyprint">=C2=A0 =C2=A0 =C2=A0 =C2=A0 std::co=
ut &lt;&lt; &quot;destroying p2...\n&quot;;</div><div class=3D"subprettypri=
nt">=C2=A0 =C2=A0 }</div><div class=3D"subprettyprint">=C2=A0</div><div cla=
ss=3D"subprettyprint">=C2=A0 =C2=A0 if (p1) p1-&gt;bar();</div><div class=
=3D"subprettyprint">=C2=A0</div><div class=3D"subprettyprint">=C2=A0 =C2=A0=
 // Second Foo instance is destroyed when p1 goes out of scope</div></span>=
<span style=3D"color: #660;" class=3D"styled-by-prettify">}</span><span sty=
le=3D"color: #000;" class=3D"styled-by-prettify"><br></span></font></div></=
code></div><br>Output:</div><div><br></div><font face=3D"courier new, monos=
pace">Foo::Foo()</font><div><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 face=3D"courier new, monospace">Foo::Foo(const Foo&a=
mp;)</font></div><div><font 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><di=
v><font face=3D"courier new, monospace">Foo::~Foo()</font><br><div><br></di=
v></div></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/13702f32-32c2-447f-9996-3624fd678675%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/13702f32-32c2-447f-9996-3624fd678675=
%40isocpp.org</a>.<br />

------=_Part_416_1112300632.1481887945419--

------=_Part_415_597689489.1481887945418--

.
