« 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 Zachary Turner-2 :: Rate this Message:

Reply to Author | View in Thread

2009/7/8 fmingu <fmingu@...>:

> As you know, I am a Chinese 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. 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:
> ..........
> 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.
> Thanks a lot.

Try to do only

std::cout << switchvalue << std::endl;

The value has already been saved, there is no need to use var outside
of the lambda expression.  for example, in the for_each code you
posted, the reason to use var is because

std::for_each(vec.begin(),vec.end(), m=_1);

is not legal.  However, using var it will basically have the same
effect.  Once the lambda function has executed, m directly contains
the updated value and you can access it like any variable.
_______________________________________________
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?