Topic: status of make_unique
Author: jgottman6@gmail.com
Date: Tue, 5 Mar 2013 18:33:07 -0800 (PST)
Raw View
------=_Part_2030_31925114.1362537187515
Content-Type: text/plain; charset=ISO-8859-1
Herb Sutter has discussed the desirability of a make_unique function,
similar to make_shared, but I haven't seen a proposal for it. This would be
useful not only for convenience but for exception safety. Is there a
proposal for this to go into C++14?
Joe Gottman
--
---
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.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/?hl=en.
------=_Part_2030_31925114.1362537187515
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Herb Sutter has discussed the desirability of a make_unique function, simil=
ar to make_shared, but I haven't seen a proposal for it. This would be usef=
ul not only for convenience but for exception safety. Is there a prop=
osal for this to go into C++14?<br><br>Joe Gottman<br>
<p></p>
-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to std-proposals+unsubscribe@isocpp.org.<br />
To post to this group, send email to std-proposals@isocpp.org.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/?hl=3Den">http://groups.google.com/a/isocpp.org/group/std-pro=
posals/?hl=3Den</a>.<br />
<br />
<br />
------=_Part_2030_31925114.1362537187515--
.
Author: Nicol Bolas <jmckesson@gmail.com>
Date: Tue, 5 Mar 2013 19:07:28 -0800 (PST)
Raw View
------=_Part_206_13780316.1362539248229
Content-Type: text/plain; charset=ISO-8859-1
On Tuesday, March 5, 2013 6:33:07 PM UTC-8, jgot...@gmail.com wrote:
>
> Herb Sutter has discussed the desirability of a make_unique function,
> similar to make_shared, but I haven't seen a proposal for it. This would be
> useful not only for convenience but for exception safety. Is there a
> proposal for this to go into C++14?
>
> Joe Gottman
>
Speaking of such tiny proposals intended to fix holes in C++11... where's
std::cbegin and std::cend too?
--
---
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.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/?hl=en.
------=_Part_206_13780316.1362539248229
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
On Tuesday, March 5, 2013 6:33:07 PM UTC-8, jgot...@gmail.com wrote:<blockq=
uote class=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8ex;border-lef=
t: 1px #ccc solid;padding-left: 1ex;">Herb Sutter has discussed the desirab=
ility of a make_unique function, similar to make_shared, but I haven't seen=
a proposal for it. This would be useful not only for convenience but for e=
xception safety. Is there a proposal for this to go into C++14?<br><b=
r>Joe Gottman<br></blockquote><div><br>Speaking of such tiny proposals inte=
nded to fix holes in C++11... where's std::cbegin and std::cend too? <br></=
div>
<p></p>
-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to std-proposals+unsubscribe@isocpp.org.<br />
To post to this group, send email to std-proposals@isocpp.org.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/?hl=3Den">http://groups.google.com/a/isocpp.org/group/std-pro=
posals/?hl=3Den</a>.<br />
<br />
<br />
------=_Part_206_13780316.1362539248229--
.
Author: Marshall Clow <mclow.lists@gmail.com>
Date: Tue, 5 Mar 2013 20:41:08 -0800
Raw View
On Mar 5, 2013, at 6:33 PM, jgottman6@gmail.com wrote:
> Herb Sutter has discussed the desirability of a make_unique function, sim=
ilar to make_shared, but I haven't seen a proposal for it. This would be us=
eful not only for convenience but for exception safety. Is there a proposa=
l for this to go into C++14?
Here's a quick make_shared search and replace job (and some cleanup)
It needs deleter support - how do you mix default template arguments and va=
riadic templates?
I don't think you can write:
template<class T, class=85 Args, class D =3D default_delete<T>> unique_ptr=
<T, D> make_unique(Args&&... args);
because given an argument list of ( a, b, c, d ) what is Args and what is D=
?
20.7.1.1.X unique_ptr creation [util.smartptr.unique.create]
=20
template<class T, class... Args> unique_ptr<T> make_unique(Args&&... args);
template<class T, class A, class... Args>
unique_ptr<T> allocate_unique(const A& a, Args&&... args);
1. Requires: The expression ::new (pv) T(std::forward<Args>(args)...), wher=
e pv has type void* and points to storage suitable to hold an object of typ=
e T, shall be well formed. A shall be an allocator (17.6.3.5). The copy con=
structor and destructor of A shall not throw exceptions.
2. Effects: Allocates memory suitable for an object of type T and construct=
s an object in that memory via the placement new expression ::new (pv) T(st=
d::forward<Args>(args)...). The template allocate_unique uses a copy of a t=
o allocate memory. If an exception is thrown, the functions have no effect.
3. Returns: A unique_ptr instance that stores and owns the address of the n=
ewly constructed object of type T.
4. Postconditions: get() !=3D 0
5. Throws: bad_alloc, or an exception thrown from A::allocate or from the c=
onstructor of T.
-- Marshall
Marshall Clow Idio Software <mailto:mclow.lists@gmail.com>
A.D. 1517: Martin Luther nails his 95 Theses to the church door and is prom=
ptly moderated down to (-1, Flamebait).
-- Yu Suzuki
--=20
---=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.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposa=
ls/?hl=3Den.
.
Author: Ville Voutilainen <ville.voutilainen@gmail.com>
Date: Wed, 6 Mar 2013 08:31:05 +0200
Raw View
On 6 March 2013 06:41, Marshall Clow <mclow.lists@gmail.com> wrote:
> On Mar 5, 2013, at 6:33 PM, jgottman6@gmail.com wrote:
>> Herb Sutter has discussed the desirability of a make_unique function, si=
milar to make_shared, but I haven't seen a proposal for it. This would be u=
seful not only for convenience but for exception safety. Is there a propos=
al for this to go into C++14?
> Here's a quick make_shared search and replace job (and some cleanup)
> It needs deleter support - how do you mix default template arguments and =
variadic templates?
> I don't think you can write:
> template<class T, class=85 Args, class D =3D default_delete<T>> u=
nique_ptr<T, D> make_unique(Args&&... args);
> because given an argument list of ( a, b, c, d ) what is Args and what is=
D?
I guess with an overload that takes a deleter as its first argument?
Or with a different function? make_shared doesn't support
custom deleters, so why should make_unique?
--=20
---=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.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposa=
ls/?hl=3Den.
.
Author: Ville Voutilainen <ville.voutilainen@gmail.com>
Date: Wed, 6 Mar 2013 08:32:08 +0200
Raw View
On 6 March 2013 08:31, Ville Voutilainen <ville.voutilainen@gmail.com> wrot=
e:
>> I don't think you can write:
>> template<class T, class=85 Args, class D =3D default_delete<T>> =
unique_ptr<T, D> make_unique(Args&&... args);
>> because given an argument list of ( a, b, c, d ) what is Args and what i=
s D?
> I guess with an overload that takes a deleter as its first argument?
> Or with a different function? make_shared doesn't support
> custom deleters, so why should make_unique?
Well, I'm too hasty - a deleter as a first argument won't work, it
would be ambiguous. So a different function is necessary.
--=20
---=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.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposa=
ls/?hl=3Den.
.
Author: =?ISO-8859-1?Q?Daniel_Kr=FCgler?= <daniel.kruegler@gmail.com>
Date: Wed, 6 Mar 2013 07:33:02 +0100
Raw View
2013/3/6 Nicol Bolas <jmckesson@gmail.com>:
> Speaking of such tiny proposals intended to fix holes in C++11... where's
> std::cbegin and std::cend too?
Already handled by
http://cplusplus.github.com/LWG/lwg-active.html#2128
- Daniel
--
---
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.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/?hl=en.
.
Author: Jeffrey Yasskin <jyasskin@googlers.com>
Date: Tue, 5 Mar 2013 23:17:03 -0800
Raw View
There's an email from a year or so ago explaining why custom deleters
aren't needed for make_unique. I'll look for it tomorrow if you
haven't found it.
On Tue, Mar 5, 2013 at 10:31 PM, Ville Voutilainen
<ville.voutilainen@gmail.com> wrote:
> On 6 March 2013 06:41, Marshall Clow <mclow.lists@gmail.com> wrote:
>> On Mar 5, 2013, at 6:33 PM, jgottman6@gmail.com wrote:
>>> Herb Sutter has discussed the desirability of a make_unique function, s=
imilar to make_shared, but I haven't seen a proposal for it. This would be =
useful not only for convenience but for exception safety. Is there a propo=
sal for this to go into C++14?
>> Here's a quick make_shared search and replace job (and some cleanup)
>> It needs deleter support - how do you mix default template arguments and=
variadic templates?
>> I don't think you can write:
>> template<class T, class=85 Args, class D =3D default_delete<T>> =
unique_ptr<T, D> make_unique(Args&&... args);
>> because given an argument list of ( a, b, c, d ) what is Args and what i=
s D?
>
> I guess with an overload that takes a deleter as its first argument?
> Or with a different function? make_shared doesn't support
> custom deleters, so why should make_unique?
>
> --
>
> ---
> 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.
> Visit this group at http://groups.google.com/a/isocpp.org/group/std-propo=
sals/?hl=3Den.
>
>
--=20
---=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.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposa=
ls/?hl=3Den.
.
Author: Ville Voutilainen <ville.voutilainen@gmail.com>
Date: Wed, 6 Mar 2013 10:11:40 +0200
Raw View
On 6 March 2013 09:17, Jeffrey Yasskin <jyasskin@googlers.com> wrote:
> There's an email from a year or so ago explaining why custom deleters
> aren't needed for make_unique. I'll look for it tomorrow if you
> haven't found it.
I found it. It's Herb's email saying
"I'm not proposing a version that supports a custom deleter. That is not
necessary for symmetry (make_shared doesn't have it either for its
own reasons,
particularly that it's not useful) and make_unique shouldn't support
a deleter because allocating with new and deallocating with a custom deleter
is fraught with peril."
I tend to agree that for symmetry we don't need deleter support for make_unique,
but I suppose we need it in general. I also don't think providing an allocator
that is then converted to a deleter is sufficient - having to write an allocator
is much more difficult than just providing a deleter lambda, for instance.
--
---
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.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/?hl=en.
.
Author: Ville Voutilainen <ville.voutilainen@gmail.com>
Date: Wed, 6 Mar 2013 10:57:22 +0200
Raw View
On 6 March 2013 10:11, Ville Voutilainen <ville.voutilainen@gmail.com> wrote:
> I found it. It's Herb's email saying
Stephan T. Lavavej says he'll write a proposal for make_unique.
--
---
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.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/?hl=en.
.
Author: jgottman6@gmail.com
Date: Wed, 6 Mar 2013 06:21:31 -0800 (PST)
Raw View
------=_Part_609_10427736.1362579691242
Content-Type: text/plain; charset=windows-1252
Content-Transfer-Encoding: quoted-printable
Another feature that make_unique would need that make_shared doesn't have=
=20
is support for unique_ptr's of arrays. At the very least, we need to be=20
able to write
make_unique<int>(10)
and have it call=20
new int[10]
What would also be nice, but I'm not sure if it would be technically=20
feasible, would be the ability to initialize the individual array elements=
=20
in make_unique. Something like
auto p =3D make_unique<pair<int, string>>(3, { {1, "one"}, {2, "two"}, {3,=
=20
"three"} });
Joe Gottman
On Tuesday, March 5, 2013 11:41:08 PM UTC-5, Marshall wrote:
>
> On Mar 5, 2013, at 6:33 PM, jgot...@gmail.com <javascript:> wrote:=20
>
> > Herb Sutter has discussed the desirability of a make_unique function,=
=20
> similar to make_shared, but I haven't seen a proposal for it. This would =
be=20
> useful not only for convenience but for exception safety. Is there a=20
> proposal for this to go into C++14?=20
>
> Here's a quick make_shared search and replace job (and some cleanup)=20
> It needs deleter support - how do you mix default template arguments and=
=20
> variadic templates?=20
>
> I don't think you can write:=20
> template<class T, class=85 Args, class D =3D default_delete<T>>=
=20
> unique_ptr<T, D> make_unique(Args&&... args);=20
> because given an argument list of ( a, b, c, d ) what is Args and what is=
=20
> D?=20
>
>
>
>
> 20.7.1.1.X unique_ptr creation [util.smartptr.unique.create]=20
> =20
> template<class T, class... Args> unique_ptr<T> make_unique(Args&&...=20
> args);=20
> template<class T, class A, class... Args>=20
> unique_ptr<T> allocate_unique(const A& a, Args&&... args);=20
>
> 1. Requires: The expression ::new (pv) T(std::forward<Args>(args)...),=20
> where pv has type void* and points to storage suitable to hold an object =
of=20
> type T, shall be well formed. A shall be an allocator (17.6.3.5). The cop=
y=20
> constructor and destructor of A shall not throw exceptions.=20
>
> 2. Effects: Allocates memory suitable for an object of type T and=20
> constructs an object in that memory via the placement new expression ::ne=
w=20
> (pv) T(std::forward<Args>(args)...). The template allocate_unique uses a=
=20
> copy of a to allocate memory. If an exception is thrown, the functions ha=
ve=20
> no effect.=20
>
> 3. Returns: A unique_ptr instance that stores and owns the address of the=
=20
> newly constructed object of type T.=20
>
> 4. Postconditions: get() !=3D 0=20
>
> 5. Throws: bad_alloc, or an exception thrown from A::allocate or from the=
=20
> constructor of T.=20
>
>
>
>
>
--=20
---=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.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposa=
ls/?hl=3Den.
------=_Part_609_10427736.1362579691242
Content-Type: text/html; charset=windows-1252
Content-Transfer-Encoding: quoted-printable
<br>Another feature that make_unique would need that make_shared does=
n't have is support for unique_ptr's of arrays. At the very least, we=
need to be able to write<br><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;"><code class=3D"prettypri=
nt"><div class=3D"subprettyprint"><span style=3D"color: #000;" class=3D"sty=
led-by-prettify">make_unique</span><span style=3D"color: #080;" class=3D"st=
yled-by-prettify"><int></span><span style=3D"color: #660;" class=3D"s=
tyled-by-prettify">(</span><span style=3D"color: #066;" class=3D"styled-by-=
prettify">10</span><span style=3D"color: #660;" class=3D"styled-by-prettify=
">)</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br></s=
pan></div></code></div><br>and have it call <div class=3D"prettyprint" 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 cla=
ss=3D"prettyprint"><div class=3D"subprettyprint"><span style=3D"color: #008=
;" class=3D"styled-by-prettify">new</span><span style=3D"color: #000;" clas=
s=3D"styled-by-prettify"> </span><span style=3D"color: #008;" class=3D"styl=
ed-by-prettify">int</span><span style=3D"color: #660;" class=3D"styled-by-p=
rettify">[</span><span style=3D"color: #066;" class=3D"styled-by-prettify">=
10</span><span style=3D"color: #660;" class=3D"styled-by-prettify">]</span>=
<span style=3D"color: #000;" class=3D"styled-by-prettify"><br></span></div>=
</code></div><br>What would also be nice, but I'm not sure if it would be t=
echnically feasible, would be the ability to initialize the individual arra=
y elements in make_unique. Something like<br><div class=3D"prettyprin=
t" style=3D"background-color: rgb(250, 250, 250); border-color: rgb(187, 18=
7, 187); border-style: solid; border-width: 1px; word-wrap: break-word;"><c=
ode class=3D"prettyprint"><div class=3D"subprettyprint"><span style=3D"colo=
r: #008;" class=3D"styled-by-prettify">auto</span><span style=3D"color: #00=
0;" class=3D"styled-by-prettify"> p </span><span style=3D"color: #660;" cla=
ss=3D"styled-by-prettify">=3D</span><span style=3D"color: #000;" class=3D"s=
tyled-by-prettify"> make_unique</span><span style=3D"color: #660;" class=3D=
"styled-by-prettify"><</span><span style=3D"color: #000;" class=3D"style=
d-by-prettify">pair</span><span style=3D"color: #660;" class=3D"styled-by-p=
rettify"><</span><span style=3D"color: #008;" class=3D"styled-by-prettif=
y">int</span><span style=3D"color: #660;" class=3D"styled-by-prettify">,</s=
pan><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span=
style=3D"color: #008;" class=3D"styled-by-prettify">string</span><span sty=
le=3D"color: #660;" class=3D"styled-by-prettify">>>(</span><span styl=
e=3D"color: #066;" class=3D"styled-by-prettify">3</span><span style=3D"colo=
r: #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-b=
y-prettify"> </span><span style=3D"color: #660;" class=3D"styled-by-prettif=
y">{</span><span style=3D"color: #066;" class=3D"styled-by-prettify">1</spa=
n><span style=3D"color: #660;" class=3D"styled-by-prettify">,</span><span s=
tyle=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"c=
olor: #080;" class=3D"styled-by-prettify">"one"</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: #066;" class=3D"styled-by=
-prettify">2</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: #080;" class=3D"styled-by-prettify">"two"</span><spa=
n 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: #066;" =
class=3D"styled-by-prettify">3</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: #080;" class=3D"styled-by-prettify=
">"three"</span><span style=3D"color: #660;" class=3D"styled-by-prettify">}=
</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><s=
pan style=3D"color: #660;" class=3D"styled-by-prettify">});</span><span sty=
le=3D"color: #000;" class=3D"styled-by-prettify"><br></span></div></code></=
div><br>Joe Gottman<br><br>On Tuesday, March 5, 2013 11:41:08 PM UTC-5, Mar=
shall wrote:<blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-lef=
t: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;">On Mar 5, 2013, at=
6:33 PM, <a href=3D"javascript:" target=3D"_blank" gdf-obfuscated-mailto=
=3D"DoGpsJDe374J">jgot...@gmail.com</a> wrote:
<br>
<br>> Herb Sutter has discussed the desirability of a make_unique functi=
on, similar to make_shared, but I haven't seen a proposal for it. This woul=
d be useful not only for convenience but for exception safety. Is the=
re a proposal for this to go into C++14?
<br>
<br>Here's a quick make_shared search and replace job (and some cleanup)
<br>It needs deleter support - how do you mix default template arguments an=
d variadic templates?
<br>
<br>I don't think you can write:
<br> template<class T, cl=
ass=85 Args, class D =3D default_delete<T>> unique_ptr<T, D>=
make_unique(Args&&... args);
<br>because given an argument list of ( a, b, c, d ) what is Args and what =
is D?
<br>
<br>
<br>
<br>
<br>20.7.1.1.X unique_ptr creation [util.smartptr.unique.create]
<br> =20
<br>template<class T, class... Args> unique_ptr<T> make_unique(=
Args&&... args);
<br>template<class T, class A, class... Args>
<br> unique_ptr<T> allocate_unique(const A& a, Args&=
amp;&... args);
<br>
<br>1. Requires: The expression ::new (pv) T(std::forward<Args>(args)=
....)<wbr>, where pv has type void* and points to storage suitable to hold a=
n object of type T, shall be well formed. A shall be an allocator (17.6.3.5=
). The copy constructor and destructor of A shall not throw exceptions.
<br>
<br>2. Effects: Allocates memory suitable for an object of type T and const=
ructs an object in that memory via the placement new expression ::new (pv) =
T(std::forward<Args>(args)...)<wbr>. The template allocate_unique use=
s a copy of a to allocate memory. If an exception is thrown, the functions =
have no effect.
<br>
<br>3. Returns: A unique_ptr instance that stores and owns the address of t=
he newly constructed object of type T.
<br>
<br>4. Postconditions: get() !=3D 0
<br>
<br>5. Throws: bad_alloc, or an exception thrown from A::allocate or from t=
he constructor of T.
<br>
<br>
<br>
<br>
<br></blockquote>
<p></p>
-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to std-proposals+unsubscribe@isocpp.org.<br />
To post to this group, send email to std-proposals@isocpp.org.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/?hl=3Den">http://groups.google.com/a/isocpp.org/group/std-pro=
posals/?hl=3Den</a>.<br />
<br />
<br />
------=_Part_609_10427736.1362579691242--
.
Author: Ville Voutilainen <ville.voutilainen@gmail.com>
Date: Wed, 6 Mar 2013 16:24:14 +0200
Raw View
On 6 March 2013 16:21, <jgottman6@gmail.com> wrote:
> Another feature that make_unique would need that make_shared doesn't have
> is support for unique_ptr's of arrays. At the very least, we need to be
> able to write
> make_unique<int>(10)
> and have it call
> new int[10]
I utterly fail to see how that's "the very least" we "need".
--
---
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.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/?hl=en.
.
Author: Martinho Fernandes <martinho.fernandes@gmail.com>
Date: Wed, 6 Mar 2013 15:29:01 +0100
Raw View
On Wed, Mar 6, 2013 at 3:21 PM, <jgottman6@gmail.com> wrote:
>
> Another feature that make_unique would need that make_shared doesn't hav=
e
> is support for unique_ptr's of arrays. At the very least, we need to be
> able to write
> make_unique<int>(10)
>
> and have it call
> new int[10]
>
Did you mean make_unique<int[]>(10)? I am not sure we need that one
"at the very least", but I am sure we don't need to hve
make_unique<int>(10) make an array, because it sounds certifiably
insane to do so.
Mit freundlichen Gr=FC=DFen,
Martinho
--=20
---=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.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposa=
ls/?hl=3Den.
.
Author: jgottman6@gmail.com
Date: Wed, 6 Mar 2013 07:27:54 -0800 (PST)
Raw View
------=_Part_1049_5729542.1362583674460
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Yes, that was a mistake on my part.
On Wednesday, March 6, 2013 9:29:01 AM UTC-5, R. Martinho Fernandes wrote:
>
> On Wed, Mar 6, 2013 at 3:21 PM, <jgot...@gmail.com <javascript:>> wrote:=
=20
> >=20
> > Another feature that make_unique would need that make_shared doesn't=
=20
> have=20
> > is support for unique_ptr's of arrays. At the very least, we need to b=
e=20
> > able to write=20
> > make_unique<int>(10)=20
> >=20
> > and have it call=20
> > new int[10]=20
> >=20
>
> Did you mean make_unique<int[]>(10)? I am not sure we need that one=20
> "at the very least", but I am sure we don't need to hve=20
> make_unique<int>(10) make an array, because it sounds certifiably=20
> insane to do so.=20
>
> Mit freundlichen Gr=FC=DFen,=20
>
> Martinho=20
>
--=20
---=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.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposa=
ls/?hl=3Den.
------=_Part_1049_5729542.1362583674460
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Yes, that was a mistake on my part.<br><br>On Wednesday, March 6, 2013 9:29=
:01 AM UTC-5, R. Martinho Fernandes wrote:<blockquote class=3D"gmail_quote"=
style=3D"margin: 0;margin-left: 0.8ex;border-left: 1px #ccc solid;padding-=
left: 1ex;">On Wed, Mar 6, 2013 at 3:21 PM, <<a href=3D"javascript=
:" target=3D"_blank" gdf-obfuscated-mailto=3D"K647Uhnzx7UJ">jgot...@gmail.c=
om</a>> wrote:
<br>>
<br>> Another feature that make_unique would need that make_shared=
doesn't have
<br>> is support for unique_ptr's of arrays. At the very least, we=
need to be
<br>> able to write
<br>> make_unique<int>(10)
<br>>
<br>> and have it call
<br>> new int[10]
<br>>
<br>
<br>Did you mean make_unique<int[]>(10)? I am not sure we need that o=
ne
<br>"at the very least", but I am sure we don't need to hve
<br>make_unique<int>(10) make an array, because it sounds certifiably
<br>insane to do so.
<br>
<br>Mit freundlichen Gr=FC=DFen,
<br>
<br>Martinho
<br></blockquote>
<p></p>
-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to std-proposals+unsubscribe@isocpp.org.<br />
To post to this group, send email to std-proposals@isocpp.org.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/?hl=3Den">http://groups.google.com/a/isocpp.org/group/std-pro=
posals/?hl=3Den</a>.<br />
<br />
<br />
------=_Part_1049_5729542.1362583674460--
.
Author: jgottman6@gmail.com
Date: Wed, 6 Mar 2013 07:45:12 -0800 (PST)
Raw View
------=_Part_703_26168095.1362584712578
Content-Type: text/plain; charset=ISO-8859-1
I meant to say make_unique_<int []> and make_unique<pair<int, string>[] >
below.
Joe Gottman
On Wednesday, March 6, 2013 9:21:31 AM UTC-5, jgot...@gmail.com wrote:
>
>
> Another feature that make_unique would need that make_shared doesn't have
> is support for unique_ptr's of arrays. At the very least, we need to be
> able to write
> make_unique<int>(10)
>
> and have it call
> new int[10]
>
> What would also be nice, but I'm not sure if it would be technically
> feasible, would be the ability to initialize the individual array elements
> in make_unique. Something like
> auto p = make_unique<pair<int, string>>(3, { {1, "one"}, {2, "two"}, {3,
> "three"} });
>
> Joe Gottman
>
>>
>>
--
---
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.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/?hl=en.
------=_Part_703_26168095.1362584712578
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
<br>I meant to say make_unique_<int []> and make_unique<pair<in=
t, string>[] > below.<br><br>Joe Gottman<br>On Wednesday, March 6, 20=
13 9:21:31 AM UTC-5, jgot...@gmail.com wrote:<blockquote class=3D"gmail_quo=
te" style=3D"margin: 0;margin-left: 0.8ex;border-left: 1px #ccc solid;paddi=
ng-left: 1ex;"><br>Another feature that make_unique would need that m=
ake_shared doesn't have is support for unique_ptr's of arrays. At the=
very least, we need to be able to write<br><div style=3D"background-color:=
rgb(250,250,250);border-color:rgb(187,187,187);border-style:solid;border-wi=
dth:1px;word-wrap:break-word"><code><div><span style=3D"color:#000">make_un=
ique</span><span style=3D"color:#080"><int></span><span style=3D"colo=
r:#660">(</span><span style=3D"color:#066">10</span><span style=3D"color:#6=
60">)</span><span style=3D"color:#000"><br></span></div></code></div><br>an=
d have it call <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><span style=3D"color:#008">new</span><span style=3D"color:#000"=
> </span><span style=3D"color:#008">int</span><span style=3D"color:#660">[<=
/span><span style=3D"color:#066">10</span><span style=3D"color:#660">]</spa=
n><span style=3D"color:#000"><br></span></div></code></div><br>What would a=
lso be nice, but I'm not sure if it would be technically feasible, would be=
the ability to initialize the individual array elements in make_unique.&nb=
sp; Something like<br><div style=3D"background-color:rgb(250,250,250);borde=
r-color:rgb(187,187,187);border-style:solid;border-width:1px;word-wrap:brea=
k-word"><code><div><span style=3D"color:#008">auto</span><span style=3D"col=
or:#000"> p </span><span style=3D"color:#660">=3D</span><span style=3D"colo=
r:#000"> make_unique</span><span style=3D"color:#660"><</span><span styl=
e=3D"color:#000">pair</span><span style=3D"color:#660"><</span><span sty=
le=3D"color:#008">int</span><span style=3D"color:#660">,</span><span style=
=3D"color:#000"> </span><span style=3D"color:#008">string</span><span style=
=3D"color:#660">>>(</span><span style=3D"color:#066">3</span><span st=
yle=3D"color:#660">,</span><span style=3D"color:#000"> </span><span style=
=3D"color:#660">{</span><span style=3D"color:#000"> </span><span style=3D"c=
olor:#660">{</span><span style=3D"color:#066">1</span><span style=3D"color:=
#660">,</span><span style=3D"color:#000"> </span><span style=3D"color:#080"=
>"one"</span><span style=3D"color:#660">},</span><span style=3D"color:#000"=
> </span><span style=3D"color:#660">{</span><span style=3D"color:#066">2</s=
pan><span style=3D"color:#660">,</span><span style=3D"color:#000"> </span><=
span style=3D"color:#080">"two"</span><span style=3D"color:#660">},</span><=
span style=3D"color:#000"> </span><span style=3D"color:#660">{</span><span =
style=3D"color:#066">3</span><span style=3D"color:#660">,</span><span style=
=3D"color:#000"> </span><span style=3D"color:#080">"three"</span><span styl=
e=3D"color:#660">}</span><span style=3D"color:#000"> </span><span style=3D"=
color:#660">});</span><span style=3D"color:#000"><br></span></div></code></=
div><br>Joe Gottman<br><blockquote class=3D"gmail_quote" style=3D"margin:0;=
margin-left:0.8ex;border-left:1px #ccc solid;padding-left:1ex">
<br></blockquote></blockquote>
<p></p>
-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to std-proposals+unsubscribe@isocpp.org.<br />
To post to this group, send email to std-proposals@isocpp.org.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/?hl=3Den">http://groups.google.com/a/isocpp.org/group/std-pro=
posals/?hl=3Den</a>.<br />
<br />
<br />
------=_Part_703_26168095.1362584712578--
.
Author: Howard Hinnant <howard.hinnant@gmail.com>
Date: Wed, 6 Mar 2013 11:17:35 -0500
Raw View
On Mar 6, 2013, at 3:57 AM, Ville Voutilainen <ville.voutilainen@gmail.com> wrote:
> Stephan T. Lavavej says he'll write a proposal for make_unique.
I offer the following code to the public domain. Feel free to ignore any or all of it. If I had strong feelings that the code was correct I would be writing this proposal myself, and I'm not.
Howard
#include <type_traits>
#include <utility>
#include <memory>
template <class T, class ...Args>
typename std::enable_if
<
!std::is_array<T>::value,
std::unique_ptr<T>
>::type
make_unique(Args&& ...args)
{
return std::unique_ptr<T>(new T(std::forward<Args>(args)...));
}
template <class T>
typename std::enable_if
<
std::is_array<T>::value,
std::unique_ptr<T>
>::type
make_unique(std::size_t n)
{
typedef typename std::remove_extent<T>::type RT;
return std::unique_ptr<T>(new RT[n]);
}
int main()
{
auto p1 = make_unique<int>(3);
auto p2 = make_unique<int[]>(3);
}
// ----------------------------------------
#include <memory>
namespace std
{
template <class T>
inline
T*
to_raw_pointer(T* p) noexcept
{
return p;
}
template <class Pointer>
inline
typename pointer_traits<Pointer>::element_type*
to_raw_pointer(Pointer p) noexcept
{
return std::to_raw_pointer(p.operator->());
}
template <class Alloc>
class alloc_deleter
: public Alloc
{
public:
typedef Alloc allocator_type;
typedef allocator_traits<allocator_type> traits;
typedef typename traits::pointer pointer;
explicit alloc_deleter(const allocator_type& a)
: allocator_type(a) {}
void operator()(pointer p)
{
traits::destroy(*this, std::to_raw_pointer(p));
traits::deallocate(*this, p, 1);
}
};
template <class T, class Alloc, class ...Args>
unique_ptr<T, alloc_deleter<Alloc>>
allocate_unique(const Alloc& a, Args&& ...args)
{
typedef alloc_deleter<Alloc> A;
static_assert(sizeof(T) == sizeof(typename A::value_type),
"Allocator has incorrect value_type");
A alloc(a);
auto p = std::allocator_traits<A>::allocate(alloc, 1);
try
{
std::allocator_traits<A>::construct(alloc, std::to_raw_pointer(p),
std::forward<Args>(args)...);
}
catch (...)
{
std::allocator_traits<A>::deallocate(alloc, p, 1);
throw;
}
return unique_ptr<T, A>(p, alloc);
}
} // std
#include <iostream>
struct A
{
A() {std::cout << "A()\n";}
~A() {std::cout << "~A()\n";}
A(const A&) {std::cout << "A(const A&)\n";}
A& operator=(const A&) {std::cout << "operator=(const A&)\n"; return *this;}
void boo() {std::cout << "A::boo()\n";}
};
int main()
{
auto p = std::allocate_unique<A>(std::allocator<A>());
p->boo();
}
--
---
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.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/?hl=en.
.
Author: Zhihao Yuan <lichray@gmail.com>
Date: Wed, 6 Mar 2013 11:39:46 -0500
Raw View
On Wed, Mar 6, 2013 at 11:17 AM, Howard Hinnant
<howard.hinnant@gmail.com> wrote:
> template <class T, class ...Args>
> typename std::enable_if
> <
> !std::is_array<T>::value,
> std::unique_ptr<T>
>>::type
> make_unique(Args&& ...args)
> {
> return std::unique_ptr<T>(new T(std::forward<Args>(args)...));
> }
auto p = make_unique<std::array<int, 2>>(3);
--
Zhihao Yuan, ID lichray
The best way to predict the future is to invent it.
___________________________________________________
4BSD -- http://4bsd.biz/
--
---
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.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/?hl=en.
.
Author: Zhihao Yuan <lichray@gmail.com>
Date: Wed, 6 Mar 2013 11:53:08 -0500
Raw View
On Wed, Mar 6, 2013 at 11:39 AM, Zhihao Yuan <lichray@gmail.com> wrote:
> auto p = make_unique<std::array<int, 2>>(3);
Sorry, I was wrong. std::array is not recognized by is_array.
--
Zhihao Yuan, ID lichray
The best way to predict the future is to invent it.
___________________________________________________
4BSD -- http://4bsd.biz/
--
---
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.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/?hl=en.
.