July 31st, 2011, 01:35 AM
I have a code written in C++ 0x. Since I am not familiar with C++ 0x, I am unable to understand the following lines.
//Fill Scene array with values
auto __greater = [&scene] (connect_line const& x, connect_line const& y)
return scene[x.first][x.second] > scene[y.first][y.second];
Please help me in me rewriting the code in a C++ version previous to 0x.
July 31st, 2011, 02:05 AM
Re: C++ 0x
This code uses the auto keyword which is nothing special, the rest is a lambda function. The closest thing in this case would be to replace it with a functor.
July 31st, 2011, 02:16 AM
Re: C++ 0x
It's better to understand it. People will get tired of rewriting code for you.
Originally Posted by openglPrg
You have a lambda expression assigned to the __greater variable. Auto means its type is deducted by the compiler so you don't have to bother. You can use __greater whenever you used a function object before. So in principle the lambda expression defines a function object.
The lambda expression itself uses (captures) the scene variable by reference so it won't get copied. It takes two variables (by const reference) of the connect_line type as parameters. It compares two scene positions and determines whether the first is greater than the second. The bool return type is deducted automatically.
Last edited by nuzzle; July 31st, 2011 at 05:27 AM.
Click Here to Expand Forum to Full Width