Boost logo

Boost :

From: Lie-Quan Lee (llee_at_[hidden])
Date: 2002-01-09 12:17:03


On Tue, 2002-01-08 at 20:59, David Abrahams wrote:
> The scheme used by BGL for selecting the component containers of adjacency_list seems to have an extra, needless level of indirection. Why bother with the traits at all? It seems to me that VecS et. al. could be generators themselves.
>
> For example, the docs say:
>
> There may also be situations when you want to use a container that has more template parameters than just ValueType. For instance, you may want to supply the allocator type. One way to do this is to hard-code in the extra parameters within the specialization of container_gen. However, if you want more flexibility then you can add a template parameter to the selector class. In the code below we show how to create a selector that lets you specify the allocator to be used with the std::list.
>
>
> template <class Allocator>
> struct list_with_allocatorS { };
>
> namespace boost {
> template <class Alloc, class ValueType>
> struct container_gen<list_with_allocatorS<Alloc>, ValueType>
> {
> typedef typename Alloc::template rebind<ValueType>::other Allocator;
> typedef std::list<ValueType, Allocator> type;
> };
> }
> With the change I am proposing, it could read as follows:
> There may also be situations when you want to use a container that has more template parameters than just ValueType. For instance, you may want to supply the allocator type. In the code below we show how to create a selector that lets you specify the allocator to be used with the std::list.
> template <class Alloc>
> struct list_with_allocatorS { template <class ValueType> struct apply {
> typedef typename Alloc::template rebind<ValueType>::other Allocator;
> typedef std::list<ValueType, Allocator> type;
> }; };
>
> IMO this is a considerable simplification, because it can be done entirely in the user's namespace.

With the current method of selecting component containers in BGL, if you
want to use your own allocator into component conainers, you define your
own selector. For example:

struct my_vecS {};
template <class ValueType>
struct container_gen<my_vecS, ValueType> {
   typedef std::vector<ValueType, MyOwnAllocator> type;
};

This is simpler to users. Right?

-- 
Lie-Quan Lee (AKA: Rich Lee)
Research Associate                   
Open Systems Laboratory        Phone:    1-812-855-3608
Computer Science Department    Email:    llee_at_[hidden]
Indiana University             Homepage: http://www.osl.iu.edu/~llee

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