typedef boost::counting_iterator<int> counter; std::transform(counter(0), counter(N), A.begin(), myFunction1); std::transform(A.begin(), A.end(), counter(0), B.begin(), myFunction2); std::transform(A.begin(), A.end(), B.begin(), C.begin(), myFunction3);
Now write your own version of std::transform , which performs a triple function:
template <typename In1, typename In2, typename In3, typename Out, typename FUNC> Out transform3(In1 first1, In1 last1, In2 first2, In3 first3, Out out, FUNC f) { while (first1 != last1) { *out++ = f(*first1++, *first2++, *first3++); } return out; } transform3(A.begin(), A.end(), B.begin(), counter(0), D.begin(), myFunction4);
I think there might be something you can do with variable templates in C ++ 0x to get transform_N , but if so, I don't know what it is, I never used them. I'm not sure that you can redirect a variable number of arguments with modifications (in this case, wrapping * ++ around each of them, as it were).