HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
countingIterator.h
Go to the documentation of this file.
1 //
2 // Copyright 2025 Pixar
3 //
4 // Licensed under the terms set forth in the LICENSE.txt file available at
5 // https://openusd.org/license.
6 //
7 #ifndef PXR_EXEC_VDF_COUNTING_ITERATOR
8 #define PXR_EXEC_VDF_COUNTING_ITERATOR
9 
10 #include "pxr/pxr.h"
11 
12 #include <iterator>
13 #include <type_traits>
14 
16 
17 /// Random access counting iterator that simply operates on an underlying
18 /// integer index.
19 ///
20 template <typename T>
22 public:
23  using iterator_category = std::random_access_iterator_tag;
24  using value_type = const T;
25  using reference = const T;
26  using pointer = const T *;
27  using difference_type = std::make_signed_t<value_type>;
28 
29  Vdf_CountingIterator() : _integer() {}
30  explicit Vdf_CountingIterator(T i) : _integer(i) {}
31 
32  reference operator*() const { return _integer; }
33  pointer operator->() const { return &_integer; }
35  return _integer + n;
36  }
37 
39  ++_integer;
40  return *this;
41  }
42 
44  Vdf_CountingIterator r(*this);
45  ++_integer;
46  return r;
47  }
48 
50  Vdf_CountingIterator r(*this);
51  r._integer += n;
52  return r;
53  }
54 
56  _integer += n;
57  return *this;
58  }
59 
61  --_integer;
62  return *this;
63  }
64 
66  Vdf_CountingIterator r(*this);
67  --_integer;
68  return r;
69  }
70 
72  Vdf_CountingIterator r(*this);
73  r._integer -= n;
74  return r;
75  }
76 
78  _integer -= n;
79  return *this;
80  }
81 
83  return _integer - rhs._integer;
84  }
85 
86  bool operator==(const Vdf_CountingIterator &rhs) const {
87  return _integer == rhs._integer;
88  }
89 
90  bool operator!=(const Vdf_CountingIterator &rhs) const {
91  return _integer != rhs._integer;
92  }
93 
94  bool operator<(const Vdf_CountingIterator &rhs) const {
95  return _integer < rhs._integer;
96  }
97 
98  bool operator<=(const Vdf_CountingIterator &rhs) const {
99  return _integer <= rhs._integer;
100  }
101 
102  bool operator>(const Vdf_CountingIterator &rhs) const {
103  return _integer > rhs._integer;
104  }
105 
106  bool operator>=(const Vdf_CountingIterator &rhs) const {
107  return _integer >= rhs._integer;
108  }
109 
110 private:
111  T _integer;
112 };
113 
115 
116 #endif
bool operator==(const Vdf_CountingIterator &rhs) const
Vdf_CountingIterator & operator--()
Vdf_CountingIterator operator--(int)
value_type operator[](const difference_type n) const
bool operator<=(const Vdf_CountingIterator &rhs) const
#define PXR_NAMESPACE_OPEN_SCOPE
Definition: pxr.h:73
Vdf_CountingIterator operator-(const difference_type n) const
difference_type operator-(const Vdf_CountingIterator &rhs) const
GLdouble n
Definition: glcorearb.h:2008
Vdf_CountingIterator operator++(int)
std::make_signed_t< value_type > difference_type
Vdf_CountingIterator & operator++()
reference operator*() const
pointer operator->() const
bool operator>=(const Vdf_CountingIterator &rhs) const
std::random_access_iterator_tag iterator_category
bool operator<(const Vdf_CountingIterator &rhs) const
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74
Vdf_CountingIterator & operator-=(const difference_type n)
Vdf_CountingIterator operator+(const difference_type n) const
bool operator>(const Vdf_CountingIterator &rhs) const
GLboolean r
Definition: glcorearb.h:1222
bool operator!=(const Vdf_CountingIterator &rhs) const
Vdf_CountingIterator & operator+=(const difference_type n)