Fix index iterator on large problem sizes
This commit is contained in:
parent
37dcdc224c
commit
193eaa7fe2
@ -23,35 +23,47 @@
|
|||||||
// implementation doesn't target
|
// implementation doesn't target
|
||||||
template <typename N>
|
template <typename N>
|
||||||
class ranged {
|
class ranged {
|
||||||
N from, to;
|
|
||||||
public:
|
public:
|
||||||
ranged(N from, N to ): from(from), to(to) {}
|
|
||||||
class iterator {
|
class iterator {
|
||||||
N num;
|
friend class ranged;
|
||||||
public:
|
public:
|
||||||
using difference_type = N;
|
using difference_type = N;
|
||||||
using value_type = N;
|
using value_type = N;
|
||||||
using pointer = const N*;
|
using pointer = const N*;
|
||||||
using reference = const N&;
|
using reference = const N&;
|
||||||
using iterator_category = std::random_access_iterator_tag;
|
using iterator_category = std::random_access_iterator_tag;
|
||||||
explicit iterator(N _num = 0) : num(_num) {}
|
|
||||||
|
|
||||||
iterator& operator++() { num++; return *this; }
|
reference operator *() const { return i_; }
|
||||||
iterator operator++(int) { iterator retval = *this; ++(*this); return retval; }
|
const iterator &operator ++() { ++i_; return *this; }
|
||||||
iterator operator+(const value_type v) const { return iterator(num + v); }
|
iterator operator ++(int) { iterator copy(*this); ++i_; return copy; }
|
||||||
iterator operator+=(int x) { iterator retval = *this; this->num+=x; return retval; }
|
|
||||||
|
|
||||||
bool operator==(iterator other) const { return num == other.num; }
|
const iterator &operator --() { --i_; return *this; }
|
||||||
bool operator!=(iterator other) const { return *this != other; }
|
iterator operator --(int) { iterator copy(*this); --i_; return copy; }
|
||||||
bool operator<(iterator other) const { return num < other.num; }
|
|
||||||
|
|
||||||
reference operator*() const { return num;}
|
const iterator &operator +=(N by) { i_+=by; return *this; }
|
||||||
difference_type operator-(const iterator &it) const { return num - it.num; }
|
|
||||||
value_type operator[](const difference_type &i) const { return num + i; }
|
|
||||||
|
|
||||||
|
value_type operator[](const difference_type &i) const { return i_ + i; }
|
||||||
|
|
||||||
|
difference_type operator-(const iterator &it) const { return i_ - it.i_; }
|
||||||
|
iterator operator+(const value_type v) const { return iterator(i_ + v); }
|
||||||
|
|
||||||
|
bool operator ==(const iterator &other) const { return i_ == other.i_; }
|
||||||
|
bool operator !=(const iterator &other) const { return i_ != other.i_; }
|
||||||
|
bool operator < (const iterator &other) const { return i_ < other.i_; }
|
||||||
|
|
||||||
|
protected:
|
||||||
|
explicit iterator(N start) : i_ (start) {}
|
||||||
|
|
||||||
|
private:
|
||||||
|
N i_;
|
||||||
};
|
};
|
||||||
iterator begin() { return iterator(from); }
|
|
||||||
iterator end() { return iterator(to >= from? to+1 : to-1); }
|
[[nodiscard]] iterator begin() const { return begin_; }
|
||||||
|
[[nodiscard]] iterator end() const { return end_; }
|
||||||
|
ranged(N begin, N end) : begin_(begin), end_(end) {}
|
||||||
|
private:
|
||||||
|
iterator begin_;
|
||||||
|
iterator end_;
|
||||||
};
|
};
|
||||||
|
|
||||||
template <class T>
|
template <class T>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user