Boost logo

Boost :

From: Jason Hise (chaos_at_[hidden])
Date: 2005-01-18 19:18:10


Pavel Vozenilek wrote:

>"Jason Hise" wrote:
>
>
>>I was thinking about the simpler standard containers... specifically
>>vector, deque, and list, and wondering... would there be any value in
>>making a generic linear_container class which uses policies to define the
>>allocation and iteration methods? Specifically, I imagine something like
>>this:
>>
>>typedef linear_container < contiguous_iterator, alloc_using_new > vector;
>>typedef linear_container < double_linked_iterator, alloc_using_new > list;
>>// etc...
>>
>>The iterator itself could probably be broken down into smaller traits, but
>>the idea is that this would make it much easier to add new types of
>>containers or mix and match existing functionality. Through the
>>linear_container it would be easy to ensure that all types of containers
>>had the same interface (push_back, pop_back, etc...) Thoughts/opinion?
>>
>>
>>
>Maybe Boost.Multi Index Container is what you are looking for.
>/Pavel
>
Not quite. I'm not looking for multiple ways to look at the underlying
data. Instead, I'm looking to specify how the underlying data is stored
and manipulated via traits instead of having the means hard-coded into
separate containers. Let me see if I can come up with a better code
demonstration;

template < typename T, template < typename > class Iterator, template <
typename > class Allocator >
class LinearContainer
{
public:
    typedef Iterator < T > :: iterator iterator;
    typedef Iterator < T > :: const_iterator const_iterator;

    iterator begin() { ... }
    const_iterator begin() const { ... }
    // all the other handy functions that are provided by any standard
containers
    // what the iterator supports determines which available functions
will compile
    // (insert, push_front, etc...)
};

// all of the details about how a vector specifically works go in here
template < typename T >
class VectorIterator
{
    class iterator
    {
    };

    class const_iterator
    {
    };
};

Algorithms would then work with any type of LinearContainer that has
traits supporting the operations required. On further speculation this
may not be a useful thing to do, because it just moves the implied
interface from between the algorithms and the containers (push_back,
insert, etc...) to between the container and its traits. Oh well, I was
just thinking out loud.

-Jason


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk