As you can see from other posts. It's been quite painful to me to
debug programs with expression templates. In order to debug some code
I implemented some functions to print the expression trees, this would
be a nice addition to Boost.Lambda and also to Boost.Phoenix (although
Boost.Phoenix will probably have it through Boost.Proto which
apparently already can print its expression trees).
Here it is a *minimal* code for printing some Boost.Lambda expression
(involving only [binary +,-,/,*],bind,constants), (let me know if I am
reinventing the wheel)
namespace boost{
namespace lambda{
using namespace boost::tuples;
template<int N> //print placeholder
std::string to_string(const
lambda_functor&){
return "_"+boost::lexical_caststd::string(N);
}
//template<class T>
//std::string to_string(const T& t){
// return boost::lexical_caststd::string(t);
//}
//binary operators
#define BOOST_LAMBDA_TO_STRING_GEN(action_name, symbol_string)\
template \
std::string to_string(const \
lambda_functor,
tuple< \
LExp1, \
LExp2 \
> > >& action_name##_expr){ \
return to_string(get<0>(action_name##_expr.args)) + #symbol_string
+to_string(get<1>(action_name##_expr.args)); \
}
BOOST_LAMBDA_TO_STRING_GEN(plus_action, +);
BOOST_LAMBDA_TO_STRING_GEN(divide_action, /);
BOOST_LAMBDA_TO_STRING_GEN(minus_action, -);
BOOST_LAMBDA_TO_STRING_GEN(multiply_action, *);
//bind
template
std::string to_string(const
lambda_functor >,
tuple<
FunctionType, //double (* const)(double),
LExpr
>
> >& bind_expr){
return std::string("bind(")
+boost::units::detail::demangle(typeid(FunctionType).name()) +",
"+to_string(get<1>(bind_expr.args)) + ")";
}
}}
Cheers,
Alfredo