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.
They are implemented as class templates, which allows great flexibility in the types supported as elements. The container manages the storage space for its elements and provides member functions to access them, either directly or through iterators (reference objects with similar properties to pointers).
std::vector always has its buffer allocated on heap. So regardless of where the vector itself is allocated resizing it will only affect the heap.
even if it does exist, you still have to typedef typename base::size_type size_type
.
does not seem you would gain much.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With