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