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