std::max with lambda and auto
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; }
};
相关文章:
- 在for循环中使用auto vs decltype(vec.size())来处理字符串的向量
- C++核心准则 C35 对于接口类"A base class destructor should be either public and virtual, or protected and nonv
- 为什么C++逐位AND运算符在不同大小的操作数中表现为这样
- 为什么 Clang 不允许"and"作为函数名称?
- 位阵列上的快速AND运算
- 如何在自定义类中启用'auto loops'?
- 当我在第一个循环中使用"auto"时,它工作正常,但是使用"int"它会给出错误,为什么?
- 是否可以在 C++03 中定义'move-and-swap idiom'等效项
- BoostPython and CMake
- OpenSSL BIO and SSL_read
- Gurobi GRBModel and GRBmodel in C++
- 为什么当我为 for(auto& it : myUnorderedMap) {... = std::move(it.second)} 时,我会得到一个 const 引用?
- 为什么结构化绑定不使用"auto&"返回对结构成员的引用,而是返回成员本身
- 擦除许多矢量元素,同时使用'auto'
- 考虑到其他好处,关键字'auto'真的有助于简化调试C++吗?
- std::visit and std::variant usage
- std::max with lambda and auto
- C 11 std :: bind and auto的编译错误,用于回调函数参数
- C++11 auto and size_type
- auto and const object