I\'m having trouble with some valarray function pointer code:
double (*fp)(double) = sin;
valarray (*fp)(const valarray &) =
26 3.1/3
Any function returning a valarray is permitted to return an object of another type, provided all the const member functions of valarray are also applicable to this type.
The aim is to allow template expressions to be used to optimize the result (i.e. looping one time on the whole array doing each times the computation, directly assigning to the resulting valarray<> instead of building a temporary).
z = sin(x+y);
can be optimized to
for (i = 0; i < N; ++i)
z[i] = sin(x[i] + y[i]);