
joel wrote:
Eric Niebler wrote:
I don't have a good solution at my fingertips or the time to come up with something really whiz-bang, but you can get part of the way with the proto::lazy transform. For instance, you can handle all binary expressions with:
bp::when< bp::nary_expr< bp::_, eval_xpr, eval_xpr > , bp::lazy< functor< bp::tag_of< bp::_ > >( eval_xpr(bp::_left) , eval_xpr(bp::_right) )> >
This uses proto::make to turn functor< bp::tag_of< bp::_ > > into, e.g., function< proto::tag::plus > and then uses proto::call to invoke it.
Hope that moves you in the right direction,
Aaaah bp::lazy ! I was indeed trying to find such thing like that.Maybe I can combine this with some fusion::fused or unfused somehow. I'll give this a try.
Also look into proto::functional::unpack_expr, which turns a Fusion sequence into a proto expression node. For instance, you might turn an N-ary expression into an (N+1)-ary expression representing a function invocation like (untested) ... when< nary_expr< _, vararg<eval_expr> > , function< vararg<eval_expr> >( // #1 functional::unpack_expr<tag::function>( // #2 push_front(_, terminal<functor<tag_of<_> > >()) // #3 ) ) > The idea here is to create an expression that, when evaluated by proto::function's pass-through transform (#1), does the Right Thing. You can accomplish that by first building a new expression from the old that (a) has an extra argument in the 0th position that is a terminal containing your function object, and (b) has a tag type of tag::function. First you build a new sequence with push_front (#3), and then you unpack that Fusion sequence into a new expression (#2). push_front doesn't exist yet; you'll have to write it. Just create a callable function object that does what fusion::push_front does. HTH, -- Eric Niebler BoostPro Computing http://www.boostpro.com