草庐IT

hash_params

全部标签

c++ - 为什么 boost::call_traits<T>::param_type 是枚举类型的引用?

基本的C++03枚举类型只是一个具有奇特名称的整数值,因此我希望按值传递它....出于这个原因,我还期望boost::call_traits::param_type与T=SomeEnum确定最有效的传球方式T是按值(value)。从boost文档中查看CallTraits:Definesatypethatrepresentsthe"best"waytopassaparameteroftypeTtoafunction.当我使用boost::call_traits::param_type时与T=SomeEnum它确定SomeEnum应该通过引用传递。我也期待C++11classenums也

c++ - 如何创建具有 64 位输出的良好 hash_combine(受 boost::hash_combine 启发)

目前Boost有hash_combine函数输出32位无符号整数(准确的说是size_t)。一些引用:http://www.boost.org/doc/libs/1_43_0/doc/html/hash/reference.html#boost.hash_combinehttp://www.boost.org/doc/libs/1_43_0/doc/html/hash/combine.htmlMagicnumberinboost::hash_combine我想探索如何创建64位版本的hash_combine。第一件事是在64位中获得黄金比例或任何其他无理数。第二部分是使用轮类。这部分相

c++ - std::hash 特化使用 sfinae?

作为练习,我试图看看我是否可以使用SFINAE为std::pair和std::创建一个std::hash特化:tuple当它的所有模板参数都是无符号类型时。我对它们有一点经验,但据我了解,散列函数需要已经使用typenameEnabled=void进行模板化,以便我添加特化。我不太确定从这里去哪里。这是一个不起作用的尝试。#include#include#include#includenamespacestd{templatestructhash,std::enable_if_t::value>>{size_toperator()(conststd::pair&x)const{retu

c++ - std::hash 模板偏特化

我用模板写了一些类:template>classmy_list;我应该为这个类编写::std::hash特化。我怎样才能做到这一点?简单的偏特化:namespacestd{templateclasshash>{public:size_toperator()(constmy_list&x)const{return...;}};}但是我不能写简单的偏特化,因为它被C++ISO禁止:ISO/IEC14882Thirdedition2011-09-0117.6.4.2.1Namespacestd[namespace.std]2ThebehaviorofaC++programisundefine

c++ - 为什么 std::hash 不专用于 std::reference_wrapper?

我以为会是这样,但我在我的标准库实现(gcc-4.8.2)中找不到它。为什么std::hash还没有专门用于std::reference_wrapper?#pragmaonce#includenamespacestd{templatestructhash>{size_toperator()(constreference_wrapper&r)const{returnstd::hash()(r.get());}};} 最佳答案 std::reference_wrapper主要用于在默认复制值的实用程序中提供引用语义,例如std::bin

c++ - std::type_info::hash_code() 的唯一性和 "should"的含义

是否意味着要保证相同的std::type_info::hash_code()值表示相同的类型?Cplusplus.com似乎是这么说的:Thisfunctionreturnsthesamevalueforanytwotype_infoobjectsthatcompareequal,anddifferentvaluesfordistincttypesthatdonot.[Emphasismine]Cppreference似乎另有说法:Returnsanunspecifiedvalue,whichisidenticalforobjects,referringtothesametype.No

c++ - 如何修复 "<hash_map> is deprecated and will be REMOVED. Please use <unordered_map>"?

我正在学习C++,所以我正在阅读Programming:PrinciplesandPracticeusingC++这本书。我正在进行第一个练习,即如何制作“Hello,World!”。使用MicrosoftVisualStudio2015编写的程序。我使用了书中提供的源代码。#include"../../std_lib_facilities.h"//headerfilerecommendedbybookintmain()//C++programsstartbyexecutingthefunctionmain{cout但是,当我尝试构建一个可执行程序时收到两个错误,如下所示:Intell

c++ - 为什么 std::hash<T> 不专用于 char*?

为什么C++标准不指定std::hash专门用于char*,constchar*,unsignedchar*,constunsignedchar*,ETC?即,它将散列C字符串的内容,直到找到终止null。将我自己的特化注入(inject)std的任何危害我自己的代码的命名空间? 最佳答案 Whydoesn'ttheC++standardspecifythatstd::hashisspecializedforchar*,constchar*,unsignedchar*,constunsignedchar*,etc?看起来它起源于pr

c++ - std::hash 是否保证在 stdlib 发行版中相同

如果我使用libstdc++做了std::hash然后在即将到来的C++11VS2012库上做了一个-他们会匹配吗?我假设哈希实现不是C++规范的一部分,并且会因分布而异? 最佳答案 标准只说明了这一点:20.8.12ClasstemplatehashTheunorderedassociativecontainersdefinedin23.5usespecializationsoftheclasstemplatehashasthedefaulthashfunction.ForallobjecttypesKeyforwhichther

c++ - 用户类型的 hash<T> 仿函数属于哪个命名空间?

我不清楚C++11标准中用户定义的hash应定义仿函数。例如,在23.5.2Header,它显示:template,classPred=std::equal_to,classAlloc=std::allocator>>classunordered_map;这表明,默认情况下,hash在全局命名空间中搜索,而equal_to在std中搜索命名空间。为什么hash之间的命名空间不同?和equal_to?(实际上,在http://www.cplusplus.com/reference/unordered_map/unordered_map/的描述中,都没有指定std命名空间。)因此,在定义h