This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: C++11 allocator compliant unordered containers


On Feb 13, 2013 9:10 PM, "François Dumont" wrote:
>
> Hi
>
>     I am working on making unordered containers C++11 allocator compliant. In assignment operator I would like, when the allocator let me do it, reuse existing nodes rather than reallocating everything. To do so I use the copy assignment operator on the value_type. On unordered_set no problem, on unordered_map value_type is pair<const Key, Value> which is not copy assignable.
>
>     So can I consider in this context that I have a pair<Key, Value> or should I never reuse existing nodes ? I know that you are working on the equivalent for std::set and std::map Jonathan. Have you come to the same question ?

I have, yes, but haven't solved it yet. I don't want to cast away
const, so I think using allocator_traits::destroy and
allocator_traits::construct is the way to go. It reuses the memory for
the object, but is suboptimal if the object itself has memory that
could have been reused, e.g. when copying nested containers.

Maybe it would be better to swap the mapped_type with a local
variable, then swap it back into the value_type after the
destroy()+construct() calls but I haven't looked into that, and for
some types it would be even more expensive.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]