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: fmingu (fmingu_at_[hidden])
Date: 2009-07-10 01:03:15


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? And How can I correct it?
Thanks a lot.

ÔÚ2009-07-09£¬"Steven Watanabe" <watanabesj_at_[hidden]> дµÀ£º
>AMDG
>
>fmingu wrote:
>> As you know, I am a Chinese
>
>As a matter of fact I didn't know.
>
>> and according to my knowledge few book in Chinese introduce boost library. I only have the book " Beyond the C++ Standard Library: An introduction to boost" (written by Bjoern Karlsson, translated in Chinese).Only several pages said about lambda. I tried to ask www.csdn.net( a Chinese developers' net) and few people answered my questions. I have not studied the source code of lambda yet.
>
>The official documentation is at http://www.boost.org/libs/lambda.
>I believe that there is also an Chinese translation project which
>you might want to check.
>http://code.google.com/p/boost-doc-zh/
>
>> So all I have to do is to ask www.boost.org to get answers and go forth.
>> I think the var(switchvalue) is a pointer to a function from the example code in the book:
>>
>
>var(switchvalue) actually returns a function object which
>returns a reference to switchvalue.
>A function pointer wouldn't work for numerous reasons.
>The point I was trying to make was that
>std::cout << var(switchvalue)
>doesn't actually do anything. It returns another function object.
>So, for example, this will work
>(std::cout << var(switchvalue))();
>and will print the value of switchvalue.
>Not that you'd actually want to write code like
>that. The correct way is to leave off the var
>as Zachary noted.
>
>> ..........
>> std::for_each(vec.begin(),vec.end(),var(m)=_1);
>> ..............
>> So the operations in m can be performed. Am I right?
>> But I do not know how to save the values in lambda expression.
>>
>
>In Christ,
>Steven Watanabe
>



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