Boost logo

Boost :

From: Jeremy Siek (jsiek_at_[hidden])
Date: 2002-01-14 13:29:38


The change you suggest is in fact the current approach we use to work
around VC++. As to whether that approach is simpler is not so clear to me.
For example, the 2nd approach requires a nested class, which could be
regarded as a complication. Overall, I'd classify this NAD ;)

On Tue, 8 Jan 2002, David Abrahams wrote:

david.> 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.
david.>
david.> For example, the docs say:
david.>
david.> 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.
david.>
david.>
david.> template <class Allocator>
david.> struct list_with_allocatorS { };
david.>
david.> namespace boost {
david.> template <class Alloc, class ValueType>
david.> struct container_gen<list_with_allocatorS<Alloc>, ValueType>
david.> {
david.> typedef typename Alloc::template rebind<ValueType>::other Allocator;
david.> typedef std::list<ValueType, Allocator> type;
david.> };
david.> }
david.> With the change I am proposing, it could read as follows:
david.> 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.
david.> template <class Alloc>
david.> struct list_with_allocatorS { template <class ValueType> struct apply {
david.> typedef typename Alloc::template rebind<ValueType>::other Allocator;
david.> typedef std::list<ValueType, Allocator> type;
david.> }; };
david.>
david.> IMO this is a considerable simplification, because it can be done entirely in the user's namespace.
david.>

----------------------------------------------------------------------
 Jeremy Siek http://php.indiana.edu/~jsiek/
 Ph.D. Student, Indiana Univ. B'ton email: jsiek_at_[hidden]
 C++ Booster (http://www.boost.org) office phone: (812) 855-3608
----------------------------------------------------------------------


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