Say I have the following template function:
template <class T>
void apply(const vector<complex<T> >& in, vector<T>& out, T (*f)(complex<T>))
{
out.resize(in.size());
for(size_t i = 0; i < in.size(); ++i) out[i] = f(in[i]);
}
You can see, I just want to apply a function to a vector of complex data, and store the results into a vector of real data. I figure this should be good for a whole list of function: abs, norm, real, imag, etc.
My problem is, how do I pass a function in?
I have tried variants of apply(in, out, abs)
supplying different templates to abs
with no luck. I am pretty sure the problem stems from the functions for complex all being templates, but I am not sure how to pass it properly. Thanks for the help.