|
Boost : |
From: Eric Niebler (eric_at_[hidden])
Date: 2007-05-07 19:14:41
Maurizio Vitale wrote:
> Eric,
> I can get the type of a proto expression (wrapped in a user-defined skin) using
> BOOST_TYPEOF, but then I noticed BOOST_PROTO_TYPEOF in context.hpp.
>
> Which one is supposed to be used?
>
> BOOST_PROTO_TYPEOF fails on me when trying to emulate the way it is used inside context.hpp.
>
> Here is code that shows what I'm trying. If BOOST_PROTO_TYPEOF is internal only, just let me know and forget
> the code below.
BOOST_PROTO_TYPEOF is internal only. I'll rename it, and #undef it at
the end of context.hpp.
You should #include proto_typeof.hpp and use BOOST_PROTO_AUTO(), like this:
BOOST_PROTO_AUTO( expr, a+b*c );
This is equivalent to:
BOOST_AUTO( expr, boost::proto::deep_copy(a+b*c) );
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.
HTH,
-- 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