Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
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
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,
34 class POINTER = typename std::add_pointer<typename std::remove_reference<REFERENCE>::type>::type>
36 size_t fIndex;
37
38protected:
39 static constexpr size_t fgEndIndex = (size_t)-1;
40
41public:
42 using iterator_category = std::random_access_iterator_tag;
43 using value_type = typename std::remove_reference<REFERENCE>::type;
44 using difference_type = std::ptrdiff_t;
45 using pointer = POINTER;
46 using reference = REFERENCE;
47
48 RIndexIter(size_t idx): fIndex(idx) {}
49
50 /// Get the current index value.
51 size_t GetIndex() const noexcept { return fIndex; }
52
53 ///\{
54 ///\name Index modifiers
55 /// ++i
57 {
58 ++fIndex;
59 return *this;
60 }
61
62 /// --i
64 {
65 if (fIndex != fgEndIndex)
66 --fIndex;
67 return *this;
68 }
69
70 /// i++
72 {
73 RIndexIter old(*this);
74 ++(*this);
75 return old;
76 }
77
78 // i--
80 {
81 RIndexIter old(*this);
82 --(*this);
83 return old;
84 }
85
86 RIndexIter &operator+=(int d) noexcept
87 {
88 fIndex += d;
89 return *this;
90 }
91
92 RIndexIter &operator-=(int d) noexcept
93 {
94 if (d > fIndex) {
96 } else {
97 fIndex -= d;
98 }
99 return *this;
100 }
101
102 RIndexIter operator+(int d) noexcept
103 {
104 RIndexIter ret(*this);
105 ret += d;
106 return ret;
107 }
108
109 RIndexIter operator-(int d) noexcept
110 {
111 RIndexIter ret(*this);
112 ret -= d;
113 return ret;
114 }
115 ///\}
116};
117
118///\{
119///\name Relational operators.
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
150template <class REFERENCE, class POINTER>
152{
153 return lhs.GetIndex() != rhs.GetIndex();
154}
155///\}
156
157} // namespace Internal
158} // namespace Experimental
159} // namespace ROOT
160
161#endif // ROOT7_RIndexIter
#define d(i)
Definition RSha256.hxx:102
int type
Definition TGX11.cxx:121
Iterates over an index; the REFERENCE is defined by the REFERENCE template parameter.
RIndexIter & operator--() noexcept
–i
RIndexIter & operator-=(int d) noexcept
std::random_access_iterator_tag iterator_category
typename std::remove_reference< REFERENCE >::type value_type
RIndexIter operator--(int) noexcept
RIndexIter operator+(int d) noexcept
size_t GetIndex() const noexcept
Get the current index value.
RIndexIter & operator+=(int d) noexcept
RIndexIter operator-(int d) noexcept
RIndexIter operator++(int) noexcept
i++
bool operator<(RIndexIter< REFERENCE, POINTER > lhs, RIndexIter< REFERENCE, POINTER > rhs) noexcept
bool operator<=(RIndexIter< REFERENCE, POINTER > lhs, RIndexIter< REFERENCE, POINTER > rhs) noexcept
bool operator!=(RIndexIter< REFERENCE, POINTER > lhs, RIndexIter< REFERENCE, POINTER > rhs) noexcept
bool operator==(RIndexIter< REFERENCE, POINTER > lhs, RIndexIter< REFERENCE, POINTER > rhs) noexcept
bool operator>(RIndexIter< REFERENCE, POINTER > lhs, RIndexIter< REFERENCE, POINTER > rhs) noexcept
bool operator>=(RIndexIter< REFERENCE, POINTER > lhs, RIndexIter< REFERENCE, POINTER > rhs) noexcept
tbb::task_arena is an alias of tbb::interface7::task_arena, which doesn't allow to forward declare tb...