
7 Oct
2005
7 Oct
'05
5 p.m.
Oh, 1 more: There are many cases you want to define a function F that applies both to scalar, and when applied to complex the result F(x) = complex (F(real(x)), F(imag(x))). ComplexFunc is handy for this: template<typename UnaryFunction, typename in_t> inline std::complex<typename boost::result_of<UnaryFunction(typename in_t::value_type)>::type> ComplexFunc (UnaryFunction f, in_t x) { typedef std::complex<typename boost::result_of<UnaryFunction(typename in_t::value_type)>::type> ret_t; return ret_t (f (real (x)), f (imag (x))); }