尝试定义一个vector的unordered_set时会出现错误,错误提示为:“调用了unordered_set< vector<int> >
的已删除默认构造函数”。但是,如果定义一个常规的(有序的)set:set< vector<int> >
则不会出现这种情况。看起来我需要定义一个hash<vector<int>>
才能摆脱这个错误。
有人知道为什么只有在使用unordered_set
时才会出现此错误吗?两种数据结构都应该使用哈希,那么为什么unordered_set需要自定义哈希函数?实际上,一个常规的(有序的)set
是否也需要一些自定义比较器以便对vector<int>
数据结构进行排序?
std::vector
已经重载了<
运算符。这就是为什么它可以与std::set
一起使用的原因。 - PaulMcKenziestd::set
不使用哈希。 - Mankarseunordered_set<T*>
而不是unordered_set<T>
,因为mysql-server和rocksdb都广泛使用了它。 - Lewis Chan