-
-
Notifications
You must be signed in to change notification settings - Fork 264
Expand file tree
/
Copy pathNumberIterator.h
More file actions
36 lines (27 loc) · 696 Bytes
/
NumberIterator.h
File metadata and controls
36 lines (27 loc) · 696 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#ifndef INSIGHTS_NUMBER_ITERATOR_H
#define INSIGHTS_NUMBER_ITERATOR_H
template<typename T>
class NumberIterator
{
const T mNum;
T mCount{};
public:
NumberIterator(const T num)
: mNum{num}
{
}
const T& operator*() const { return mCount; }
NumberIterator& operator++()
{
++mCount;
return *this;
}
struct sentinel
{
};
bool operator==(sentinel) const { return mCount >= mNum; }
const NumberIterator& begin() const { return *this; }
const sentinel end() const { return {}; }
};
//-----------------------------------------------------------------------------
#endif /* INSIGHTS_NUMBER_ITERATOR_H */