Circumventing __USE_MALLOC and templatized containers

Wolfgang Bangerth wolfgang.bangerth@iwr.uni-heidelberg.de
Fri Nov 16 08:28:00 GMT 2001


> >   template <typename T>
> >     class my_vector : public std::vector<T, some_allocator>
> >     { };
> > 
> > This is a bad idea, obviously. What then is the suggested way to have
> 
> This is how I've been doing it whenever I needed a templated
> typedef.  Why is it a bad idea?

Because one would have to clone all constructors of std::vector/map/set/...
and maybe also assignment operators. 

Second, one would have to have a copy constructor from std::vector<T,A> to
my_vector<T>, since there might be functions not under my control that
take std::vector<T,A>, but also return std::vector<T,A>. In order to be
able to work with my_vector only (after all, it's invention was to _not_
have to use the long form std::vector<T,A>), one would like to copy the
result of such functions to my_vector. This, then involves a deep copy of
the data, unfortunately.

Third, there are libraries of which the sources are available, but which
only work with std::vector<T>, i.e. they do not templatize on the
allocator type. These would need to be fixed, but as these libs are not
under our control, this is somewhat tedious to maintain.

Fourth, but I may be wrong, I think that none of the other allocator's
name is standardized, so selecting one by deriving another class is non-
portable across different compilers. (Though this indeed is the least
difficult thing to work around.)

So while I understand the concerns that led to the deprecation of
__USE_MALLOC, it makes the new scheme significantly more complicated to
use. That's why I asked how people solve these problems?

Best regards
  Wolfgang

-------------------------------------------------------------------------
Wolfgang Bangerth          email: wolfgang.bangerth@iwr.uni-heidelberg.de
                             www: http://gaia.iwr.uni-heidelberg.de/~wolf





More information about the Libstdc++ mailing list