다음 코드는 unordered_set
을 정의합니다. 코드가 잘 컴파일됩니다. 그러나 발견을 호출 할 때 펑 던져 대신 람다 함수를 사용하여 :lambda를 사용하면 해시 함수가 예외를 throw 함 do
의 libC++ abi.dylib : 예외를 던지는라고 종료
#include <unordered_set>
class pair_hash {
public:
size_t operator() (const std::pair<int, int> &x) const {
return std::hash<int>()(x.first)^std::hash<int>()(x.second);
}
};
int main() {
std::unordered_set<std::pair<int, int>, pair_hash> temp;
temp.find(std::make_pair(0,0));
std::function<std::size_t(std::pair<int , int>)> fpair_hash;
fpair_hash = [](const std::pair<int, int>& v) -> std::size_t
{
return std::hash<int>()(v.first)^std::hash<int>()(v.second);
};
std::unordered_set<std::pair<int, int>, decltype(fpair_hash)> temp2;
//why does this not work?
temp2.find(std::make_pair(0,0));
return 0;
}
그 소리 ++ -std = C++ 11 -stdlib = libc의 ++ -o 테스트 Test.cpp에
'return std :: hash() (std :: hash () (v.first)^v.second);에 대해 논할 것이다. –
Yakk