Boilerplate typedefs for STL-compatible container

1.6k Views Asked by At

Is there, within the standard library or Boost, some kind of utility base class for populating a custom STL-compatible Sequence with the required typedefs (size_type, value_type, etc...). I'm thinking of something like boost::iterator_facade, but for containers.

I was going to roll-up my own, but wanted to make sure such a thing didn't already exist.

UPDATE:

This is the utility base class I came up with, in case anybody finds it useful:

template <class C>
class ContainerAdapter
{
public:
    typedef C::value_type value_type;
    typedef C::reference reference;
    typedef C::const_reference const_reference;
    typedef C::const_iterator iterator;
    typedef C::const_iterator const_iterator;
    typedef C::difference_type difference_type;
    typedef C::size_type size_type;

protected:
    typedef C::container_type;
};


// Usage
class MyCustomContainer : public ContainerAdapter< std::vector<int> >
{
...
};

ContainerAdapter simply "echoes" the nested typedefs of a custom container's underlying container. There's nothing to it, really.

1

There are 1 best solutions below

4
On BEST ANSWER

even if it does exist, you still have to typedef typename base::size_type size_type. does not seem you would gain much.