The new C++11 standard requires STL implementations to support stateful allocators in containers. Do main STL implementations (Visual Studio 2008, 2010, libstdc++) comply to this requirement now? I found nothing about this in MSDN or in libstdc++ documentation.
The new C++11 standard requires STL implementations to support stateful allocators in containers. Do
Share
Looks like the feature of stateful allocators in STL containers is widely supported already. In most cases statefullness of the allocator does not cause trouble. What is not widely supported yet is the new standard’s way of handling the problematic situations (swap of a container(whether to swap the allocator too), splice of lists).
This thread says:
This tread (libstdc++, 2004) says (if i understood correctly):
This blog entry (libstdc++, 2009) says:
This document says about the new libc++ library:
EASTL supports statefull allocators.
This thread contains an interesting dispute about how portable this feature is.
So most STL implementations support statefull allocators, which means that they do not create additional instances of the allocator type under the hood, but store the client-supplied allocator instance and all allocations/deallocations are done via that. However the way that they handle
swapping andlist::spliceis undocumented, non-portable.UPDATE: VS2008’s STL requires the allocators to have the templated copy constructor, which IMO makes the most important use of custom allocators impossible: simple segregated storage.
For whoever is not satisfied with the current state of stateful allocators in STL, I recommend to consider
Boost.IntrusiveandBoost.Container.