This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
Re: std::shared_ptr vs allocators: by value or by const ref?!?
- From: Jonathan Wakely <jwakely dot gcc at gmail dot com>
- To: Paolo Carlini <paolo dot carlini at oracle dot com>
- Cc: "libstdc++" <libstdc++ at gcc dot gnu dot org>
- Date: Fri, 8 Oct 2010 12:38:07 +0100
- Subject: Re: std::shared_ptr vs allocators: by value or by const ref?!?
- References: <4CAF0103.7030600@oracle.com>
On 8 October 2010 12:31, Paolo Carlini wrote:
> Hi all, hi Jon,
>
> does anybody know what the heck is going on about allocator passing? We
> have allocate_shared taking the allocator by const ref, whereas the
> constructors, at variance with the rest of the library AFAICS, ?take it
> by value. Then in our implementation, at variance with the current
> C++0x, shared_ptr::reset takes it by const ref only to pass it
> immediately to a by value constructor, also we internally use by const
> ref in many other places. For sure, I have been able to change our impl
> to consistently use by const ref everywhere and apparently nothing
> breaks, and I don't see why it should: when a mutable allocator is
> required it is always constructed in the body of the various functions
> from the argument. Is there an open DR about this, Jon?
I don't think so. I have no idea why the shared_ptr constructors take
allocators by value.
The reset() inconsistency is probably my fault. At one point I
experimented with passing them by reference, so maybe I missed that
one and it got committed. I think I chose to pass by const-ref
internally, because I couldn't see any reason not to.