在cppreference上环顾四周,我发现std::unordered_mapgetsefficientlookup来自“等效键”的函数。我认为这意味着等效键必须具有相同的哈希值。如何为字符串文字提供与std::hash相同的哈希值无需临时构建std::string从而使关于等效键的全部观点一文不值? 最佳答案 这是cppreference中的错误;对于无序的关联容器没有模板化查找。比较,来自n3690,来自§23.5.4.1[unord.map.overview]//lookupiteratorfind(constkey_typ
在cppreference上环顾四周,我发现std::unordered_mapgetsefficientlookup来自“等效键”的函数。我认为这意味着等效键必须具有相同的哈希值。如何为字符串文字提供与std::hash相同的哈希值无需临时构建std::string从而使关于等效键的全部观点一文不值? 最佳答案 这是cppreference中的错误;对于无序的关联容器没有模板化查找。比较,来自n3690,来自§23.5.4.1[unord.map.overview]//lookupiteratorfind(constkey_typ
据我所知,我所做的一切都是正确的,并且我收到了错误消息:error:'unordered_map'doesnotnameatypeerror:'mymap'doesnotnameatype在我的代码中,我有:#includeusingnamespacestd;//globalvariableunordered_mapmymap;mymap.reserve(7000);voidmain{return;}我看不出这里可能缺少什么......编辑:当我将声明更新为std::tr1::unordered_mapmymap;我能够消除第一个错误,但是当我尝试保留时,我仍然收到第二个错误消息。ED
据我所知,我所做的一切都是正确的,并且我收到了错误消息:error:'unordered_map'doesnotnameatypeerror:'mymap'doesnotnameatype在我的代码中,我有:#includeusingnamespacestd;//globalvariableunordered_mapmymap;mymap.reserve(7000);voidmain{return;}我看不出这里可能缺少什么......编辑:当我将声明更新为std::tr1::unordered_mapmymap;我能够消除第一个错误,但是当我尝试保留时,我仍然收到第二个错误消息。ED
我对“unordered_map”这个名字感到很困惑。顾名思义,键根本没有排序。但我一直认为它们是按哈希值排序的。还是说错了(因为名字暗示它们不是有序的)?或者换个说法:这是这个typedefmap>HashMap;与templatestructHashComp{booloperator()(v1)()(v2);}};同typedefunordered_mapHashMap;?(好吧,不完全是,STL会在这里提示,因为可能有键k1,k2并且既不是k1multimap并覆盖相等检查。)或者再次不同:当我遍历它们时,我可以假设键列表是按它们的哈希值排序的吗? 最
我对“unordered_map”这个名字感到很困惑。顾名思义,键根本没有排序。但我一直认为它们是按哈希值排序的。还是说错了(因为名字暗示它们不是有序的)?或者换个说法:这是这个typedefmap>HashMap;与templatestructHashComp{booloperator()(v1)()(v2);}};同typedefunordered_mapHashMap;?(好吧,不完全是,STL会在这里提示,因为可能有键k1,k2并且既不是k1multimap并覆盖相等检查。)或者再次不同:当我遍历它们时,我可以假设键列表是按它们的哈希值排序的吗? 最
根据this你不能为std::map:保留空间No,themembersofthemapareinternallystoredinatreestructure.Thereisnowaytobuildthetreeuntilyouknowthekeysandvaluesthataretobestored.从这里很明显为什么std::map会缺少reserve()方法,它在cppreference.com上就是这样做的。但是,std::unordered_mapdoes有一个reserve()方法,但是当我尝试将它与operator[]、insert()或emplace()尽管我先调用了r
根据this你不能为std::map:保留空间No,themembersofthemapareinternallystoredinatreestructure.Thereisnowaytobuildthetreeuntilyouknowthekeysandvaluesthataretobestored.从这里很明显为什么std::map会缺少reserve()方法,它在cppreference.com上就是这样做的。但是,std::unordered_mapdoes有一个reserve()方法,但是当我尝试将它与operator[]、insert()或emplace()尽管我先调用了r
我想拥有类似的东西unordered_set>>us;但即使没有配对:#include#includeusingnamespacestd;intmain(){unordered_set>um;}失败了:Infileincludedfrom/usr/include/c++/4.8/bits/hashtable.h:35:0,from/usr/include/c++/4.8/unordered_set:47,fromprog.cpp:2:/usr/include/c++/4.8/bits/hashtable_policy.h:Ininstantiationof‘structstd::__d
我想拥有类似的东西unordered_set>>us;但即使没有配对:#include#includeusingnamespacestd;intmain(){unordered_set>um;}失败了:Infileincludedfrom/usr/include/c++/4.8/bits/hashtable.h:35:0,from/usr/include/c++/4.8/unordered_set:47,fromprog.cpp:2:/usr/include/c++/4.8/bits/hashtable_policy.h:Ininstantiationof‘structstd::__d