new predefined operations for input ranges (defined for all without need for custom impl)

master
Daniel Kolesa 2015-08-31 14:46:36 +01:00
parent eb3c273376
commit d9120a0015
2 changed files with 52 additions and 1 deletions

View File

@ -850,7 +850,7 @@ struct Function<R(Args...)>: detail::FunctionBase<R, Args...> {
ostd::swap(p_call, f.p_call);
}
operator bool() const { return p_call != nullptr; }
explicit operator bool() const { return p_call != nullptr; }
private:
detail::FmStorage p_stor;

View File

@ -505,6 +505,57 @@ template<typename B, typename C, typename V, typename R = V &,
}
return (on - n);
}
/* iterator like interface operating on the front part of the range
* this is sometimes convenient as it can be used within expressions */
Reference operator*() const {
return ((B *)this)->front();
}
B &operator++() {
((B *)this)->pop_front();
return *((B *)this);
}
B operator++(int) {
B tmp(*((const B *)this));
((B *)this)->pop_front();
return tmp;
}
B &operator--() {
((B *)this)->push_front();
return *((B *)this);
}
B operator--(int) {
B tmp(*((const B *)this));
((B *)this)->push_front();
return tmp;
}
B operator+(Difference n) const {
B tmp(*((const B *)this));
tmp.pop_front_n(n);
return tmp;
}
B operator-(Difference n) const {
B tmp(*((const B *)this));
tmp.push_front_n(n);
return tmp;
}
B &operator+=(Difference n) {
((B *)this)->pop_front_n(n);
return *((B *)this);
}
B &operator-=(Difference n) {
((B *)this)->push_front_n(n);
return *((B *)this);
}
/* universal bool operator */
explicit operator bool() const { return !((B *)this)->empty(); }
};
template<typename T>