Boost logo

Boost :

From: David Abrahams (david.abrahams_at_[hidden])
Date: 2002-01-08 20:59:34


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.

=================================================== David Abrahams, C++ library designer for hire resume: http://users.rcn.com/abrahams/resume.html

        C++ Booster (http://www.boost.org)
          email: david.abrahams_at_[hidden]
===================================================



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