Boost logo

Boost Users :

Subject: Re: [Boost-users] How can I save the values in lambda expression? Can any one with kindness help me?
From: Johan Nilsson (r.johan.nilsson_at_[hidden])
Date: 2009-07-10 02:58:17


"fmingu" <fmingu_at_[hidden]> wrote in message
news:31100020.905591247202195143.JavaMail.coremail_at_bj163app94.163.com...
>After your advice,I wrote the following test program:
>int main(int argc, char *argv[])
>{
> int nnumber=7;
> int switchvalue=1;
> if_then_else(var(nnumber)==6, var(switchvalue)=3
> ,var(switchvalue)=30);
> std::cout<<" the nnumber is "<<nnumber<<" and switchvalue is
> "<<switchvalue<<"\n";
> system("PAUSE");
> return 0;
>}
>and the result is:
>the nnumber is 7 and and switchvalue is 1
>Even
>if_then_else(var(nnumber)==6, var(switchvalue)=constant(3)
> ,var(switchvalue)=constant(30));
>get the same result.
>
>the value in the lambda expression did not saved.
>Can you tell me why?

if_then_else only creates and returns a lambda function object.

>And How can I correct it?

You need to apply it (note invoking the fn call operator):

if_then_else(var(nnumber)==6, var(switchvalue)=3
                               ,var(switchvalue)=30)();

HTH / Johan


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