diff --git a/iterator_adaptors.htm b/iterator_adaptors.htm index 8f6323c..dcfa62e 100644 --- a/iterator_adaptors.htm +++ b/iterator_adaptors.htm @@ -13,7 +13,9 @@ align="center" width="277" height="86">
The file boost/iterator_adaptors.hpp includes the main iterator_adaptors class and several other classes @@ -26,6 +28,13 @@ for constructing commonly used iterator adaptors.
The file boost/integer_range.hpp includes a class that + uses iterator adaptors to create an iterator that increments over a + range of integers. The file also includes a "container" type + that creates a container-interface for the range of integers. +
@@ -168,12 +177,11 @@ constructors. This is the class used inside of the iterator_adaptors type generator. Use this class directly (instead of using -iterator_adaptors) when there is no difference between the -const and non-const versions of the iterator type. Often this is -because there is only a const (read-only) version of the iterator, as -is the case for std::set's iterators. Use the same type for -the Iterator and NonconstIterator template -arguments. +iterator_adaptors) when you are interested in creating only +one of the iterator types (either const or non-const) or when there is +no difference between the const and non-const versions of the iterator +type (often this is because there is only a const (read-only) version +of the iterator, as is the case for std::set's iterators).
++template <class Pair> +struct select1st_ + : public std::unary_function<Pair, typename Pair::first_type> +{ + const typename Pair::first_type& operator()(const Pair& x) const { + return x.first; + } + typename Pair::first_type& operator()(Pair& x) const { + return x.first; + } +}; + |
+
++template <class AdaptableUnaryFunction> +struct projection_iterator_policies : public default_iterator_policies +{ + projection_iterator_policies() { } + projection_iterator_policies(const AdaptableUnaryFunction& f) : m_f(f) { } + + template <class Reference, class Iterator> + Reference dereference (type<Reference>, Iterator const& iter) const { + return m_f(*iter); + } + + AdaptableUnaryFunction m_f; +}; + |
+
++template <class AdaptableUnaryFunction, class Traits> +struct projection_iterator_traits { + typedef typename AdaptableUnaryFunction::result_type value_type; + typedef value_type& reference; + typedef value_type* pointer; + typedef typename Traits::difference_type difference_type; + typedef typename Traits::iterator_category iterator_category; +}; + +template <class AdaptableUnaryFunction, class Traits> +struct const_projection_iterator_traits { + typedef typename AdaptableUnaryFunction::result_type value_type; + typedef value_type const& reference; + typedef value_type const* pointer; + typedef typename Traits::difference_type difference_type; + typedef typename Traits::iterator_category iterator_category; +}; + |
+
++template <class AdaptableUnaryFunction, class Iterator, + class Traits = std::iterator_traits<Iterator> + > +struct projection_iterator { + typedef projection_iterator_traits<AdaptableUnaryFunction, Traits> + Projection_Traits; + typedef iterator_adaptor<Iterator, + projection_iterator_policies<AdaptableUnaryFunction>, + Projection_Traits> type; +}; + +template <class AdaptableUnaryFunction, class Iterator, + class Traits = std::iterator_traits<Iterator> + > +struct const_projection_iterator { + typedef const_projection_iterator_traits<AdaptableUnaryFunction, + Traits> Projection_Traits; + typedef iterator_adaptor<Iterator, + projection_iterator_policies<AdaptableUnaryFunction>, + Projection_Traits> type; +}; + +template <class AdaptableUnaryFunction, class Iterator, class ConstIterator, + class Traits = std::iterator_traits<Iterator>, + class ConstTraits = std::iterator_traits<ConstIterator> + > +struct projection_iterators { + typedef projection_iterator_traits<AdaptableUnaryFunction, Traits> + Projection_Traits; + typedef const_projection_iterator_traits<AdaptableUnaryFunction, + ConstTraits> Const_Projection_Traits; + typedef iterator_adaptors<Iterator, ConstIterator, + Projection_Traits, Const_Projection_Traits, + projection_iterator_policies<AdaptableUnaryFunction> > Adaptors; + typedef typename Adaptors::iterator iterator; + typedef typename Adaptors::const_iterator const_iterator; +}; + |
+template <class IntegerType> struct counting_iterator_policies : public default_iterator_policies { - template <class IntegerType> IntegerType dereference(type<IntegerType>, const IntegerType& i) const { return i; } }; |