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: Steven Watanabe (watanabesj_at_[hidden])
Date: 2009-07-09 00:57:46


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