我试图在跨平台的C++应用程序中使用std :: unordered_set.它在Windows下编译和工作就像Visual C++中的魅力,但在Mac OS X下的clang上产生致命的编译错误.
我想知道它为什么会发生,以及正确的方法是什么.
示例代码:
//
// Clang build cmdline:
// $ clang++ ./set.cpp -Wall -Werror -Wfatal-errors -std=c++11 -stdlib=libc++ -o set.out
//
#include <iostream>
#include <unordered_set>
struct Point {
int x, y;
Point(int x = 0, int y = 0) {
this->x = x;
this->y = y;
}
bool operator==(Point const& p) const {
return this->x == p.x && this->y == p.y;
}
operator std::size_t () const {
return std::hash<int>()(x) ^ std::hash<int>()(y);
}
};
typedef std::unordered_set<Point> points_set_t; …Run Code Online (Sandbox Code Playgroud)