|
Boost Users : |
Subject: [Boost-users] [Proto] Recreating an expression
From: christophe henry (henry_christophe_at_[hidden])
Date: 2009-07-03 10:42:36
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<typename proto::terminal<guard_tag>::type>
{...}
These terminals are used with a simple grammar:
struct BuildGuards
: proto::or_<
proto::when<
proto::logical_or<BuildGuards,BuildGuards >,
GuardOR<BuildGuards(proto::_left),BuildGuards(proto::_right)>()
>,
proto::when<
proto::logical_and<BuildGuards,BuildGuards >,
GuardAND<BuildGuards(proto::_left),BuildGuards(proto::_right)>()
>,
proto::when<
proto::logical_not<BuildGuards >,
GuardNOT<BuildGuards(proto::_value)>()
>,
proto::when <
proto::terminal<guard_tag>,
proto::_()
>
>
{};
Then, expressions like:
True()|| False() give the expected result (struct GuardOR<struct True,struct False>).
Even True()&& (Dummy1() || !(False() || True())) give the expected result:
struct GuardAND<struct True,struct GuardOR<struct Dummy1,struct GuardNOT<struct GuardOR<struct False,struct True> > > >
But a "!" alone (meaning followed by just a terminal, not the other parts of the BuildGuards grammar) breaks all (as do all unary operators I tried), like !False() or True()|| !False().
!False() =>
struct GuardNOT<struct mp_terminal<struct boost::proto::exprns_::expr<struct boost::proto::tag::terminal,struct boost::proto::argsns_::term<struct guard_tag>,0> > >
Notice that !(False() || True()) works!
Now, if I do not derive from mp_terminal but instead proceed as documented, all works as expected:
proto::terminal<True>::type True_;
...
!False_ => correct result.
Sadly, this documented usage is unpractical in my use case.
So, supposing that I managed this easy grammar, I imagine that the usage I do of terminals (deriving from them) is not allowed.
Then, why do most use cases work like a charm? Only unary operators seem to fail.
Attached are 2 test files. V1 doesn't work in all cases while V2 does.
I use 1.38.
Thanks a lot!
Christophe
_________________________________________________________________
Windows Live: Keep your life in sync. Check it out!
http://windowslive.com/explore?ocid=TXT_TAGLM_WL_t1_allup_explore_012009
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net