Boost logo

Boost :

From: Synge Todo (wistaria_at_[hidden])
Date: 2002-02-09 17:15:38


From: "Andrei Alexandrescu" <andrewalex_at_[hidden]>
Date: Sat, 9 Feb 2002 13:19:44 -0800
> > template<class T, class Storage = DynamicStorge<T> >
> > vector {
> > Storage storage;
> > ...
> > };
> >
> > template<class T>
> > DynamicStorage {
> > allocator<T> alloc;
> > allocate();
> > void swap(); // swapping pointer
> > ... etc
> > };
> >
> > template<class T, std::size_t N>
> > StaticStorage {
> > non_initialized_array<N> data;
> > allocate();
> > void swap(); // copying elements;
> > ... etc
> > };
>
> See above. With your approach you will have to duplicate all the Storage
> code if you want to use (1) malloc or SysAlloc instead of new (2) another
> way of storing the additional data while still using new.

Of course, I intended to parameterize the above DynamicStorage policy
class by allocator, like

template<class T, template<class> class Storage = DynamicStorage,
         template<class> class Allocator = std::allocator> class vector {
Storage<Allocator<T> > storage;
...
};
template<class Allocator> class DynamicStorage { ... };
template<class> class StaticStorage { ... };
...
vector<int, DynamicStorage, malloc_based_allocator> vec0;
vector<int, StaticStorage> vec1;

In the latest version of fixed_capacity_vector, I tried to encapsulate
storage management into vector_base class in order to hide its details
from the main class (though it was a non-portable implementation).
I believe this abstraction scheme is a good prototype to start
implementing policy-based vector class and storage policy classes.

Best regards,

Synge Todo
wistaria_at_[hidden]


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