Re: [boost] [ANN] Phoenix-2 prerelease

Joel de Guzman wrote:
Docs: http://tinyurl.com/77pz5
In "Block Statement", (http://tinyurl.com/b25hr) you show how to use the comma operator to sequence statements. I see problems here, especially when calling a function that takes a predicate that isn't the last argument. For instance, how would you use Phoenix to create a filter_iterator? iterator begin, end; ... boost::make_filter_iterator(arg1 > 5, begin, end); // Oops! ---------------------------^ Isn't that comma going to be Phoenix's overloaded comma? -- Eric Niebler Boost Consulting www.boost-consulting.com

Eric Niebler wrote:
Joel de Guzman wrote:
Docs: http://tinyurl.com/77pz5
In "Block Statement", (http://tinyurl.com/b25hr) you show how to use the comma operator to sequence statements. I see problems here, especially when calling a function that takes a predicate that isn't the last argument. For instance, how would you use Phoenix to create a filter_iterator?
iterator begin, end; ... boost::make_filter_iterator(arg1 > 5, begin, end); // Oops! ---------------------------^
Isn't that comma going to be Phoenix's overloaded comma?
No. If you want the comma operator to fire, you have to place them inside parentheses: boost::make_filter_iterator((arg1 > 5, blah1, blah2), begin, end); I remember a very early version of Phoenix named SE (short for semantic expressions) and Spirit where I used the () operator instead of the [] operator. For compound expressions, I had to use the double parens. Example: if_(c) (( do_this, then_than, finaly_that )) Otherwise, C++ will complain. Regards, -- Joel de Guzman http://www.boost-consulting.com http://spirit.sf.net

On 10/12/05 7:31 PM, "Eric Niebler" <eric@boost-consulting.com> wrote:
Joel de Guzman wrote:
Docs: http://tinyurl.com/77pz5
In "Block Statement", (http://tinyurl.com/b25hr) you show how to use the comma operator to sequence statements. I see problems here, especially when calling a function that takes a predicate that isn't the last argument. For instance, how would you use Phoenix to create a filter_iterator?
iterator begin, end; ... boost::make_filter_iterator(arg1 > 5, begin, end); // Oops! ---------------------------^
Isn't that comma going to be Phoenix's overloaded comma?
I don't think so. The comma used to separate function (call) arguments always overrides a comma operator. In fact, the docs for the block statement (as of 2005-Oct-13) mention that: //===================================================================== Outside the square brackets, block statements should be grouped. For example: //------------------------------------------ for_each(c.begin(), c.end(), ( do_this(arg1), do_that(arg1) ) ); //------------------------------------------ //===================================================================== Wrapping a comma operator chain around a parentheses pair blocks the interpretation as an argument separator. The reason for the exception for the square bracket operator is that the operator always takes exactly one argument, so it "transforms" any attempt at multiple arguments with a comma operator chain (and spits out an error for zero arguments). -- Daryle Walker Mac, Internet, and Video Game Junkie darylew AT hotmail DOT com

Daryle Walker wrote:
I don't think so. The comma used to separate function (call) arguments always overrides a comma operator. In fact, the docs for the block statement (as of 2005-Oct-13) mention that:
//===================================================================== Outside the square brackets, block statements should be grouped. For example:
//------------------------------------------ for_each(c.begin(), c.end(), ( do_this(arg1), do_that(arg1) ) ); //------------------------------------------ //=====================================================================
Wrapping a comma operator chain around a parentheses pair blocks the interpretation as an argument separator. The reason for the exception for the square bracket operator is that the operator always takes exactly one argument, so it "transforms" any attempt at multiple arguments with a comma operator chain (and spits out an error for zero arguments).
I think this is a good explanation. I updated the docs and added this. Thanks, -- Joel de Guzman http://www.boost-consulting.com http://spirit.sf.net
participants (3)
-
Daryle Walker
-
Eric Niebler
-
Joel de Guzman