equality checking for NumberRange

master
Daniel Kolesa 2015-04-17 20:20:38 +01:00
parent 37aa387734
commit 0116d3cf4c
2 changed files with 14 additions and 7 deletions

View File

@ -190,6 +190,13 @@ namespace octa {
p_step(it.p_step) {}
NumberRange(T a, T b, T step = 1): p_a(a), p_b(b), p_step(step) {}
bool operator==(const NumberRange &v) const {
return p_a == v.p_a && p_b == v.p_b && p_step == v.p_step;
}
bool operator!=(const NumberRange &v) const {
return p_a != v.p_a || p_b != v.p_b || p_step != v.p_step;
}
bool empty() const { return p_a * p_step >= p_b * p_step; }
void pop_first() { p_a += p_step; }
T &first() { return p_a; }

View File

@ -28,6 +28,13 @@ namespace octa {
}
VectorRange(T *beg, T *end): p_beg(beg), p_end(end) {}
bool operator==(const VectorRange &v) const {
return p_beg == v.p_beg && p_end == v.p_end;
}
bool operator!=(const VectorRange &v) const {
return p_beg != v.p_beg || p_end != v.p_end;
}
/* satisfy InputRange / ForwardRange */
bool empty() const { return p_beg == nullptr; }
@ -39,13 +46,6 @@ namespace octa {
T &first() { return *p_beg; }
const T &first() const { return *p_beg; }
bool operator==(const VectorRange &v) const {
return p_beg == v.p_beg && p_end == v.p_end;
}
bool operator!=(const VectorRange &v) const {
return p_beg != v.p_beg || p_end != v.p_end;
}
/* satisfy BidirectionalRange */
void pop_last() {
if (p_end-- == p_beg) { p_end = nullptr; return; }