From 8556605289449503203
X-Google-Thread: f78e5,52dd3e1082ac085e
X-Google-Attributes: gidf78e5,public
X-Google-Language: ENGLISH,ASCII-7-bit
Path: g2news1.google.com!news4.google.com!news.glorb.com!border1.nntp.dca.giganews.com!nntp.giganews.com!local01.nntp.dca.giganews.com!nntp.speakeasy.net!news.speakeasy.net.POSTED!not-for-mail
NNTP-Posting-Date: Mon, 05 Sep 2005 16:50:20 -0500
Return-Path: <devnull@stump.algebra.com>
X-Authentication-Warning: mulga.cs.mu.OZ.AU: fjh set sender to devnull@stump.algebra.com using -f
X-Robomod: STUMP, ichudov@algebra.com (Igor Chudov)
Delivered-To: std-c++@ucar.edu
From: thorsten.ottosen@dezide.com
Newsgroups: comp.std.c++
Subject: Re: unique_ptr
Organization: http://groups.google.com
Message-ID: <1125946895.333900.88980@g49g2000cwa.googlegroups.com>
References: <1125603471.570361.32720@o13g2000cwo.googlegroups.com>
   <hinnant-8804B5.11081102092005@syrcnyrdrs-03-ge0.nyroc.rr.com>
Mime-Version: 1.0
Content-Type: text/plain; charset="iso-8859-1"
X-Complaints-To: groups-abuse@google.com
User-Agent: G2/0.2
X-HTTP-UserAgent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322),gzip(gfe),gzip(gfe)
Complaints-To: groups-abuse@google.com
Injection-Info: g49g2000cwa.googlegroups.com; posting-host=194.192.110.10;
   posting-account=u6ioRQ0AAAAsnrNzUsWML0OL2lIx3WFM
X-Virus-Scanned: amavisd-new at ucar.edu
X-Virus-Scanned: amavisd-new at cs.mu.OZ.AU
Approved: Fergus Henderson <fjh@cs.mu.oz.au>, moderator of comp.std.c++
X-Virus-Scanned: amavisd-new at cs.mu.OZ.AU
Date: Mon,  5 Sep 2005 16:44:19 CST
Lines: 59
NNTP-Posting-Host: 65.182.171.162
X-Trace: sv3-6nAEUBTEk0KrhifalA6w6zvJ8iwMZY0xn+qpO6h+GQGvxXtIMPCLkllQpy4UxUvhKvFvRo8n5CK8OJt!j3EKv1B10cDXSvvO6pQ+S4mM/HMXATIhYSO02KRmwNrHNLReZA1dCOcfINFAVKqiVtOejvmslNcr!MkBa2nxOBbAXtpbV2gSRjJahOt6GjZ869/td0Syekw==
X-Complaints-To: abuse@speakeasy.net
X-DMCA-Complaints-To: abuse@speakeasy.net
X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers
X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly
X-Postfilter: 1.3.32
Xref: g2news1.google.com comp.std.c++:2020


Howard Hinnant wrote:
> In article <1125603471.570361.32720@o13g2000cwo.googlegroups.com>,
>  "l.j.persson@gmail.com" <l.j.persson@gmail.com> wrote:
>
> > Hello,
> > I was just reading the excellent proposal on unique_ptr
> > (http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2005/n1856.html).
> > But I have a question on the constructor: why doesn't it take a T*&&
> > parameter?
> >
> > explicit unique_ptr(T*&& p);
> >
> > If I understand rvalues correctly that would mean:
> >
> > unique_ptr<int> ui(new int); // Ok
> > int* pi = new int;
> > unique_ptr<int> ui(pi); // Not Ok

[snip]

> That's a very interesting suggestion!
>
> I must admit that I'm waffling on it at the moment.  At first I thought
> it sounded great, and I prototyped it right up.  But then I used that
> prototype to start looking at some of my use cases, and my enthusiasm is
> waning.


While we're discussion potential correctness issues, then
we should probably consider adding functions like

template<class T, class U>
unique_ptr<T> make_unique_ptr( U&& );

[etc for X arguments].

The motivating example would be

foo( make_unique_ptr<T>( "foo" ), make_unique_ptr<T>( "bar" ) );

which is exception-safe whereas

foo( unique_ptr<T>( new T("foo") ), unique_ptr<T>( new T("bar") ) );

is not.

Similar stuff has been discussed for shared_ptr.

br

-Thorsten

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]



