[Proto] Recreating an expression
Thanks Eric for your fast answer!
Unfortunately, this doesn't solve my problem. To make a very very long discussion long, here a small
example showing the problem from another side:
I have an expression wrapper called mp_terminal and I define terminals, but not in the documented
way (which I suspect is the problem) but instead deriving from them (for convenience purposes), for example:
struct True : mp_terminal
{};
Then, expressions like:
True()|| False() give the expected result (struct GuardOR
christophe henry wrote:
Thanks Eric for your fast answer! Unfortunately, this doesn't solve my problem. To make a very very long discussion long, here a small example showing the problem from another side: I have an expression wrapper called mp_terminal and I define terminals, but not in the documented way (which I suspect is the problem)
Indeed.
but instead deriving from them (for convenience purposes), for example: struct True : mp_terminal
::type> {...}
<snip>
Then, why do most use cases work like a charm? Only unary operators seem to fail.
It's because (a) True is a Proto type, but hasn't been made so by
directly using proto::extends, and (b) Proto's unary operators are being
a little too nit-picky about (a).
I have fixed (b) on trunk (changelist 54610). In the mean time, you can
change your definition of True and False to use this formulation:
struct True
: proto::extends<
mp_terminal
Here's a little extra feedback that I forgot include in my first reply. christophe henry wrote:
These terminals are used with a simple grammar: struct BuildGuards : proto::or_< proto::when< proto::logical_or
, GuardOR
() >, proto::when< proto::logical_and , GuardAND
() >, proto::when< proto::logical_not<BuildGuards >, GuardNOT ()
Use proto::_child instead of proto::_value here. proto::_value returns the value of a terminal node. proto::_child returns the child of a unary expression tree node. It's really just luck that this is working for you.
>, proto::when < proto::terminal
, proto::_()
I would use proto::_ here instead of proto::_(). They mean the same thing, but proto::_ is more idiomatic. See the following section for an explanation of why proto::_ and proto::_() are equivalent when used as transforms: http://www.boost.org/doc/libs/1_39_0/doc/html/proto/users_guide.html#boost_p... -- Eric Niebler BoostPro Computing http://www.boostpro.com
participants (2)
-
christophe henry
-
Eric Niebler