template <class Body>
void foreach(Body&& body) const {
source_.foreach([&](Value value) {
- if (pred_(std::forward<Value>(value))) {
+ // NB: Argument not forwarded to avoid accidental move-construction
+ if (pred_(value)) {
body(std::forward<Value>(value));
}
});
template <class Handler>
bool apply(Handler&& handler) const {
return source_.apply([&](Value value) -> bool {
- if (pred_(std::forward<Value>(value))) {
+ // NB: Argument not forwarded to avoid accidental move-construction
+ if (pred_(value)) {
return handler(std::forward<Value>(value));
}
return true;
constexpr detail::Unwrap unwrap{};
-inline detail::Take take(size_t count) { return detail::Take(count); }
+template <class Number>
+inline detail::Take take(Number count) {
+ if (count < 0) {
+ throw std::invalid_argument("Negative value passed to take()");
+ }
+ return detail::Take(static_cast<size_t>(count));
+}
inline detail::Stride stride(size_t s) { return detail::Stride(s); }