Topic: unique_ptr : make_unique missing ?
Author: Thomas Petit <thomas.petit33@gmail.com>
Date: Tue, 2 Jun 2009 13:36:02 CST Raw View
I cannot spot any equivalent function of make_shared() for unique_ptr
in the latest draft
(N2857 : http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2009/n2857.pdf)
An helper function, say make_unique(), would bring the interface of
unique_ptr closer than
the shared_ptr one, and would be more convenient to use :
std::shared_ptr<MyType> sp = new std::shared_ptr<MyType>(new MyType
(someargs...)); // redondant, new/new and MyType/MyType x2
std::shared_ptr<MyType> sp = std::make_shared<MyType>(someargs...); //
better !
std::unique_ptr<MyType> up = new std::unique_ptr<MyType>(new MyType
(someargs...));
// std::unique_ptr<MyType> up = std::make_unique<MyType>
(someargs...); // doesn't exist ?
Is there any plan to add something like make_unique for C++0x ? Or do
I overlooked some technical difficulties ?
Thanks,
Thomas.
--
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@netlab.cs.rpi.edu]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]
Author: Mathias Gaunard <loufoque@gmail.com>
Date: Wed, 3 Jun 2009 00:35:33 CST Raw View
On 2 juin, 21:36, Thomas Petit <thomas.peti...@gmail.com> wrote:
> I cannot spot any equivalent function of make_shared() for unique_ptr
> in the latest draft
> (N2857 : http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2009/n2857.pdf)
there is a make_shared so that the object and the reference count can
be allocated in a single allocation.
unique_ptr cannot make use of such things.
--
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@netlab.cs.rpi.edu]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]
Author: wasti.redl@gmx.net
Date: Wed, 3 Jun 2009 12:53:38 CST Raw View
On Jun 3, 8:35 am, Mathias Gaunard <loufo...@gmail.com> wrote:
> On 2 juin, 21:36, Thomas Petit <thomas.peti...@gmail.com> wrote:
>
> > I cannot spot any equivalent function of make_shared() for unique_ptr
> > in the latest draft
> > (N2857 : http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2009/n2857.pdf)
>
> there is a make_shared so that the object and the reference count can
> be allocated in a single allocation.
> unique_ptr cannot make use of such things.
But unique_ptr would still profit from the RAII safety in the
classical example:
void func(unique_ptr<Foo> f1, unique_ptr<Foo> f2);
func(new Foo, new Foo); // exception-unsafe
func(make_unique<Foo>(), make_unique<Foo>()); // exception-safe
--
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@netlab.cs.rpi.edu]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]