1 // (C) Copyright Toon Knapen 2001. Permission to copy, use,
2 // modify, sell and distribute this software is granted provided this
3 // copyright notice appears in all copies. This software is provided
4 // "as is" without express or implied warranty, and with no claim as
5 // to its suitability for any purpose.
8 #ifndef boost_permutation_iterator_hpp
9 #define boost_permutation_iterator_hpp
11 #include <boost/iterator_adaptors.hpp>
15 template < typename IndexIterator >
16 struct permutation_iterator_policies : public default_iterator_policies
18 permutation_iterator_policies() {}
20 permutation_iterator_policies(IndexIterator order_it)
21 : order_it_( order_it )
24 template <class IteratorAdaptor>
25 typename IteratorAdaptor::reference dereference(const IteratorAdaptor& x) const
26 { return *(x.base() + *order_it_); }
28 template <class IteratorAdaptor>
29 void increment(IteratorAdaptor&)
32 template <class IteratorAdaptor>
33 void decrement(IteratorAdaptor&)
36 template <class IteratorAdaptor, class DifferenceType>
37 void advance(IteratorAdaptor& x, DifferenceType n)
38 { std::advance( order_it_, n ); }
40 template <class IteratorAdaptor1, class IteratorAdaptor2>
41 typename IteratorAdaptor1::difference_type
42 distance(const IteratorAdaptor1& x, const IteratorAdaptor2& y) const
43 { return std::distance( x.policies().order_it_, y.policies().order_it_ ); }
45 template <class IteratorAdaptor1, class IteratorAdaptor2>
46 bool equal(const IteratorAdaptor1& x, const IteratorAdaptor2& y) const
47 { return x.policies().order_it_ == y.policies().order_it_; }
49 IndexIterator order_it_;
52 template < typename ElementIterator, typename IndexIterator >
53 struct permutation_iterator_generator
55 typedef boost::iterator_adaptor
57 permutation_iterator_policies< IndexIterator >
61 template < class IndexIterator, class ElementIterator >
62 inline typename permutation_iterator_generator< ElementIterator, IndexIterator >::type
63 make_permutation_iterator(ElementIterator base, IndexIterator order)
65 typedef typename permutation_iterator_generator< ElementIterator, IndexIterator >::type result_t;
66 return result_t( base, order );
71 #endif // boost_permutation_iterator_hpp