-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathIndexIterator.h
More file actions
58 lines (53 loc) · 1.36 KB
/
IndexIterator.h
File metadata and controls
58 lines (53 loc) · 1.36 KB
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#ifndef INDEXITERATOR_HEADER
#define INDEXITERATOR_HEADER
#include <iterator>
#ifndef DLL_LINKAGE
#define DLL_LINKAGE
#endif
class DLL_LINKAGE IndexIterator
{
public:
typedef const size_t value_type;
typedef value_type *pointer;
typedef value_type &reference;
typedef std::forward_iterator_tag iterator_category;
typedef size_t size_type;
typedef size_t difference_type;
IndexIterator() {}
IndexIterator(size_t index) : m_index(index) {}
const size_t operator*() const { return m_index; }
const size_t *operator->() const { return &m_index; }
IndexIterator &operator++() { ++m_index; return *this; }
IndexIterator operator++(int) { size_t save = m_index; ++m_index; return IndexIterator(save); }
bool operator==(IndexIterator a) const { return m_index == a.m_index; }
bool operator!=(IndexIterator a) const { return m_index != a.m_index; }
IndexIterator &operator+=(size_t offset)
{
m_index += offset;
return *this;
}
IndexIterator &operator-=(size_t offset)
{
m_index -= offset;
return *this;
}
IndexIterator operator+(size_t offset) const
{
return IndexIterator(m_index + offset);
}
IndexIterator operator-(size_t offset) const
{
return IndexIterator(m_index - offset);
}
size_t operator-(IndexIterator i) const
{
return m_index - i.m_index;
}
size_t operator[](size_t i) const
{
return m_index + i;
}
private:
size_t m_index;
};
#endif