1 // (C) Copyright Toon Knapen 2001.
\r
2 // (C) Copyright David Abrahams 2003.
\r
3 // (C) Copyright Roland Richter 2003.
\r
4 // Distributed under the Boost Software License, Version 1.0. (See
\r
5 // accompanying file LICENSE_1_0.txt or copy at
\r
6 // http://www.boost.org/LICENSE_1_0.txt)
\r
8 #ifndef BOOST_PERMUTATION_ITERATOR_HPP
\r
9 #define BOOST_PERMUTATION_ITERATOR_HPP
\r
13 #include <boost/iterator/iterator_adaptor.hpp>
\r
19 template< class ElementIterator
\r
20 , class IndexIterator>
\r
21 class permutation_iterator
\r
22 : public iterator_adaptor<
\r
23 permutation_iterator<ElementIterator, IndexIterator>
\r
24 , IndexIterator, typename detail::iterator_traits<ElementIterator>::value_type
\r
25 , use_default, typename detail::iterator_traits<ElementIterator>::reference>
\r
27 typedef iterator_adaptor<
\r
28 permutation_iterator<ElementIterator, IndexIterator>
\r
29 , IndexIterator, typename detail::iterator_traits<ElementIterator>::value_type
\r
30 , use_default, typename detail::iterator_traits<ElementIterator>::reference> super_t;
\r
32 friend class iterator_core_access;
\r
35 permutation_iterator() : m_elt_iter() {}
\r
37 explicit permutation_iterator(ElementIterator x, IndexIterator y)
\r
38 : super_t(y), m_elt_iter(x) {}
\r
40 template<class OtherElementIterator, class OtherIndexIterator>
\r
41 permutation_iterator(
\r
42 permutation_iterator<OtherElementIterator, OtherIndexIterator> const& r
\r
43 , typename enable_if_convertible<OtherElementIterator, ElementIterator>::type* = 0
\r
44 , typename enable_if_convertible<OtherIndexIterator, IndexIterator>::type* = 0
\r
46 : super_t(r.base()), m_elt_iter(r.m_elt_iter)
\r
50 typename super_t::reference dereference() const
\r
51 { return *(m_elt_iter + *this->base()); }
\r
53 #ifndef BOOST_NO_MEMBER_TEMPLATE_FRIENDS
\r
54 template <class,class> friend class permutation_iterator;
\r
58 ElementIterator m_elt_iter;
\r
62 template <class ElementIterator, class IndexIterator>
\r
63 permutation_iterator<ElementIterator, IndexIterator>
\r
64 make_permutation_iterator( ElementIterator e, IndexIterator i )
\r
66 return permutation_iterator<ElementIterator, IndexIterator>( e, i );
\r
70 } // namespace boost
\r