paludis  Version 2.6.0
member_iterator.hh
1 /* vim: set sw=4 sts=4 et foldmethod=syntax : */
2 
3 /*
4  * Copyright (c) 2007, 2008, 2009 Ciaran McCreesh
5  * Copyright (c) 2007 David Leverton
6  *
7  * This file is part of the Paludis package manager. Paludis is free software;
8  * you can redistribute it and/or modify it under the terms of the GNU General
9  * Public License version 2, as published by the Free Software Foundation.
10  *
11  * Paludis is distributed in the hope that it will be useful, but WITHOUT ANY
12  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13  * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
14  * details.
15  *
16  * You should have received a copy of the GNU General Public License along with
17  * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
18  * Place, Suite 330, Boston, MA 02111-1307 USA
19  */
20 
21 #ifndef PALUDIS_GUARD_PALUDIS_UTIL_MEMBER_ITERATOR_HH
22 #define PALUDIS_GUARD_PALUDIS_UTIL_MEMBER_ITERATOR_HH 1
23 
24 #include <paludis/util/member_iterator-fwd.hh>
25 #include <paludis/util/operators.hh>
26 #include <type_traits>
27 
28 namespace paludis
29 {
30  template <typename Iterator_>
31  struct FirstIteratorTypes
32  {
33  typedef MemberIterator<
34  typename std::remove_reference<typename std::iterator_traits<Iterator_>::value_type>::type::first_type,
35  Iterator_,
36  &std::remove_reference<typename std::iterator_traits<Iterator_>::value_type>::type::first>
37  Type;
38  };
39 
40  template <typename Iterator_>
41  struct SecondIteratorTypes
42  {
43  typedef MemberIterator<
44  typename std::remove_reference<typename std::iterator_traits<Iterator_>::value_type>::type::second_type,
45  Iterator_,
46  &std::remove_reference<typename std::iterator_traits<Iterator_>::value_type>::type::second>
47  Type;
48  };
49 
50  /**
51  * A MemberIterator is a wrapper around a forward iterator to a struct,
52  * selecting one particular member of that struct for the value.
53  *
54  * \ingroup g_iterator
55  * \since 0.26
56  */
57  template <typename Value_, typename Iterator_,
58  Value_ std::remove_reference<typename std::iterator_traits<Iterator_>::value_type>::type::* member_>
59  class MemberIterator :
60  public equality_operators::HasEqualityOperators
61  {
62  private:
63  Iterator_ _iter;
64 
65  public:
66  ///\name Basic operations
67  ///\{
68 
69  MemberIterator();
70  MemberIterator(const MemberIterator &);
71  MemberIterator(const Iterator_ &);
72 
73  MemberIterator & operator= (const MemberIterator &);
74 
75  ///\}
76 
77  ///\name Standard library typedefs
78  ///\{
79 
80  typedef typename std::remove_const<typename std::remove_reference<Value_>::type>::type value_type;
81  typedef const typename std::remove_reference<Value_>::type & reference;
82  typedef const typename std::remove_reference<Value_>::type * pointer;
83  typedef std::ptrdiff_t difference_type;
84  typedef std::forward_iterator_tag iterator_category;
85 
86  ///\}
87 
88  ///\name Increment
89  ///\{
90 
91  MemberIterator & operator++ ();
92  MemberIterator operator++ (int);
93 
94  ///\}
95 
96  ///\name Dereference
97  ///\{
98 
99  pointer operator-> () const;
100  reference operator* () const;
101 
102  ///\}
103 
104  ///\name Equality
105  ///\{
106 
107  bool operator== (const MemberIterator &) const;
108 
109  ///\}
110  };
111 }
112 
113 #endif
Definition: about_metadata-fwd.hh:23
bool operator==(const PackageID &, const PackageID &) PALUDIS_ATTRIBUTE((warn_unused_result)) PALUDIS_VISIBLE