std::shared_ptr vs allocators: by value or by const ref?!?
Fri Oct 8 11:38:00 GMT 2010
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.
More information about the Libstdc++