Re: allocator requirements

From: John Harrison (john_andronicus_at_hotmail.com)
Date: 07/09/04


Date: Fri, 09 Jul 2004 22:33:10 +0100

On Fri, 9 Jul 2004 15:21:25 -0600, Jonathan Turkanis
<technews@kangaroologic.com> wrote:

>
> "John Harrison" <john_andronicus@hotmail.com> wrote in message
> news:opsav1xfa5212331@andronicus...
>> On Fri, 09 Jul 2004 20:47:16 GMT, P.J. Plauger <pjp@dinkumware.com>
> wrote:
>>
>> > "John Harrison" <john_andronicus@hotmail.com> wrote in message
>> > news:opsavy7sdb212331@andronicus...
>> >
>> >> If you specify an allocator in an STL container is it a
> requirement that
>> >> the allocator allocates object of the right type,
>> >
>> > Yes, according to the C++ Standard.
>> >
>> >> or can you
> assume that
>> >> the container will rebind the allocator to the correct type?
>> >
>> > Yes, according to widespread practice.
>> >
>> > P.J. Plauger
>> > Dinkumware, Ltd.
>> > http://www.dinkumware.com
>> >
>>
>> Yes it seems so, both implementations of the STL I've checked do
> rebind
>> the allocator for vector at least. This seems to directly contradict
> the
>> requirements for allocator_type.
>
> How does this contradict the allocator requirements?

Not the allocator requirements, the requirements for allocator_type. For
instance 23.2.4 has

template <class T, class Allocator = std::allocator<T> >
class vector
{
        ...
        typedef Allocator allocator_type;

i.e. allocator_type should be the same type as the template parameter.

>
>> I also noticed that Josuttis' book also ignores what the standard
> says,
>> see first page of chapter 15 where he happily passes the same
> allocator to
>> several containers with different value types.
>
> It looks to me like the allocators he uses all have value_types
> appropriate for the containers.
>

Well maybe I'm reading too much into this but in chpater 15 in quick
succession he gives

vector<int,SpecialAlloc> v;

map<int,float,less<int>,SpecialAlloc> m;

basic_string<char,char_traits<char>,SpecialAlloc> s;

Its not specified anywhere what SpecialAlloc is but by the quote you made
 from the standard it cannot have the correct value type for all these
different containers.

john

> Jonathan
>
>



Relevant Pages

  • Re: Ada containers and custom allocators
    ... standard storage pool). ... containers manageable. ... course it is the container which would then instantiate the allocator ... Only if you put severe limits on the implementations. ...
    (comp.lang.ada)
  • Re: size_t and size_type
    ... Denis Remezov wrote: ... > the standard allocator). ... >> In other words you cannot pass an allocator to a standard library container ... However, on yet another thought, are the standard containers required to ...
    (comp.lang.cpp)
  • Re: What would be the right decision?
    ... containers but for a class of containers, ... or all hash tables, etc. ... My suggestion would be that the choice of allocator (and you should ... to change the behavior of all lists. ...
    (comp.lang.c)
  • Re: size_t and size_type
    ... the standard allocator). ... > implementations of the standard library to assume that vector<T, ... > In other words you cannot pass an allocator to a standard library container ... containers are required to define size_type as size_t. ...
    (comp.lang.cpp)
  • Re: allocator requirements
    ... both implementations of the STL I've checked do ... This seems to directly contradict ... How does this contradict the allocator requirements? ... > several containers with different value types. ...
    (comp.lang.cpp)