Boost logo

Boost :

Subject: Re: [boost] Metaprogrammers, all of you!
From: Sebastian Redl (sebastian.redl_at_[hidden])
Date: 2010-10-13 10:39:06


On 13.10.2010 16:15, Andrew Sutton wrote:
> On the topic of abstraction, I would say that Matt's solution seems to be
> the right approach -- from an iterator perspective. He claims that
> segmentation concepts is an orthogonal to the standard iterator concepts. I
> don't especially like the implementation, requiring an explicit
> specialization of segmented_iterator_traits. I see nothing preventing the
> segmented iterator class from defining those associated types and operations
> and allowing the traits class to use them by default.
>
Easy enough. Your class just has to contain a type called is_segmented,
definition irrelevant. But there is no way around having such a marker.
You don't want to trigger off the classical iterator tag, since that
would mean twice the number of tags.

BOOST_MPL_DEFINE_HAS_MEMBER(is_segmented)

template <typename T, bool Enable = has_is_segmented<T>::value>
struct segmented_iterator_traits {
   typedef false_type is_segmented_iterator;
};

template <typename T>
struct segmented_iterator_traits<T, true> {
   typedef true_type is_segmented_iterator;
   typedef T iterator;
   typedef typename T::segment_iterator segment_iterator;
   // ...
};

Sebastian


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