|
Boost Users : |
Subject: Re: [Boost-users] [Proto] Forwarding evaluation via tag
From: Eric Niebler (eric_at_[hidden])
Date: 2009-09-29 10:08:01
Joel Falcou wrote:
> I have the following grammar that handles the evaluation of various
> matrix classes:
>
> struct eval_xpr
> : bp::or_< bp::when< bp::terminal< block<bp::_,bp::_> >
> , _load(bp::_)
> >
> , bp::when< bp::plus< eval_xpr,eval_xpr >
> , bp::call<
> functor<bp::tag::plus>(eval_xpr(bp::_left ), eval_xpr(bp::_right) )
> >
> >
> > {};
>
> As you can see, the functor<T> class is a Callable object but not a
> primitive Transform so I use call to be able to forward the proper
> things to it. Currently I only play with + but I wanted to know how i
> can use proto::tag_of and a clever way to conserve the recursive look so
> it works for any operator of any tag. Basically what should I do to have :
>
> bp::when< bp::nary_expr< bp::_, bp::vararg< eval_xpr > >
> , bp::call< functor< ???? >( eval_xpr(????), ???, ??? ) >
> >
>
> to work for any tag and any number of parameters while typiong the less
> code possible. I *think* I should make a new Primitive Transform that
> extarct tags and arguments from bp::_expr and then perform the call to
> functor but doesn't this mean I have to explicitly write the code for
> 1,2,3 etc arguments ?
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,
-- Eric Niebler BoostPro Computing http://www.boostpro.com
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net