|
Boost Users : |
Subject: Re: [Boost-users] [phoenix] conditional expression?
From: TONGARI (tongari95_at_[hidden])
Date: 2011-05-02 06:16:17
2011/5/2 alfC <alfredo.correa_at_[hidden]>
> 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:
simply:
std::clog << if_else(arg1>2., 1., -1.)(2.) << std::endl;
HTH
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