Std :: max with lambda and auto

Could this be done with C ++ 11?
With current clang compilers (Xcode 5 on OS X 10.8), it does not compile:

std::max_element(group->GetComponents().begin(), group->GetComponents().end(),
                 [](auto a, auto b) { return a.length > b.length; });

Error message: Stuff.cp: 68: 40: "auto" is not allowed in the function prototype

+4
source share
1 answer

In C ++ 1y, you have generic lambdas, so the syntax will compile in clang 3.5 . The lambda will look like this:

class /* unnamed */
{
public:
    template<typename T>
    T operator () (T a) const { return a; }
};
0
source

Source: https://habr.com/ru/post/1528191/


All Articles