I guess that there should be someway to write the below piece of code without using “for” loops and by just using STL algorithms and iterators. If I am not wrong can anyone guide me on how to do this?
std::vector<double> A(N);
std::vector<double> B(N);
std::vector<double> C(N);
std::vector<double> D(N);
for(int i = 0; i < N; ++i)
A[i] = myFunction1(i);
for(int i = 0; i < N; ++i)
B[i] = myFunction2(A[i], i);
for(int i = 0; i < N; ++i)
C[i] = myFunction3(A[i], B[i]);
for(int i = 0; i < N; ++i)
D[i] = myFunction4(A[i], B[i], i);
Now write your own version of
std::transformthat takes a ternary function:I guess there might be something you can do with variadic templates in C++0x to get a
transform_N, but if so I don’t know what it is, I’ve never used them. Not sure if you can forward a variable number of arguments with modifications (in this case wrapping* ++around each one, as it were).