|
Boost : |
From: Eric Niebler (eric_at_[hidden])
Date: 2008-03-12 07:09:06
Markus Werle wrote:
>> So you can say "fun + fun" and build a new node
>> representing an addition. Or you can say "fun(fun)" to build a new node
>> representing a function call. You could even say "(fun + fun)(fun, fun
>> fun)". But that would be too much fun.
>
> Is the following statement correct:
>
> expr< tag::terminal, args0< placeholder_t >, 0 >::operator()(...args...)
> returns an expression representation that during evaluation via
> proto::eval() first evaluates its arguments and then delegates the result to
> to placeholder_t::operator()( ... args... ).
No. proto::eval() has no behavior independent of a context and treats no
expression types specially. If you are talking about how the
default_context handles tag::function, then the answer is, almost. For a
default_context C and an expression E with E::proto_tag of
tag::function, then proto::eval(E, C) is equivalent to:
proto::eval(proto::arg_c<0>(E),C)(
proto::eval(proto::arg_c<1>(E),C)
,proto::eval(proto::arg_c<2>(E),C)
,...
)
So the left-most arg is evaluated and the result is treated as a
callable object. The rest of the arguments are evaluated and their
results are treated as arguments to the callable object.
In your case, the result of evaluating a placeholder_t terminal with the
default_context is simply the placeholder_t object itself. In that case,
yes, the default_context would dispatch to any placeholder_t::operator().
> In contrast to this all other operators (+, -, *, / etc.)
> return an expression representation that during evaluation via
> proto::eval(expr, context) first evaluates its arguments and then
> delegates the result to context::operator()(proto::tag::xxx, ...args...)
operator()'s handling is consistent with the other operators.
> If the above is correct: can I write
> my_context::operator()(proto::tag::fucntion, ...args...) to catch it first
> and hinder delegation to placeholder_t::operator()(...args...)?
Yes, you can specify in your context how tag::function expressions
should be handled.
-- 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