
On 12/10/2010 11:57 AM, Hossein Haeri wrote:
Dear all,
I am trying to use callable_contexts to evaluate expressions like:
x >> f >> g >> h;
where this would be equivalent to h(g(f(x))). I have derived my context from callable_context, and thought I have overloaded for relevant tags (terminal and shift_right). GCC 4.5.1 (MinGW32, WinXP, SP3) stops with an error message which is cryptic to my current level of knowledge about Proto. I guess that's because I haven't done the job correctely. For your reference, I have included a copy of my program as well as the error GCC gives me in the P.S. section of this posting. Any ideas please?
Contexts make life harder, and I hope to deprecate them in the future. Here's what the solution looks like using transforms: #include <boost/proto/proto.hpp> #include <iostream> namespace proto = boost::proto; using proto::_; struct add_one_ { typedef int result_type; int operator()(int i) const { return i + 1; } }; proto::terminal<add_one_>::type const add_one = {}; struct GetFun : proto::call<proto::_value(proto::_right)> {}; struct EvalStream : proto::or_< proto::when< proto::terminal<_> , proto::_value > , proto::when< proto::shift_right<EvalStream, proto::terminal<_> > , proto::lazy< GetFun(EvalStream(proto::_left)) > > > {}; int main() { // This prints "3" std::cout << EvalStream()( 1 >> add_one >> add_one ) << std::endl; } HTH, -- Eric Niebler BoostPro Computing http://www.boostpro.com