Chinaunix
标题:
unordered_set使用自定义hash函数编译错误,帮忙砍下
[打印本页]
作者:
zhycjh
时间:
2018-07-28 23:00
标题:
unordered_set使用自定义hash函数编译错误,帮忙砍下
如题,我测试了一下:
int main(){
auto f=[](const node& n){
return (size_t)n.value;
};
unordered_set<node, decltype(f)> s2;
return 0;
}
复制代码
编译错误:
g++ -std=c++11 usehashset.cpp
usehashset.cpp: In function ‘int main()’:
usehashset.cpp:21:39: error: use of deleted function ‘std::unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set() [with _Value = node; _Hash = main()::<lambda(const node&)>; _Pred = std::equal_to<node>; _Alloc = std::allocator<node>]’
unordered_set<node, decltype(f)> s2;
这个该怎么改呢?谢谢。
作者:
bruceteen
时间:
2018-07-30 08:49
#include <unordered_set>
using namespace std;
struct node
{
size_t value;
};
int main( void )
{
auto f = [](const node& n) {
return (size_t)n.value;
};
auto g = [](const node& a,const node& b) {
return a.value==b.value;
};
std::unordered_set<node,decltype(f),decltype(g)> s2( 100, f, g );
node a = { 0 };
s2.insert(a);
}
复制代码
欢迎光临 Chinaunix (http://bbs.chinaunix.net/)
Powered by Discuz! X3.2