paludis  Version 2.6.0
indirect_iterator.hh
1 /* vim: set sw=4 sts=4 et foldmethod=syntax : */
2 
3 /*
4  * Copyright (c) 2007, 2008, 2011 Ciaran McCreesh
5  *
6  * This file is part of the Paludis package manager. Paludis is free software;
7  * you can redistribute it and/or modify it under the terms of the GNU General
8  * Public License version 2, as published by the Free Software Foundation.
9  *
10  * Paludis is distributed in the hope that it will be useful, but WITHOUT ANY
11  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12  * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
13  * details.
14  *
15  * You should have received a copy of the GNU General Public License along with
16  * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
17  * Place, Suite 330, Boston, MA 02111-1307 USA
18  */
19 
20 #ifndef PALUDIS_GUARD_PALUDIS_UTIL_INDIRECT_ITERATOR_HH
21 #define PALUDIS_GUARD_PALUDIS_UTIL_INDIRECT_ITERATOR_HH 1
22 
23 #include <paludis/util/indirect_iterator-fwd.hh>
24 #include <paludis/util/operators.hh>
25 #include <memory>
26 #include <functional>
27 #include <type_traits>
28 
29 namespace paludis
30 {
31  template <typename T_>
32  struct IndirectIteratorValueType
33  {
34  typedef typename std::iterator_traits<T_>::value_type Type;
35  };
36 
37  template <typename T_>
39  {
40  typedef T_ Type;
41  };
42 
43  template <typename T_>
44  struct IndirectIteratorValueType<std::shared_ptr<T_> >
45  {
46  typedef T_ Type;
47  };
48 
49  template <typename T_>
50  struct IndirectIteratorValueType<std::shared_ptr<const T_> >
51  {
52  typedef const T_ Type;
53  };
54 
55  template <typename T_>
56  struct IndirectIteratorValueType<const T_>
57  {
58  typedef typename IndirectIteratorValueType<T_>::Type Type;
59  };
60 
61  template <typename T_>
63  {
64  typedef typename IndirectIteratorValueType<T_>::Type Type;
65  };
66 
67  /**
68  * An IndirectIterator turns an iterator over T_ * or std::shared_ptr<T_> into an iterator
69  * over T_.
70  *
71  * \ingroup g_iterator
72  * \see indirect_iterator
73  */
74  template <typename Iter_, typename Value_>
75  class IndirectIterator :
77  {
78  friend bool operator== <> (const IndirectIterator &, const IndirectIterator &);
79  friend bool operator< <> (const IndirectIterator &, const IndirectIterator &);
80 
81  private:
82  Iter_ _iter;
83 
84  public:
85  ///\name Basic operations
86  ///\{
87 
90  IndirectIterator(const Iter_ &);
91 
92  IndirectIterator & operator= (const IndirectIterator &);
93 
94  ///\}
95 
96  ///\name Standard library typedefs
97  ///\{
98 
99  typedef typename std::remove_reference<Value_>::type & value_type;
100  typedef typename std::remove_reference<Value_>::type & reference;
101  typedef typename std::remove_reference<Value_>::type * pointer;
102  typedef std::ptrdiff_t difference_type;
103  typedef std::forward_iterator_tag iterator_category;
104 
105  ///\}
106 
107  ///\name Additional typedefs
108  ///\{
109 
110  typedef Iter_ underlying_iterator_type;
111 
112  ///\}
113 
114  ///\name Increment
115  ///\{
116 
117  IndirectIterator & operator++ ();
118  IndirectIterator operator++ (int);
119 
120  ///\}
121 
122  ///\name Dereference
123  ///\{
124 
125  pointer operator-> () const;
126  reference operator* () const;
127 
128  underlying_iterator_type underlying_iterator();
129 
130  ///\}
131  };
132 
133  /**
134  * Construct an IndirectIterator from another iterator.
135  *
136  * \see IndirectIterator
137  * \ingroup g_iterator
138  */
139  template <typename Iter_>
141 }
142 
143 #endif
Definition: about_metadata-fwd.hh:23
IndirectIterator< Iter_ > indirect_iterator(const Iter_ &)
STL namespace.
Definition: indirect_iterator-fwd.hh:28
Definition: indirect_iterator-fwd.hh:32