-
July 31st, 2011, 01:35 AM
#1
C++ 0x
I have a code written in C++ 0x. Since I am not familiar with C++ 0x, I am unable to understand the following lines.
int scene[M][N];
//Fill Scene array with values
Fill_Scene(scene);
typedef std:air<size_t,size_t>connect_line;
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
#2
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
#3
Re: C++ 0x
Originally Posted by openglPrg
Please help me in me rewriting the code in a C++ version previous to 0x.
It's better to understand it. People will get tired of rewriting code for you.
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|