From: Eric Niebler (eric_at_[hidden])
Date: 2007-05-08 02:05:30
Maurizio Vitale wrote:
> Eric Niebler <eric_at_[hidden]> writes:
>> Nodes in proto's expression tree are held by reference, so that building
>> an expression tree requires no copying. But some nodes are temporaries.
>> deep_copy() forces all nodes to be held by value, which is necessary if
>> you're storing them in a local variable like this.
> Actually, I'm trying to do the opposite: I have expressions used to
> represent the way to do quantization and manage overflow which have
> noting to refer to when they're created, so they're made of operators
> and terminals with no data in. The type is all that is needed for
> evaluating them, and the evaluation context will know where to grab
> the data from. Although evaluation is driven by the type, it is a
> run-time evaluation.
> I hope to be able to use evaluation contexts for this, if it doesn't
> work either transforms or an homebrewed solutions (but still using
> proto for describing the expression).
proto::eval() takes an expression and a context. So you need an
expression, not just the expression's type. You can write a transform
that works with types, but if you want to manipulate runtime data (and
you say you do), the transforms will also need an expression object.
(Recall that the transforms take an expression, in addition to the state
and a visitor.)
But if you want it, BOOST_TYPEOF() should get you the type of a proto
expression, once you include proto_typeof.hpp to get the type registrations.
> Since you mentioned by-ref/by-value, there's something I meant to ask:
> proto stores by ref: wouldn't be possible to let the terminal decide?
> When data is a simple builtin, by-value would be more efficient.
> I haven't checked the implementation, so I'm not sure the above makes
I considered that, but decided against it. It would take an extra
compile-time conditional to decide whether to store by value or
reference (that is, at least one extra template instantiation per
terminal type). And lots of stuff would still be stored by reference, so
people will still need to use deep_copy(). I don't see an obvious win to
storing some terminals by value and others by reference. I'm happy to be
proven wrong, however.
-- 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