allocator question (reposted here... sorry for the mistake)

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



Hi to all,

when passing an allocator to SEVERAL containers at the same time, can we
rely on the "rebind" mechanism assuming that each container is able to
select its own allocator?
for example: is the following ok?


template <class T, class allocator_t>
class MyContainer
{
std::vector<T, allocator_t> v_;
std::map<T, int, std::less<T>, allocator_t> m_;
};


or should we be verbose and deduce the correct allocators out of the
sub-containers:

template <class T, class allocator_t>
class MyContainer
{
typedef typename allocator_t::template rebind<T>::other rebind1_t;
std::vector<double, rebind1_t> v_;

typedef typename allocator_t::template rebind< std::pair<const T,
int>::other rebind2_t;
// etc...

};


of course version #1 and version #2 declare a class whose members have
different types (say, m_ is map<T,int, ... allocator<T> > and map<T,int, ...
allocator< std::pair<...> > >), but apart from that, are they "functionally"
equivalent?



.



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: 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: allocator requirements
    ... >> the allocator for vector at least. ... This seems to directly contradict ... >> several containers with different value types. ... from the standard it cannot have the correct value type for all these ...
    (comp.lang.cpp)
  • allocator question
    ... when passing an allocator to SEVERAL containers at the same time, ... template ... class MyContainer ...
    (microsoft.public.vc.language)
  • custom allocator issue
    ... We have a list derived from std::list that has a custom allocator ... so could not use the rebind struct. ... a _Charalloc function was implemented. ... allocator is taking two template parms. ...
    (microsoft.public.vc.stl)