On Mon, 12 Jan 2004 19:21:23 -0000, "Nick Hounsome"
<> wrote:
>unfortunately the standard (20.1.5 para 4) says that implementations of
>standard containers are allowed to assume that
>"ALL INSTANCES OF A GIVEN ALLOCATOR TYPE ARE REQUIRED TO BE INTERCHANGEABLE
>AND ALWAYS COMPARE EQUAL TO EACH OTHER"
>
>This draconian requirement
I don't think it's considered draconian by implementors!
> effectively means that you cannot (usefully) have
>non-static data members in an allocator which - as far as I can see - makes
>them pretty well useless.
On the contrary, all the common standard library implementations have
waived that clause. In particular, Dinkumware's lib (used all over the
place), libstdc++ and STLport all allow stateful allocators, and that
covers most compilers. SGI (and libcomo) allows them, but doesn't seem
to swap them when swapping containers. I'd be very surprised if
Metrowerks didn't support them fully. Some libraries optimize the
common case of stateless allocators.
As well as the compare-equal clause, there's also the "encapsulate
more general memory models" recommendation, that Dinkumware have taken
up I believe (by not relying on alloc:

ointer being T*), but I'm not
sure about others.
The clause exists because not enough was known about allocators when
the standard was written. Experience now leads to the conclusion that
having stateful allocators is a good thing (since it allows use of
arbitrary pools, shared memory, etc.) - I suspect the next standard
will mandate it.
>What you could do is look up context in a map<pthread_t,Context> using
>pthread_self()
>
>P.S.Another stupid feature of allocators is the optional hint argument of
>the allocate method. This is totally useless because the standard template
>aren't required to use it.
And I don't know of an implementation that does use that hint
argument, no. Anyone?
Tom
C++ FAQ:
http://www.parashift.com/c++-faq-lite/
C FAQ:
http://www.eskimo.com/~scs/C-faq/top.html