C++ - 我使用哪个编译器来使自动 eq = [ ](..) 语法工作?

C++ - Which compiler do I use to get the auto eq = [ ](...) syntax to work?

本文关键字:语法 工作 eq C++ 编译器      更新时间:2023-10-16

我正在尝试运行此处答案中列出的矢量代码中元素的出现次数

但是我在这个函数中遇到了编译错误:

auto h = [](const std::string* s) {
return std::hash<std::string>()(*s);
};

[ ]周围陈述Expected expression.我知道这与编译器有关。 我正在使用Xcode 5.0.2,所以我可以选择更改编译器(我认为)。

然后我收到另一个编译错误:

std::unordered_map<const std::string*, size_t, decltype(h), decltype(eq)> m(v.size(), h, eq);

说明m(v.size(), h, eq)部分周围的C++ requires a specifier for all declarations

我应该确保Xcode使用哪个编译器进行编译才能使此代码正常工作?

更新:

我可以谷歌搜索这种auto = [ ](...)表示法的特定名称吗?

你知道考虑什么标准吗?

尝试强制到 C++11,以覆盖这些lambda结构和unordered_map.