capture by references more (the objects live long enough to be safe)
This commit is contained in:
parent
a9bbccb1fb
commit
288526e7db
|
@ -30,7 +30,7 @@ inline R partition(R range, U pred) {
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename F> inline auto partition(F func) {
|
template<typename F> inline auto partition(F func) {
|
||||||
return [f = move(func)](auto obj) { return partition(obj, f); };
|
return [&func](auto &obj) mutable { return partition(obj, func); };
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename R, typename P>
|
template<typename R, typename P>
|
||||||
|
@ -42,7 +42,9 @@ inline bool is_partitioned(R range, P pred) {
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename F> inline bool is_partitioned(F func) {
|
template<typename F> inline bool is_partitioned(F func) {
|
||||||
return [f = move(func)](auto obj) { return is_partitioned(obj, f); };
|
return [&func](auto &obj) mutable {
|
||||||
|
return is_partitioned(obj, move(func));
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
/* sorting */
|
/* sorting */
|
||||||
|
@ -256,10 +258,10 @@ inline F for_each(R range, F func) {
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename F> inline auto for_each(F func) {
|
template<typename F> inline auto for_each(F func) {
|
||||||
return [f = move(func)](auto obj) {
|
return [&func](auto &obj) mutable {
|
||||||
for (; !obj.empty(); obj.pop_front())
|
for (; !obj.empty(); obj.pop_front())
|
||||||
f(obj.front());
|
func(obj.front());
|
||||||
return move(f);
|
return move(func);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -271,7 +273,7 @@ inline bool all_of(R range, P pred) {
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename F> inline auto all_of(F func) {
|
template<typename F> inline auto all_of(F func) {
|
||||||
return [f = move(func)](auto obj) { return all_of(obj, f); };
|
return [&func](auto &obj) mutable { return all_of(obj, move(func)); };
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename R, typename P>
|
template<typename R, typename P>
|
||||||
|
@ -282,7 +284,7 @@ inline bool any_of(R range, P pred) {
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename F> inline auto any_of(F func) {
|
template<typename F> inline auto any_of(F func) {
|
||||||
return [f = move(func)](auto obj) { return any_of(obj, f); };
|
return [&func](auto &obj) mutable { return any_of(obj, move(func)); };
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename R, typename P>
|
template<typename R, typename P>
|
||||||
|
@ -293,7 +295,7 @@ inline bool none_of(R range, P pred) {
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename F> inline auto none_of(F func) {
|
template<typename F> inline auto none_of(F func) {
|
||||||
return [f = move(func)](auto obj) { return none_of(obj, f); };
|
return [&func](auto &obj) mutable { return none_of(obj, move(func)); };
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename R, typename T>
|
template<typename R, typename T>
|
||||||
|
@ -305,7 +307,7 @@ inline R find(R range, const T &v) {
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T> inline auto find(const T &v) {
|
template<typename T> inline auto find(const T &v) {
|
||||||
return [v](auto obj) { return find(obj, v); };
|
return [&v](auto &obj) { return find(obj, v); };
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename R, typename T>
|
template<typename R, typename T>
|
||||||
|
@ -323,7 +325,7 @@ inline R find_last(R range, const T &v) {
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T> inline auto find_last(const T &v) {
|
template<typename T> inline auto find_last(const T &v) {
|
||||||
return [v](auto obj) { return find_last(obj, v); };
|
return [&v](auto &obj) { return find_last(obj, v); };
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename R, typename P>
|
template<typename R, typename P>
|
||||||
|
@ -335,7 +337,7 @@ inline R find_if(R range, P pred) {
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename F> inline auto find_if(F func) {
|
template<typename F> inline auto find_if(F func) {
|
||||||
return [f = move(func)](auto obj) { return find_if(obj, f); };
|
return [&func](auto &obj) mutable { return find_if(obj, move(func)); };
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename R, typename P>
|
template<typename R, typename P>
|
||||||
|
@ -347,7 +349,7 @@ inline R find_if_not(R range, P pred) {
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename F> inline auto find_if_not(F func) {
|
template<typename F> inline auto find_if_not(F func) {
|
||||||
return [f = move(func)](auto obj) { return find_if_not(obj, f); };
|
return [&func](auto &obj) mutable { return find_if_not(obj, move(func)); };
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename R1, typename R2, typename C>
|
template<typename R1, typename R2, typename C>
|
||||||
|
@ -378,7 +380,7 @@ inline RangeSize<R> count(R range, const T &v) {
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T> inline auto count(const T &v) {
|
template<typename T> inline auto count(const T &v) {
|
||||||
return [v](auto obj) { return count(obj, v); };
|
return [&v](auto &obj) { return count(obj, v); };
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename R, typename P>
|
template<typename R, typename P>
|
||||||
|
@ -391,7 +393,7 @@ inline RangeSize<R> count_if(R range, P pred) {
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename F> inline auto count_if(F func) {
|
template<typename F> inline auto count_if(F func) {
|
||||||
return [f = move(func)](auto obj) { return count_if(obj, f); };
|
return [&func](auto &obj) mutable { return count_if(obj, move(func)); };
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename R, typename P>
|
template<typename R, typename P>
|
||||||
|
@ -404,7 +406,7 @@ inline RangeSize<R> count_if_not(R range, P pred) {
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename F> inline auto count_if_not(F func) {
|
template<typename F> inline auto count_if_not(F func) {
|
||||||
return [f = move(func)](auto obj) { return count_if_not(obj, f); };
|
return [&func](auto &obj) mutable { return count_if_not(obj, move(func)); };
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename R>
|
template<typename R>
|
||||||
|
@ -418,7 +420,7 @@ inline bool equal(R range1, R range2) {
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename R> inline bool equal(R range) {
|
template<typename R> inline bool equal(R range) {
|
||||||
return [r = move(range)](auto obj) { return equal(obj, r); };
|
return [&range](auto &obj) mutable { return equal(obj, move(range)); };
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename R>
|
template<typename R>
|
||||||
|
@ -427,7 +429,7 @@ R slice_until(R range1, R range2) {
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename R> inline auto slice_until(R range) {
|
template<typename R> inline auto slice_until(R range) {
|
||||||
return [r = move(range)](auto obj) { return slice_until(obj, r); };
|
return [&range](auto &obj) mutable { return slice_until(obj, move(range)); };
|
||||||
}
|
}
|
||||||
|
|
||||||
/* algos that modify ranges or work with output ranges */
|
/* algos that modify ranges or work with output ranges */
|
||||||
|
@ -521,7 +523,7 @@ inline T foldl(R range, T init, F func) {
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T> inline auto foldl(T init) {
|
template<typename T> inline auto foldl(T init) {
|
||||||
return [v = move(init)](auto obj) { return foldl(obj, v); };
|
return [&init](auto &obj) mutable { return foldl(obj, move(init)); };
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename R, typename T>
|
template<typename R, typename T>
|
||||||
|
@ -539,7 +541,7 @@ inline T foldr(R range, T init, F func) {
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T> inline auto foldr(T init) {
|
template<typename T> inline auto foldr(T init) {
|
||||||
return [v = move(init)](auto obj) { return foldr(obj, v); };
|
return [&init](auto &obj) mutable { return foldr(obj, move(init)); };
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T, typename F, typename R>
|
template<typename T, typename F, typename R>
|
||||||
|
@ -631,7 +633,7 @@ inline MapRange<R, F, detail::MapReturnType<R, F>> map(R range, F func) {
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename F> inline auto map(F func) {
|
template<typename F> inline auto map(F func) {
|
||||||
return [f = move(func)](auto obj) { return map(obj, f); };
|
return [&func](auto &obj) mutable { return map(obj, move(func)); };
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T, typename F>
|
template<typename T, typename F>
|
||||||
|
@ -704,7 +706,7 @@ inline FilterRange<R, detail::FilterPred<R, P>> filter(R range, P pred) {
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename F> inline auto filter(F func) {
|
template<typename F> inline auto filter(F func) {
|
||||||
return [f = move(func)](auto obj) { return filter(obj, f); };
|
return [&func](auto &obj) mutable { return filter(obj, move(func)); };
|
||||||
}
|
}
|
||||||
|
|
||||||
} /* namespace ostd */
|
} /* namespace ostd */
|
||||||
|
|
|
@ -485,12 +485,12 @@ template<typename B, typename C, typename V, typename R = V &,
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename R1, typename ...RR>
|
template<typename R1, typename ...RR>
|
||||||
JoinRange<B, R1, RR...> join(R1 r1, RR ...rr) {
|
JoinRange<B, R1, RR...> join(R1 r1, RR ...rr) const {
|
||||||
return JoinRange<B, R1, RR...>(iter(), move(r1), move(rr)...);
|
return JoinRange<B, R1, RR...>(iter(), move(r1), move(rr)...);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename R1, typename ...RR>
|
template<typename R1, typename ...RR>
|
||||||
ZipRange<B, R1, RR...> zip(R1 r1, RR ...rr) {
|
ZipRange<B, R1, RR...> zip(R1 r1, RR ...rr) const {
|
||||||
return ZipRange<B, R1, RR...>(iter(), move(r1), move(rr)...);
|
return ZipRange<B, R1, RR...>(iter(), move(r1), move(rr)...);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -585,36 +585,36 @@ inline auto operator|(const R &range, F &&func) -> decltype(func(range)) {
|
||||||
}
|
}
|
||||||
|
|
||||||
inline auto reverse() {
|
inline auto reverse() {
|
||||||
return [](auto obj) { return obj.reverse(); };
|
return [](auto &obj) { return obj.reverse(); };
|
||||||
}
|
}
|
||||||
|
|
||||||
inline auto movable() {
|
inline auto movable() {
|
||||||
return [](auto obj) { return obj.movable(); };
|
return [](auto &obj) { return obj.movable(); };
|
||||||
}
|
}
|
||||||
|
|
||||||
inline auto enumerate() {
|
inline auto enumerate() {
|
||||||
return [](auto obj) { return obj.enumerate(); };
|
return [](auto &obj) { return obj.enumerate(); };
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
inline auto take(T n) {
|
inline auto take(T n) {
|
||||||
return [n](auto obj) { return obj.take(n); };
|
return [n](auto &obj) { return obj.take(n); };
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
inline auto chunks(T n) {
|
inline auto chunks(T n) {
|
||||||
return [n](auto obj) { return obj.chunks(n); };
|
return [n](auto &obj) { return obj.chunks(n); };
|
||||||
}
|
}
|
||||||
|
|
||||||
/* TODO: can't use generalized captures on packs so gotta workaround */
|
/* TODO: can't use generalized captures on packs so gotta workaround */
|
||||||
template<typename R1, typename ...R>
|
template<typename R1, typename ...R>
|
||||||
inline auto join(R1 r1, R ...rr) {
|
inline auto join(R1 r1, R ...rr) {
|
||||||
return [=](auto obj) mutable { return obj.join(move(r1), move(rr)...); };
|
return [=](auto &obj) mutable { return obj.join(move(r1), move(rr)...); };
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename R1, typename ...R>
|
template<typename R1, typename ...R>
|
||||||
inline auto zip(R1 r1, R ...rr) {
|
inline auto zip(R1 r1, R ...rr) {
|
||||||
return [=](auto obj) mutable { return obj.zip(move(r1), move(rr)...); };
|
return [=](auto &obj) mutable { return obj.zip(move(r1), move(rr)...); };
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
|
|
Loading…
Reference in a new issue