std::max with lambda and auto



这不应该在C++11中实现吗?
使用当前的 clang 编译器(OS X 10.8 上的 Xcode 5),它无法编译:

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

错误消息是:Stuff.cp:68:40: 函数原型中不允许使用"自动"

在 C++1y 中,你有通用的 lambda,所以语法将在 clang 3.5 中编译。lambda 将如下所示:

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

最新更新