I\'m having trouble with some valarray function pointer code:
double (*fp)(double) = sin;
valarray (*fp)(const valarray &) =
You speak about std::sin in the title, but then assign ::sin.
valarray (*fp)(const valarray &) = std::sin;
That should work. Note, that you should qualify all uses of sin, though most implementations will inject the name to the global namespace even if you include (that is non-standard behavior).
Edit: unfortunately, you're out of luck. The standard says about sin(valarray the following (26.3.3.3).
This function shall return a value which is of type T or which can be unambiguously converted to type T.
Optimizations performed by gcc are granted by the standard. The code above is not guaranteed to work.