Logo ROOT  
Reference Guide
RIndexIter.hxx
Go to the documentation of this file.
1 /// \file ROOT/RIndexIter.hxx
2 /// \ingroup Base ROOT7
3 /// \author Axel Naumann <axel@cern.ch>
4 /// \date 2016-01-19
5 /// \warning This is part of the ROOT 7 prototype! It will change without notice. It might trigger earthquakes. Feedback
6 /// is welcome!
7 
8 /*************************************************************************
9  * Copyright (C) 1995-2016, Rene Brun and Fons Rademakers. *
10  * All rights reserved. *
11  * *
12  * For the licensing terms see $ROOTSYS/LICENSE. *
13  * For the list of contributors see $ROOTSYS/README/CREDITS. *
14  *************************************************************************/
15 
16 #ifndef ROOT7_RIndexIter
17 #define ROOT7_RIndexIter
18 
19 #include <iterator>
20 
21 namespace ROOT {
22 namespace Experimental {
23 namespace Internal {
24 
25 /**
26  \class RIndexIter
27  Iterates over an index; the REFERENCE is defined by the REFERENCE template parameter.
28 
29  Derived classes are expected to implement `const REFERENCE& operator*()` and
30  `const POINTER operator->()`.
31  */
32 
33 template <class REFERENCE,
35 class RIndexIter: public std::iterator<std::random_access_iterator_tag, REFERENCE, POINTER> {
36  size_t fIndex;
37 
38 protected:
39  static constexpr size_t fgEndIndex = (size_t)-1;
40 
41 public:
42  RIndexIter(size_t idx): fIndex(idx) {}
43 
44  /// Get the current index value.
45  size_t GetIndex() const noexcept { return fIndex; }
46 
47  ///\{
48  ///\name Index modifiers
49  /// ++i
50  RIndexIter &operator++() noexcept
51  {
52  ++fIndex;
53  return *this;
54  }
55 
56  /// --i
57  RIndexIter &operator--() noexcept
58  {
59  if (fIndex != fgEndIndex)
60  --fIndex;
61  return *this;
62  }
63 
64  /// i++
65  RIndexIter operator++(int)noexcept
66  {
67  RIndexIter old(*this);
68  ++(*this);
69  return old;
70  }
71 
72  // i--
73  RIndexIter operator--(int)noexcept
74  {
75  RIndexIter old(*this);
76  --(*this);
77  return old;
78  }
79 
80  RIndexIter &operator+=(int d) noexcept
81  {
82  fIndex += d;
83  return *this;
84  }
85 
86  RIndexIter &operator-=(int d) noexcept
87  {
88  if (d > fIndex) {
90  } else {
91  fIndex -= d;
92  }
93  return *this;
94  }
95 
96  RIndexIter operator+(int d) noexcept
97  {
98  RIndexIter ret(*this);
99  ret += d;
100  return ret;
101  }
102 
103  RIndexIter operator-(int d) noexcept
104  {
105  RIndexIter ret(*this);
106  ret -= d;
107  return ret;
108  }
109  ///\}
110 };
111 
112 ///\{
113 ///\name Relational operators.
114 template <class REFERENCE, class POINTER>
116 {
117  return lhs.GetIndex() < rhs.GetIndex();
118 }
119 
120 template <class REFERENCE, class POINTER>
122 {
123  return lhs.GetIndex() > rhs.GetIndex();
124 }
125 
126 template <class REFERENCE, class POINTER>
128 {
129  return lhs.GetIndex() <= rhs.GetIndex();
130 }
131 
132 template <class REFERENCE, class POINTER>
134 {
135  return lhs.GetIndex() >= rhs.GetIndex();
136 }
137 
138 template <class REFERENCE, class POINTER>
140 {
141  return lhs.GetIndex() == rhs.GetIndex();
142 }
143 
144 template <class REFERENCE, class POINTER>
146 {
147  return lhs.GetIndex() != rhs.GetIndex();
148 }
149 ///\}
150 
151 } // namespace Internal
152 } // namespace Experimental
153 } // namespace ROOT
154 
155 #endif // ROOT7_RIndexIter
ROOT::Experimental::Internal::operator>
bool operator>(RIndexIter< REFERENCE, POINTER > lhs, RIndexIter< REFERENCE, POINTER > rhs) noexcept
Definition: RIndexIter.hxx:121
ROOT::Experimental::Internal::operator<=
bool operator<=(RIndexIter< REFERENCE, POINTER > lhs, RIndexIter< REFERENCE, POINTER > rhs) noexcept
Definition: RIndexIter.hxx:127
ROOT::Experimental::Internal::RIndexIter
Iterates over an index; the REFERENCE is defined by the REFERENCE template parameter.
Definition: RIndexIter.hxx:35
ROOT::Experimental::Internal::RIndexIter::fIndex
size_t fIndex
Definition: RIndexIter.hxx:36
ROOT::Experimental::Internal::RIndexIter::operator++
RIndexIter operator++(int) noexcept
i++
Definition: RIndexIter.hxx:65
ROOT::Experimental::Internal::RIndexIter::operator-=
RIndexIter & operator-=(int d) noexcept
Definition: RIndexIter.hxx:86
ROOT::Experimental::Internal::RIndexIter::fgEndIndex
static constexpr size_t fgEndIndex
Definition: RIndexIter.hxx:39
ROOT::Experimental::Internal::operator>=
bool operator>=(RIndexIter< REFERENCE, POINTER > lhs, RIndexIter< REFERENCE, POINTER > rhs) noexcept
Definition: RIndexIter.hxx:133
ROOT::Experimental::Internal::RIndexIter::operator--
RIndexIter operator--(int) noexcept
Definition: RIndexIter.hxx:73
ROOT::Experimental::Internal::operator==
bool operator==(RIndexIter< REFERENCE, POINTER > lhs, RIndexIter< REFERENCE, POINTER > rhs) noexcept
Definition: RIndexIter.hxx:139
ROOT::Experimental::Internal::operator<
bool operator<(RIndexIter< REFERENCE, POINTER > lhs, RIndexIter< REFERENCE, POINTER > rhs) noexcept
Definition: RIndexIter.hxx:115
ROOT::Experimental::Internal::RIndexIter::RIndexIter
RIndexIter(size_t idx)
Definition: RIndexIter.hxx:42
ROOT::Experimental::Internal::RIndexIter::operator+=
RIndexIter & operator+=(int d) noexcept
Definition: RIndexIter.hxx:80
ROOT::Experimental::Internal::RIndexIter::operator++
RIndexIter & operator++() noexcept
Definition: RIndexIter.hxx:50
d
#define d(i)
Definition: RSha256.hxx:102
ROOT::Experimental::Internal::RIndexIter::operator+
RIndexIter operator+(int d) noexcept
Definition: RIndexIter.hxx:96
ROOT::Experimental::Internal::RIndexIter::GetIndex
size_t GetIndex() const noexcept
Get the current index value.
Definition: RIndexIter.hxx:45
ROOT::Experimental::Internal::RIndexIter::operator--
RIndexIter & operator--() noexcept
–i
Definition: RIndexIter.hxx:57
ROOT::Experimental::Internal::RIndexIter::operator-
RIndexIter operator-(int d) noexcept
Definition: RIndexIter.hxx:103
type
int type
Definition: TGX11.cxx:121
ROOT::Experimental::Internal::operator!=
bool operator!=(RIndexIter< REFERENCE, POINTER > lhs, RIndexIter< REFERENCE, POINTER > rhs) noexcept
Definition: RIndexIter.hxx:145
ROOT
VSD Structures.
Definition: StringConv.hxx:21