« Return to Thread: How can I save the values in lambda expression? Can any one with kindness help me?

Re: How can I save the values in lambda expression? Can any one with kindness help me?

by Johan Nilsson-4 :: Rate this Message:

Reply to Author | View in Thread


"fmingu" <fmingu@...> wrote in message
news:31100020.905591247202195143.JavaMail.coremail@......

>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 mailing list
Boost-users@...
http://lists.boost.org/mailman/listinfo.cgi/boost-users

 « Return to Thread: How can I save the values in lambda expression? Can any one with kindness help me?