CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: C++ 0x

  1. #1
    Join Date
    Jul 2011
    Posts
    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.

  2. #2
    Join Date
    Aug 2008
    Posts
    902

    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.

  3. #3
    Join Date
    May 2009
    Posts
    2,413

    Re: C++ 0x

    Quote Originally Posted by openglPrg View Post
    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
  •  





Click Here to Expand Forum to Full Width

Featured