forked from OctaForge/libostd
pop_first() and pop_last() now return bool instead of void (true if popped, false if not)
parent
38fc61481a
commit
26f83b9efb
|
@ -440,8 +440,8 @@ namespace octa {
|
||||||
bool empty() const { return p_range.empty(); }
|
bool empty() const { return p_range.empty(); }
|
||||||
RangeSize<T> size() const { return p_range.size(); }
|
RangeSize<T> size() const { return p_range.size(); }
|
||||||
|
|
||||||
void pop_first() { p_range.pop_first(); }
|
bool pop_first() { return p_range.pop_first(); }
|
||||||
void pop_last() { p_range.pop_last(); }
|
bool pop_last() { return p_range.pop_last(); }
|
||||||
|
|
||||||
bool push_first() { return p_range.pop_first(); }
|
bool push_first() { return p_range.pop_first(); }
|
||||||
bool push_last() { return p_range.push_last(); }
|
bool push_last() { return p_range.push_last(); }
|
||||||
|
@ -530,9 +530,10 @@ namespace octa {
|
||||||
|
|
||||||
bool empty() const { return p_range.empty(); }
|
bool empty() const { return p_range.empty(); }
|
||||||
|
|
||||||
void pop_first() {
|
bool pop_first() {
|
||||||
p_range.pop_first();
|
bool ret = p_range.pop_first();
|
||||||
advance_valid();
|
advance_valid();
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
bool push_first() {
|
bool push_first() {
|
||||||
T tmp = p_range;
|
T tmp = p_range;
|
||||||
|
|
52
octa/range.h
52
octa/range.h
|
@ -120,19 +120,15 @@ namespace octa {
|
||||||
|
|
||||||
template<typename R>
|
template<typename R>
|
||||||
RangeSize<R> __octa_pop_first_n(R &range, RangeSize<R> n) {
|
RangeSize<R> __octa_pop_first_n(R &range, RangeSize<R> n) {
|
||||||
for (RangeSize<R> i = 0; i < n; ++i) {
|
for (RangeSize<R> i = 0; i < n; ++i)
|
||||||
if (range.empty()) return i;
|
if (!range.pop_first()) return i;
|
||||||
range.pop_first();
|
|
||||||
}
|
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename R>
|
template<typename R>
|
||||||
RangeSize<R> __octa_pop_last_n(R &range, RangeSize<R> n) {
|
RangeSize<R> __octa_pop_last_n(R &range, RangeSize<R> n) {
|
||||||
for (RangeSize<R> i = 0; i < n; ++i) {
|
for (RangeSize<R> i = 0; i < n; ++i)
|
||||||
if (range.empty()) return i;
|
if (!range.pop_last()) return i;
|
||||||
range.pop_last();
|
|
||||||
}
|
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -237,8 +233,8 @@ namespace octa {
|
||||||
bool empty() const { return p_range.empty(); }
|
bool empty() const { return p_range.empty(); }
|
||||||
r_size size() const { return p_range.size(); }
|
r_size size() const { return p_range.size(); }
|
||||||
|
|
||||||
void pop_first() { p_range.pop_last(); }
|
bool pop_first() { return p_range.pop_last(); }
|
||||||
void pop_last() { p_range.pop_first(); }
|
bool pop_last() { return p_range.pop_first(); }
|
||||||
|
|
||||||
bool push_first() { return p_range.push_last(); }
|
bool push_first() { return p_range.push_last(); }
|
||||||
bool push_last() { return p_range.push_first(); }
|
bool push_last() { return p_range.push_first(); }
|
||||||
|
@ -316,8 +312,8 @@ namespace octa {
|
||||||
bool empty() const { return p_range.empty(); }
|
bool empty() const { return p_range.empty(); }
|
||||||
r_size size() const { return p_range.size(); }
|
r_size size() const { return p_range.size(); }
|
||||||
|
|
||||||
void pop_first() { p_range.pop_first(); }
|
bool pop_first() { return p_range.pop_first(); }
|
||||||
void pop_last() { p_range.pop_last(); }
|
bool pop_last() { return p_range.pop_last(); }
|
||||||
|
|
||||||
bool push_first() { return p_range.push_first(); }
|
bool push_first() { return p_range.push_first(); }
|
||||||
bool push_last() { return p_range.push_last(); }
|
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; }
|
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; }
|
bool push_first() { p_a -= p_step; return true; }
|
||||||
T &first() { return p_a; }
|
T &first() { return p_a; }
|
||||||
|
|
||||||
|
@ -412,9 +408,10 @@ namespace octa {
|
||||||
/* satisfy InputRange / ForwardRange */
|
/* satisfy InputRange / ForwardRange */
|
||||||
bool empty() const { return p_beg == p_end; }
|
bool empty() const { return p_beg == p_end; }
|
||||||
|
|
||||||
void pop_first() {
|
bool pop_first() {
|
||||||
if (p_beg == p_end) return;
|
if (p_beg == p_end) return false;
|
||||||
++p_beg;
|
++p_beg;
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
bool push_first() {
|
bool push_first() {
|
||||||
--p_beg; return true;
|
--p_beg; return true;
|
||||||
|
@ -439,9 +436,10 @@ namespace octa {
|
||||||
const T &first() const { return *p_beg; }
|
const T &first() const { return *p_beg; }
|
||||||
|
|
||||||
/* satisfy BidirectionalRange */
|
/* satisfy BidirectionalRange */
|
||||||
void pop_last() {
|
bool pop_last() {
|
||||||
if (p_end == p_beg) return;
|
if (p_end == p_beg) return false;
|
||||||
--p_end;
|
--p_end;
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
bool push_last() {
|
bool push_last() {
|
||||||
++p_end; return true;
|
++p_end; return true;
|
||||||
|
@ -540,7 +538,13 @@ namespace octa {
|
||||||
|
|
||||||
bool empty() const { return p_range.empty(); }
|
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 pop_first_n(r_size n) {
|
||||||
r_size ret = p_range.pop_first_n(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(); }
|
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() {
|
bool push_first() {
|
||||||
if (p_range.push_first()) {
|
if (p_range.push_first()) {
|
||||||
++p_remaining;
|
++p_remaining;
|
||||||
|
@ -632,7 +642,7 @@ namespace octa {
|
||||||
void pop_last() {
|
void pop_last() {
|
||||||
static_assert(IsRandomAccessRange<T>::value,
|
static_assert(IsRandomAccessRange<T>::value,
|
||||||
"pop_last() only available for random access ranges");
|
"pop_last() only available for random access ranges");
|
||||||
--p_remaining;
|
return --p_remaining >= 0;
|
||||||
}
|
}
|
||||||
RangeSize<T> pop_last_n(RangeSize<T> n) {
|
RangeSize<T> pop_last_n(RangeSize<T> n) {
|
||||||
static_assert(IsRandomAccessRange<T>::value,
|
static_assert(IsRandomAccessRange<T>::value,
|
||||||
|
@ -706,7 +716,7 @@ namespace octa {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool empty() const { return p_range.empty(); }
|
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() {
|
bool push_first() {
|
||||||
T tmp = p_range;
|
T tmp = p_range;
|
||||||
RangeSize<T> an = tmp.push_first_n(p_chunksize);
|
RangeSize<T> an = tmp.push_first_n(p_chunksize);
|
||||||
|
|
Loading…
Reference in New Issue