
Maurizio Vitale wrote:
Eric Niebler <eric@boost-consulting.com> writes:
Maurizio, deep_copy() alone will not work here. The user is creating a lambda expression and assigning it directly to function<>:
function<int(int&,int&)> f(_0 + _1);
function<> knows nothing about proto expressions, and doesn't know to call proto::deep_copy().
Rats! (apologizes to Dan, I didn't intend to mislead)
But now I'd appreciate you entering "grade school mode" and do some explaining.
My mental model was: - proto::deep_copy traverse the expression top-down replacing references with value.
Actually, bottom-up, but yes references are replaced with values.
- generators are used to wrap expressions as they are built bottom-up
Generators are used whenever you want to customize the result of proto's operator overloads.
So, assuming that the expression is properly wrapped in lambda_expr<> why the result of calling proto::expr on the whole expression would be different from using the generator?
Sorry, I don't understand the question.
And why this would tell function<> more about proto expressions?
It doesn't.
What am I missing?
Maybe you're not clear on how generators work. (Not surprising, it isn't documented yet.) By default, proto's operator overloads create proto::expr<> objects in which everything (terminals and non-terminals) are held by reference. Generators give you a hook where you can customize the operators' return types. The operator overload passes the generator the new node (bare proto::expr<>, sub-nodes held by reference) and the generator is free to do whatever it wants with it. It can wrap it in a domain-specific wrapper, deep_copy it, or whatever. How this helps is that as phoenix expressions are being built, the phoenix generator will ensure that all the nodes are held by-value. There will never be a need for the user to deep_copy phoenix expressions explicitly -- it's done piecemeal by phoenix. So function<> is passed an object that does not need to be deep-copied. HTH, -- Eric Niebler Boost Consulting www.boost-consulting.com The Astoria Seminar ==> http://www.astoriaseminar.com