Logo ROOT   6.18/05
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
21namespace ROOT {
22namespace Experimental {
23namespace 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
33template <class REFERENCE,
35class RIndexIter: public std::iterator<std::random_access_iterator_tag, REFERENCE, POINTER> {
36 size_t fIndex;
37
38protected:
39 static constexpr size_t fgEndIndex = (size_t)-1;
40
41public:
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
51 {
52 ++fIndex;
53 return *this;
54 }
55
56 /// --i
58 {
59 if (fIndex != fgEndIndex)
60 --fIndex;
61 return *this;
62 }
63
64 /// i++
66 {
67 RIndexIter old(*this);
68 ++(*this);
69 return old;
70 }
71
72 // i--
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.
114template <class REFERENCE, class POINTER>
116{
117 return lhs.GetIndex() < rhs.GetIndex();
118}
119
120template <class REFERENCE, class POINTER>
122{
123 return lhs.GetIndex() > rhs.GetIndex();
124}
125
126template <class REFERENCE, class POINTER>
128{
129 return lhs.GetIndex() <= rhs.GetIndex();
130}
131
132template <class REFERENCE, class POINTER>
134{
135 return lhs.GetIndex() >= rhs.GetIndex();
136}
137
138template <class REFERENCE, class POINTER>
140{
141 return lhs.GetIndex() == rhs.GetIndex();
142}
143
144template <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
#define d(i)
Definition: RSha256.hxx:102
int type
Definition: TGX11.cxx:120
Iterates over an index; the REFERENCE is defined by the REFERENCE template parameter.
Definition: RIndexIter.hxx:35
RIndexIter & operator--() noexcept
–i
Definition: RIndexIter.hxx:57
RIndexIter & operator-=(int d) noexcept
Definition: RIndexIter.hxx:86
RIndexIter & operator++() noexcept
Definition: RIndexIter.hxx:50
RIndexIter operator--(int) noexcept
Definition: RIndexIter.hxx:73
RIndexIter operator+(int d) noexcept
Definition: RIndexIter.hxx:96
static constexpr size_t fgEndIndex
Definition: RIndexIter.hxx:39
size_t GetIndex() const noexcept
Get the current index value.
Definition: RIndexIter.hxx:45
RIndexIter & operator+=(int d) noexcept
Definition: RIndexIter.hxx:80
RIndexIter operator-(int d) noexcept
Definition: RIndexIter.hxx:103
RIndexIter operator++(int) noexcept
i++
Definition: RIndexIter.hxx:65
bool operator<(RIndexIter< REFERENCE, POINTER > lhs, RIndexIter< REFERENCE, POINTER > rhs) noexcept
Definition: RIndexIter.hxx:115
bool operator<=(RIndexIter< REFERENCE, POINTER > lhs, RIndexIter< REFERENCE, POINTER > rhs) noexcept
Definition: RIndexIter.hxx:127
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:139
bool operator>(RIndexIter< REFERENCE, POINTER > lhs, RIndexIter< REFERENCE, POINTER > rhs) noexcept
Definition: RIndexIter.hxx:121
bool operator>=(RIndexIter< REFERENCE, POINTER > lhs, RIndexIter< REFERENCE, POINTER > rhs) noexcept
Definition: RIndexIter.hxx:133
Namespace for new ROOT classes and functions.
Definition: StringConv.hxx:21