简体   繁体   中英

Boilerplate typedefs for STL-compatible container

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM