Logo ROOT   master
Reference Guide
RIndexIter.hxx
Go to the documentation of this file.
1 /// \file ROOT/RIndexIter.h
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>
115 bool operator<(RIndexIter<REFERENCE, POINTER> lhs, RIndexIter<REFERENCE, POINTER> rhs) noexcept
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>
127 bool operator<=(RIndexIter<REFERENCE, POINTER> lhs, RIndexIter<REFERENCE, POINTER> rhs) noexcept
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
Iterates over an index; the REFERENCE is defined by the REFERENCE template parameter.
Definition: RIndexIter.hxx:35
Returns the available number of logical cores.
Definition: RNumpyDS.hxx:30
bool operator==(RIndexIter< REFERENCE, POINTER > lhs, RIndexIter< REFERENCE, POINTER > rhs) noexcept
Definition: RIndexIter.hxx:139
RIndexIter operator-(int d) noexcept
Definition: RIndexIter.hxx:103
static constexpr size_t fgEndIndex
Definition: RIndexIter.hxx:39
bool operator!=(RIndexIter< REFERENCE, POINTER > lhs, RIndexIter< REFERENCE, POINTER > rhs) noexcept
Definition: RIndexIter.hxx:145
bool operator>=(RIndexIter< REFERENCE, POINTER > lhs, RIndexIter< REFERENCE, POINTER > rhs) noexcept
Definition: RIndexIter.hxx:133
bool operator>(RIndexIter< REFERENCE, POINTER > lhs, RIndexIter< REFERENCE, POINTER > rhs) noexcept
Definition: RIndexIter.hxx:121
RIndexIter operator--(int) noexcept
Definition: RIndexIter.hxx:73
RIndexIter & operator++() noexcept
Definition: RIndexIter.hxx:50
size_t GetIndex() const noexcept
Get the current index value.
Definition: RIndexIter.hxx:45
RIndexIter & operator-=(int d) noexcept
Definition: RIndexIter.hxx:86
#define d(i)
Definition: RSha256.hxx:102
RIndexIter operator+(int d) noexcept
Definition: RIndexIter.hxx:96
int type
Definition: TGX11.cxx:120
RIndexIter & operator+=(int d) noexcept
Definition: RIndexIter.hxx:80
RIndexIter operator++(int) noexcept
i++
Definition: RIndexIter.hxx:65
RIndexIter & operator--() noexcept
–i
Definition: RIndexIter.hxx:57