| 80 | |
| 81 | // Class of the dependent iterator, created implicitly by begin and end |
| 82 | class RangeIter { |
| 83 | public: |
| 84 | using difference_type = int64_t; |
| 85 | using value_type = return_type; |
| 86 | using reference = const value_type&; |
| 87 | using pointer = const value_type*; |
| 88 | using iterator_category = std::forward_iterator_tag; |
| 89 | |
| 90 | #ifdef _MSC_VER |
| 91 | // msvc complains about unchecked iterators, |
| 92 | // see https://stackoverflow.com/questions/21655496/error-c4996-checked-iterators |
| 93 | using _Unchecked_type = typename LazyRange<Generator>::RangeIter; |
| 94 | #endif |
| 95 | |
| 96 | RangeIter() = delete; |
| 97 | RangeIter(const RangeIter& other) = default; |
| 98 | RangeIter& operator=(const RangeIter& other) = default; |
| 99 | |
| 100 | RangeIter(const LazyRange<Generator>& range, int64_t index) |
| 101 | : range_(&range), index_(index) {} |
| 102 | |
| 103 | const return_type operator*() const { return range_->gen_(index_); } |
| 104 | |
| 105 | RangeIter operator+(difference_type length) const { |
| 106 | return RangeIter(*range_, index_ + length); |
| 107 | } |
| 108 | |
| 109 | // pre-increment |
| 110 | RangeIter& operator++() { |
| 111 | ++index_; |
| 112 | return *this; |
| 113 | } |
| 114 | |
| 115 | // post-increment |
| 116 | RangeIter operator++(int) { |
| 117 | auto copy = RangeIter(*this); |
| 118 | ++index_; |
| 119 | return copy; |
| 120 | } |
| 121 | |
| 122 | bool operator==(const typename LazyRange<Generator>::RangeIter& other) const { |
| 123 | return this->index_ == other.index_ && this->range_ == other.range_; |
| 124 | } |
| 125 | |
| 126 | bool operator!=(const typename LazyRange<Generator>::RangeIter& other) const { |
| 127 | return this->index_ != other.index_ || this->range_ != other.range_; |
| 128 | } |
| 129 | |
| 130 | int64_t operator-(const typename LazyRange<Generator>::RangeIter& other) const { |
| 131 | return this->index_ - other.index_; |
| 132 | } |
| 133 | |
| 134 | bool operator<(const typename LazyRange<Generator>::RangeIter& other) const { |
| 135 | return this->index_ < other.index_; |
| 136 | } |
| 137 | |
| 138 | private: |
| 139 | // parent range reference |
no outgoing calls
no test coverage detected