[phoenix] conditional expression?
Hi, Does Phoenix support conditional expression? I know if supports if_ *statements* but it seems that there's is no conditional (expression*. The question what is is the equivalent for "(x>2.)?(1.):(-1.)" in general. For example, I tryed with if_[].else_[] hoping that the statement is used as result but with no luck: #include<boost/phoenix/phoenix.hpp> #include<iostream> using namespace boost::phoenix; using namespace boost::phoenix::arg_names; int main(){ std::clog << (arg1*arg1)(2.) << std::endl; //returns correctly 4 std::clog << (if_(arg1>2.)[val(1.)].else_[val(-1.)])(2.) << std::endl; //syntax error return 0; } The syntax error points that the expression fails to evaluate as a number. Any ideas? -- Thanks, Alfredo usr/include/boost/proto/operators.hpp:79:9: error: forming reference to void if.cpp:8:43: error: no match for ‘operator<<’ in ‘std::clog << boost::phoenix::if_ [with Cond = boost::phoenix::actor<boost::proto::exprns_::basic_expr<boost::proto::tag::greater, boost::proto::argsns_::list2<boost::phoenix::actor<boost ... etc, etc, 100 lines
2011/5/2 alfC <alfredo.correa@gmail.com>
Hi, Does Phoenix support conditional expression? I know if supports if_ *statements* but it seems that there's is no conditional (expression*. The question what is is the equivalent for
"(x>2.)?(1.):(-1.)"
in general. For example, I tryed with if_[].else_[] hoping that the statement is used as result but with no luck:
#include<boost/phoenix/phoenix.hpp> #include<iostream> using namespace boost::phoenix; using namespace boost::phoenix::arg_names; int main(){ std::clog << (arg1*arg1)(2.) << std::endl; //returns correctly 4 std::clog << (if_(arg1>2.)[val(1.)].else_[val(-1.)])(2.) << std::endl; //syntax error return 0; }
The syntax error points that the expression fails to evaluate as a number. Any ideas? -- Thanks, Alfredo
See: http://tinyurl.com/4xqsezx simply: std::clog << if_else(arg1>2., 1., -1.)(2.) << std::endl; HTH
On May 2, 3:16 am, TONGARI <tongar...@gmail.com> wrote:
The syntax error points that the expression fails to evaluate as a number. Any ideas? -- Thanks, Alfredo
See:
of course, in the "Operators" section of the manual - Thank you.
On Mon, May 2, 2011 at 11:58 AM, alfC <alfredo.correa@gmail.com> wrote:
Hi, Does Phoenix support conditional expression? I know if supports if_ *statements* but it seems that there's is no conditional (expression*. The question what is is the equivalent for
"(x>2.)?(1.):(-1.)"
in general. For example, I tryed with if_[].else_[] hoping that the statement is used as result but with no luck:
#include<boost/phoenix/phoenix.hpp> #include<iostream> using namespace boost::phoenix; using namespace boost::phoenix::arg_names; int main(){ std::clog << (arg1*arg1)(2.) << std::endl; //returns correctly 4 std::clog << (if_(arg1>2.)[val(1.)].else_[val(-1.)])(2.) << std::endl; //syntax error return 0; }
The syntax error points that the expression fails to evaluate as a number. Any ideas? -- Thanks, Alfredo
if_(...)[...] and if_(...)[...].else_[...] always return void. This is the problem you are seeing. There is a solution to this problem: http://goo.gl/gjH7F ... if_else(arg1 > 2., val(1.), val(-1.)) ... Regards, Thomas
participants (3)
-
alfC
-
Thomas Heller
-
TONGARI