Hi, I need some complex arithmetic in lambda expressions, for that I
implemented this to make some std::complex functions work with
Boost.Lambda.
namespace boost{
namespace lambda{
#define BOOST_LAMBDA_COMPLEX_IMPL(function_name) \
template<typename Arg> \
lambda_functor >, \
boost::tuples::tuple< \
const double& (* const)(const std::complex<double>&), \
const lambda_functor<Arg> \
> \
function_name(const lambda_functor<Arg>& f){ \
return boost::lambda::bind(static_cast(&std::function_name<double>), f); \
}
BOOST_LAMBDA_COMPLEX_IMPL(real)
BOOST_LAMBDA_COMPLEX_IMPL(imag)
BOOST_LAMBDA_COMPLEX_IMPL(abs)
BOOST_LAMBDA_COMPLEX_IMPL(norm)
}
}
use as
boost::function f = imag(_1) + real(_1) +
abs(_1+2.);
I have two questions about it:
1) Is this something that is implemented in some other way already?
2) it seem imposible to generalized to other template overloads of
imag<T>, real<T> (i.e. something that can be used for std::complex<T>)
because the template parameter Arg doesn't have information about the
actual type. is it so?
(comments on the code and alternatives also accepted)
Thank you,
Alfredo