Proposal for std::vector.

Gabriel Dos Reis gdr@integrable-solutions.net
Tue Feb 10 02:29:00 GMT 2004


Matt Austern <austern@apple.com> writes:

| I'm afraid you're right too.  Fortunately, I really do only mean "a
| bit" more
| complicated.  The solution is pretty simple: instead of inheriting
| directly
| from the allocator, instead inherit from a thin wrapper class that
| provides
| nothing but the allocator functions we care about.


Just to make sure I understand your suggestion.  In doing so, how do
we prevent the "virtual function is a sin you inherit from your
descendents" syndrom and benefit at the same time from the empty base
optimization? 

The solution I'm thinking of would be:

  template<class Allocator>
    WrapAllocator {
       Allocator allocator;
       // standard allocator interface goes here 
       // as forwarding functions to Allocator
       // ...
    };

  template<class T, class Allocator = allocator<T> >
    struct vector : private WrapAllocator<Allocator> {
      // ...
    };

Is that what you're alluding to?

-- Gaby



More information about the Libstdc++ mailing list