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 "<
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