Boost logo

Boost :

From: Eric Niebler (eric_at_[hidden])
Date: 2007-05-22 19:26:48


Maurizio Vitale wrote:
> Eric,
> the attached file exibits a problem with (I think) display_expr:
> The second line in main() fails. But if you comment out the definition of META_EXPR(plus,left,...) and replace it with the one
> just below it and presently commented out then everything is fine.
> Seems like display_expr is not appy with function applied to more than one argument.
>
> Unless there's something stupid in my code.

Essentially, what you're doing is:

BOOST_TYPEOF(some + proto + expr) e = some + proto + expr;
// Use e

It doesn't work quite like this. The reason why is that "some + proto +
expr" is a tree where some of the nodes are temporary objects, which are
held by reference by other nodes. It's a castle in the air, and at the
semicolon, it crashes down.

You need proto::deep_copy():

BOOST_TYPEOF(proto::deep_copy(some + proto + expr)) e =
proto::deep_copy(some + proto + expr);
// Use e

Or even better:

BOOST_PROTO_AUTO(e, some + proto + expr);

which does the deep_copy for you.

-- 
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