Topic: allocate_shared and placement new


Author: Nicol Bolas <jmckesson@gmail.com>
Date: Thu, 17 Jan 2013 07:40:13 -0800 (PST)
Raw View
------=_Part_552_20130621.1358437213792
Content-Type: text/plain; charset=ISO-8859-1

std::allocate_shared takes an allocator to allocate the memory for the
shared_ptr. But a standard library allocator can do more than allocate
memory; it can also construct the object using
std::allocator_traits<A>::construct.

Except that it doesn't. It's specifically said to use placement new.

Shouldn't this be changed to use the traits, so that a user can define
their own traits class and potentially use constructors that are not
publicly accessible without making it easy for the rest of the world to
access them?

--




------=_Part_552_20130621.1358437213792
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

std::allocate_shared takes an allocator to allocate the memory for the shar=
ed_ptr. But a standard library allocator can do more than allocate memory; =
it can also construct the object using std::allocator_traits&lt;A&gt;::cons=
truct.<br><br>Except that it doesn't. It's specifically said to use placeme=
nt new.<br><br>Shouldn't this be changed to use the traits, so that a user =
can define their own traits class and potentially use constructors that are=
 not publicly accessible without making it easy for the rest of the world t=
o access them?<br>

<p></p>

-- <br />
&nbsp;<br />
&nbsp;<br />
&nbsp;<br />

------=_Part_552_20130621.1358437213792--

.


Author: =?ISO-8859-1?Q?Daniel_Kr=FCgler?= <daniel.kruegler@gmail.com>
Date: Thu, 17 Jan 2013 16:43:56 +0100
Raw View
2013/1/17 Nicol Bolas <jmckesson@gmail.com>:
> std::allocate_shared takes an allocator to allocate the memory for the
> shared_ptr. But a standard library allocator can do more than allocate
> memory; it can also construct the object using
> std::allocator_traits<A>::construct.
>
> Except that it doesn't. It's specifically said to use placement new.
>
> Shouldn't this be changed to use the traits, so that a user can define their
> own traits class and potentially use constructors that are not publicly
> accessible without making it easy for the rest of the world to access them?

This looks like

http://cplusplus.github.com/LWG/lwg-active.html#2070

to me.

- Daniel

--




.