Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/boost_1_33_1/boost/iterator/permutation_iterator.hpp @ 13

Last change on this file since 13 was 12, checked in by landauf, 17 years ago

added boost

File size: 2.1 KB
Line 
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)
7
8#ifndef BOOST_PERMUTATION_ITERATOR_HPP
9#define BOOST_PERMUTATION_ITERATOR_HPP
10
11#include <iterator>
12
13#include <boost/iterator/iterator_adaptor.hpp>
14
15
16namespace boost
17{
18
19template< class ElementIterator
20        , class IndexIterator>
21class 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>
26{
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;
31
32  friend class iterator_core_access;
33
34public:
35  permutation_iterator() : m_elt_iter() {}
36
37  explicit permutation_iterator(ElementIterator x, IndexIterator y) 
38      : super_t(y), m_elt_iter(x) {}
39
40  template<class OtherElementIterator, class OtherIndexIterator>
41  permutation_iterator(
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
45      )
46    : super_t(r.base()), m_elt_iter(r.m_elt_iter)
47  {}
48
49private:
50    typename super_t::reference dereference() const
51        { return *(m_elt_iter + *this->base()); }
52
53    ElementIterator m_elt_iter;
54};
55
56
57template <class ElementIterator, class IndexIterator>
58permutation_iterator<ElementIterator, IndexIterator> 
59make_permutation_iterator( ElementIterator e, IndexIterator i )
60{
61    return permutation_iterator<ElementIterator, IndexIterator>( e, i );
62}
63
64
65} // namespace boost
66
67#endif
Note: See TracBrowser for help on using the repository browser.