pop_first() and pop_last() now return bool instead of void (true if popped, false if not)

master
Daniel Kolesa 2015-05-29 20:02:40 +01:00
parent 38fc61481a
commit 26f83b9efb
2 changed files with 36 additions and 25 deletions

View File

@ -440,8 +440,8 @@ namespace octa {
bool empty() const { return p_range.empty(); }
RangeSize<T> size() const { return p_range.size(); }
void pop_first() { p_range.pop_first(); }
void pop_last() { p_range.pop_last(); }
bool pop_first() { return p_range.pop_first(); }
bool pop_last() { return p_range.pop_last(); }
bool push_first() { return p_range.pop_first(); }
bool push_last() { return p_range.push_last(); }
@ -530,9 +530,10 @@ namespace octa {
bool empty() const { return p_range.empty(); }
void pop_first() {
p_range.pop_first();
bool pop_first() {
bool ret = p_range.pop_first();
advance_valid();
return ret;
}
bool push_first() {
T tmp = p_range;

View File

@ -120,19 +120,15 @@ namespace octa {
template<typename R>
RangeSize<R> __octa_pop_first_n(R &range, RangeSize<R> n) {
for (RangeSize<R> i = 0; i < n; ++i) {
if (range.empty()) return i;
range.pop_first();
}
for (RangeSize<R> i = 0; i < n; ++i)
if (!range.pop_first()) return i;
return n;
}
template<typename R>
RangeSize<R> __octa_pop_last_n(R &range, RangeSize<R> n) {
for (RangeSize<R> i = 0; i < n; ++i) {
if (range.empty()) return i;
range.pop_last();
}
for (RangeSize<R> i = 0; i < n; ++i)
if (!range.pop_last()) return i;
return n;
}
@ -237,8 +233,8 @@ namespace octa {
bool empty() const { return p_range.empty(); }
r_size size() const { return p_range.size(); }
void pop_first() { p_range.pop_last(); }
void pop_last() { p_range.pop_first(); }
bool pop_first() { return p_range.pop_last(); }
bool pop_last() { return p_range.pop_first(); }
bool push_first() { return p_range.push_last(); }
bool push_last() { return p_range.push_first(); }
@ -316,8 +312,8 @@ namespace octa {
bool empty() const { return p_range.empty(); }
r_size size() const { return p_range.size(); }
void pop_first() { p_range.pop_first(); }
void pop_last() { p_range.pop_last(); }
bool pop_first() { return p_range.pop_first(); }
bool pop_last() { return p_range.pop_last(); }
bool push_first() { return p_range.push_first(); }
bool push_last() { return p_range.push_last(); }
@ -370,7 +366,7 @@ namespace octa {
}
bool empty() const { return p_a * p_step >= p_b * p_step; }
void pop_first() { p_a += p_step; }
bool pop_first() { p_a += p_step; return true; }
bool push_first() { p_a -= p_step; return true; }
T &first() { return p_a; }
@ -412,9 +408,10 @@ namespace octa {
/* satisfy InputRange / ForwardRange */
bool empty() const { return p_beg == p_end; }
void pop_first() {
if (p_beg == p_end) return;
bool pop_first() {
if (p_beg == p_end) return false;
++p_beg;
return true;
}
bool push_first() {
--p_beg; return true;
@ -439,9 +436,10 @@ namespace octa {
const T &first() const { return *p_beg; }
/* satisfy BidirectionalRange */
void pop_last() {
if (p_end == p_beg) return;
bool pop_last() {
if (p_end == p_beg) return false;
--p_end;
return true;
}
bool push_last() {
++p_end; return true;
@ -540,7 +538,13 @@ namespace octa {
bool empty() const { return p_range.empty(); }
void pop_first() { ++p_index; p_range.pop_first(); }
bool pop_first() {
if (p_range.pop_first()) {
++p_index;
return true;
}
return false;
}
r_size pop_first_n(r_size n) {
r_size ret = p_range.pop_first_n(n);
@ -597,7 +601,13 @@ namespace octa {
bool empty() const { return (p_remaining <= 0) || p_range.empty(); }
void pop_first() { --p_remaining; p_range.pop_first(); }
bool pop_first() {
if (p_range.pop_first()) {
--p_remaining;
return true;
}
return false;
}
bool push_first() {
if (p_range.push_first()) {
++p_remaining;
@ -632,7 +642,7 @@ namespace octa {
void pop_last() {
static_assert(IsRandomAccessRange<T>::value,
"pop_last() only available for random access ranges");
--p_remaining;
return --p_remaining >= 0;
}
RangeSize<T> pop_last_n(RangeSize<T> n) {
static_assert(IsRandomAccessRange<T>::value,
@ -706,7 +716,7 @@ namespace octa {
}
bool empty() const { return p_range.empty(); }
void pop_first() { p_range.pop_first_n(p_chunksize); }
bool pop_first() { return p_range.pop_first_n(p_chunksize) > 0; }
bool push_first() {
T tmp = p_range;
RangeSize<T> an = tmp.push_first_n(p_chunksize);