Iterators should not be reference parameters
This commit is contained in:
parent
acec279889
commit
f1095f294a
@ -44,21 +44,21 @@ namespace sc {
|
|||||||
// iterator versions
|
// iterator versions
|
||||||
|
|
||||||
template<class T, class M, class FwdIter>
|
template<class T, class M, class FwdIter>
|
||||||
std::vector<M> map(FwdIter& begin, FwdIter& end, std::function<M(T)> fun) {
|
std::vector<M> map(FwdIter begin, FwdIter end, std::function<M(T)> fun) {
|
||||||
std::vector<M> result;
|
std::vector<M> result;
|
||||||
std::transform(begin, end, std::back_inserter(result), fun);
|
std::transform(begin, end, std::back_inserter(result), fun);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class T, class FwdIter>
|
template<class T, class FwdIter>
|
||||||
std::vector<T> filter(FwdIter& begin, FwdIter& end, std::function<bool(T)> fun) {
|
std::vector<T> filter(FwdIter begin, FwdIter end, std::function<bool(T)> fun) {
|
||||||
std::vector<T> result;
|
std::vector<T> result;
|
||||||
std::copy_if(begin, end, std::back_inserter(result), fun);
|
std::copy_if(begin, end, std::back_inserter(result), fun);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class T, class R, class FwdIter>
|
template<class T, class R, class FwdIter>
|
||||||
R reduce(FwdIter& begin, FwdIter& end, R seed, std::function<R(T, R)> fun) {
|
R reduce(FwdIter begin, FwdIter end, R seed, std::function<R(T, R)> fun) {
|
||||||
R result {seed};
|
R result {seed};
|
||||||
for (FwdIter it = begin; it != end; ++it) {
|
for (FwdIter it = begin; it != end; ++it) {
|
||||||
result = fun(*it, result);
|
result = fun(*it, result);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user