Just for completeness, here's an example of the functor approach:
#include <algorithm>
#include <vector>
#include <iostream>
struct Copy {
template <typename InputIter, typename OutputIter>
OutputIter operator()(InputIter i1, InputIter i2, OutputIter o1) {
return std::copy(i1, i2, o1);
}
};
template <typename CopyFunctor>
void foo(CopyFunctor cf) {
std::vector<int> v1 = {3, 1, 4};
std::vector<int> v2(v1.size());
cf(v1.begin(), v1.end(), v2.begin());
for (auto i : v2) {
std::cout << i << ' ';
}
}
int main() {
foo(Copy()); // displays "3 1 4"
}