|
Boost : |
From: Eric Niebler (eric_at_[hidden])
Date: 2008-01-31 11:12:45
Benoit wrote:
> Hello,
>
> I am having a look at your library which seems very interesting. But
> i am having trouble finding whether there would be a way to do the
> following using Proto :
>
> typedef ... Variable; Variable x, y; evaluate( x - y );
>
> The important thing that differs from your examples is that, in this
> case, x and y have the exact same type...
That doesn't matter. If Variable is a proto expression type, x-y will
create a proto expression tree.
> As far as i understand what you have done, this implies instantiating
> both an expr<> type and the associated context at the same time.
Sorry, I don't understand.
> Such a process does not appear in any of your examples, and i can't
> see how it could be done the "Proto" way... Is it simply not possible
> ?
Given:
template<typename Expr>
typename proto::result_of::eval<
Expr const,
proto::default_context const
>::type
evaluate(Expr const &expr)
{
proto::default_context const ctx;
return proto::eval(expr, ctx);
}
You can do this:
proto::literal<int> x(12), y(4);
int z = evaluate(x - y);
And it should display "8". Substitute your own context type in
"evaluate()" and you can make it do anything you want.
-- Eric Niebler Boost Consulting www.boost-consulting.com
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk