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