【发布时间】:2020-08-23 09:06:14
【问题描述】:
我不确定我理解为什么会这样编译。
#include <iostream>
#include <iterator>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>
#include <unordered_set>
#include <algorithm>
#include <queue>
using namespace std;
void thing() {
auto hash = [](const std::pair<int, int> &pair) {
return std::hash<string>()(to_string(pair.first));
};
auto map = std::unordered_map<std::pair<int, int>, int, decltype(hash)>();
}
int main() {
}
我还没有将散列函数传递给构造函数——它如何知道散列一对的实现?
【问题讨论】:
-
你传入了哈希函数的类型;够了。
-
您确定您将其编译为 C++11 而不是 C++2a?
-
仅 为我编译为 C++2a,请参阅:wandbox.org/permlink/6KU1hDxw4wSsWRUa
标签: c++ dictionary hash