Limit template parameters in hashtable

François Dumont frs.dumont@gmail.com
Wed Jul 17 20:54:00 GMT 2013


On 07/16/2013 11:03 AM, Jonathan Wakely wrote:
> On 15 July 2013 21:36, François Dumont wrote:
>> Hi
>>
>>      Here is a patch proposal to limit number of template parameters in
>> recently introduced _ReuseOrAllocNode and _AllocNode types. I hope it is
>> what you had in mind Jonathan. I have isolated most of allocation code into
>> a new _Hashtable_alloc class and inherit from it in _Hashtable. It greatly
>> reduce the number of template parameters for a number of methods that used
>> to be in _Hashtable.
> Yes, that's what I was thinking, thanks for doing it.  Would it be
> possible to rebind the allocator before instantiating _Hashtable, and
> have _Hastable_alloc<_Alloc, __cache> and get the value_type from the
> allocator?  That would mean these two specializations would share more
> code:
>
> unordered_map<int, int, P, C, allocator<pair<int,int>>>
>
> unordered_map<int, int, P, C, allocator<pair<const int,int>>>
>
> because they would both use the same specialization of _Hashtable and
> _Hashtable_alloc.
>
> If that makes change too complicated it isn't essential.

     Here is another proposal. I haven't rebound the allocator to 
instantiate _Hashtable but only to instantiate _Hashtable_alloc. I 
prefered to keep the definition of allocator_type into _Hashtable so 
that it isolates unordered_XXX from this kind of implementation detail. 
As allocator_type typedef must match _Alloc template parameters it has 
to be done before it is rebound.

>
>
>>      The drawback is of course that it introduces a binary breaking change,
>> is it fine ?
> Did we already do that for 4.9 anyway?
AFAIK no, no binary incompatibility so far. But I can't see how to do 
this simplification without this breaking change. _M_bbegin could be 
restore in its previous place but the allocator instance must be managed 
by _Hashtable_alloc so it will necessarily generate this breaking change.

François

-------------- next part --------------
A non-text attachment was scrubbed...
Name: hashtable.patch
Type: text/x-patch
Size: 37220 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/libstdc++/attachments/20130717/29771d01/attachment.bin>


More information about the Libstdc++ mailing list