Debian Codegraph @

yo/concrete/examples/iterators/random.h

raw
1 #include <iterator>
2
3 struct RandomIterator
4 {
5 using iterator_category = std::bidirectional_iterator_tag;
6 using difference_type = std::ptrdiff_t;
7 using value_type = int;
8 using pointer = value_type *;
9 using reference = value_type &;
10
11 private:
12 int d_value;
13
14 public:
15 RandomIterator(int init);
16
17 // standard:
18 bool operator==(RandomIterator const &other) const;
19 bool operator!=(RandomIterator const &other) const;
20 int &operator*();
21 RandomIterator &operator++();
22
23 // required:
24 int operator-(RandomIterator const &rhs) const;
25 RandomIterator operator+(int step) const;
26 RandomIterator operator-(int step) const;
27 bool operator<(RandomIterator const &other) const;
28
29 // consider:
30 int *operator->() const;
31 RandomIterator &operator--();
32 RandomIterator operator--(int);
33 RandomIterator operator++(int);
34 RandomIterator &operator-=(int step);
35 RandomIterator &operator+=(int step);
36 };
37
38 RandomIterator::RandomIterator(int init)
39 :
40 d_value(init)
41 {}
42
43 bool RandomIterator::operator!=(RandomIterator const &other) const
44 {
45 return d_value != other.d_value;
46 }
47
48 bool RandomIterator::operator==(RandomIterator const &other) const
49 {
50 return d_value == other.d_value;
51 }
52
53 bool RandomIterator::operator<(RandomIterator const &other) const
54 {
55 return d_value < other.d_value;
56 }
57
58 int RandomIterator::operator-(RandomIterator const &rhs) const
59 {
60 return 0;
61 }
62
63 RandomIterator RandomIterator::operator+(int step) const
64 {
65 return *this;
66 }
67
68 RandomIterator RandomIterator::operator-(int step) const
69 {
70 return *this;
71 }
72
73 RandomIterator &RandomIterator::operator--()
74 {
75 return *this;
76 }
77
78 RandomIterator &RandomIterator::operator++()
79 {
80 return *this;
81 }
82
83 int &RandomIterator::operator*()
84 {
85 return d_value;
86 }