[patch] Simplify allocator use
François Dumont
frs.dumont@gmail.com
Fri Jun 27 21:29:00 GMT 2014
On 26/06/2014 13:31, Jonathan Wakely wrote:
> On 25/06/14 21:56 +0100, Jonathan Wakely wrote:
>> The other adds an RAII type to help manage pointers obtained from
>> allocators. The new type means I can remove several ugly try-catch
>> blocks that are all very similar in structure and have been bothering
>> me for some time. The new type also makes it trivial to support
>> allocators with fancy pointers, fixing long-standing (but not very
>> important) bugs in std::promise and std::shared_ptr.
>
> This patch applies the __allocated_ptr type to hashtable_policy.h to
> remove most explicit deallocation (yay!) The buckets are still
> allocated and deallocated manually, because __allocated_ptr only works
> for allocations of single objects, not arrays.
>
> As well as __allocated_ptr this change relies on two things:
>
> 1) the node type has a trivial destructor, so we don't actually need
> to call it, we can just reuse or release its storage.
> (See 3.8 [basic.life] p1)
>
> 2) allocator_traits::construct and allocator_traits::destroy can be
> used with an allocator that has a different value_type, so we don't
> need to create a rebound copy to destroy every element, we can just
> use the node-allocator.
> (See http://cplusplus.github.io/LWG/lwg-active.html#2218 which is
> Open, but I've discussed the issue with Howard, Pablo and others,
> and I think libc++ already relies on this assumption).
>
> François, could you check it, and let me know if you see anything
> wrong or have any comments?
>
That looks fine to me, nice simplification.
François
More information about the Libstdc++
mailing list