Re: [Boost-users] still stuck on expectation points

This start %= (constitkind > id > ':' > id >> probs) % ","; // FAILS Should read start %= (constitkind >> id > ':' > id >> probs) % ","; // FAILS Sorry.

On Fri, Apr 16, 2010 at 6:34 PM, philip tucker
This
start %= (constitkind > id > ':' > id >> probs) % ","; // FAILS
Should read
start %= (constitkind >> id > ':' > id >> probs) % ","; // FAILS
Sorry.
Because of how operator precedence works in C++. You should pretty well memorize the C++ precedence rules before starting to use more advanced C++ features that rely on fancy operator usage, else run into a lot of 'fun' things like this. Basically this: start %= (constitkind >> id > ':' > id >> probs) % ","; Is read as this to the C++ parser: start %= (constitkind >> (id > ':' > id) >> probs) % ","; Because greater-then's have a different precedence level then right-shifts.

On Fri, Apr 16, 2010 at 7:47 PM, philip tucker
On 16 Apr 2010, at 6:16 PM, OvermindDL1 wrote:
start %= (constitkind >> (id > ':' > id) >> probs) % ",";
Thanks, but I already tried it. Doesn't compile.
Er, if you re-read my post I was saying *not* to do that, because that will not work, that is actually what the compiler is doing because of operator precedence. You should memorize the precedence rules for C++, *especially* if you are going to be dealing with heavily templated operator libraries like Spirit. http://en.wikipedia.org/wiki/Operators_in_C_and_C%2B%2B Because you are mixing right-shifts (>>) and greater-than's (>), the precedence causes them to collapse in different ways, which is why you need the parenthesis like this: start %= (constitkind >> (id > (':' > (id >> probs)))) % ","; Again, learn the C++ operator precedence rules and all this will make easy sense. :)

On 16 Apr 2010, at 6:52 PM, OvermindDL1 wrote:
On Fri, Apr 16, 2010 at 7:47 PM, philip tucker
wrote: On 16 Apr 2010, at 6:16 PM, OvermindDL1 wrote:
start %= (constitkind >> (id > ':' > id) >> probs) % ",";
Thanks, but I already tried it. Doesn't compile.
Er, if you re-read my post I was saying *not* to do that, because that will not work, that is actually what the compiler is doing because of operator precedence. You should memorize the precedence rules for C++, *especially* if you are going to be dealing with heavily templated operator libraries like Spirit. http://en.wikipedia.org/wiki/Operators_in_C_and_C%2B%2B
Because you are mixing right-shifts (>>) and greater-than's (>), the precedence causes them to collapse in different ways, which is why you need the parenthesis like this: start %= (constitkind >> (id > (':' > (id >> probs)))) % ",";
Again, learn the C++ operator precedence rules and all this will make easy sense. :) _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
If I have understood your advice correctly, you suggest that this code should compile:
start %= (constitkind >> (id > (':' > (id >> probs)))) % ",";
It doesn't.

On 16 Apr 2010, at 6:16 PM, OvermindDL1 wrote:
start %= (constitkind >> id > ':' > id >> probs) % ","; // FAILS
start %= (constitkind >> (id > ':' > id) >> probs) % ",";
I see what you are saying about precedence. I don't see how to write an expression which does what I want. I appreciate your help.

On 4/17/2010 10:03 AM, philip tucker wrote:
On 16 Apr 2010, at 6:16 PM, OvermindDL1 wrote:
start %= (constitkind >> id > ':' > id >> probs) % ","; // FAILS
start %= (constitkind >> (id > ':' > id) >> probs) % ",";
I see what you are saying about precedence. I don't see how to write an expression which does what I want.
I appreciate your help.
Here's a tip: use rules to break your expressions into manageable chunks. Regards, -- Joel de Guzman http://www.boostpro.com http://spirit.sf.net http://www.facebook.com/djowel Meet me at BoostCon http://www.boostcon.com/home http://www.facebook.com/boostcon
participants (3)
-
Joel de Guzman
-
OvermindDL1
-
philip tucker