草庐IT

info-hash

全部标签

c++ - boost::exception_detail::clone_impl<boost::exception_detail::error_info_injector<boost::thread_resource_error>>

我需要一些帮助来解决这个异常,我正在实现一个NPAPI插件,以便能够使用来自浏览器扩展的本地套接字,为此我正在使用Firebreath框架。对于套接字和连接,我使用带有异步调用的Boostasio和一个包含5个工作线程的线程池。我还为每个线程设置了截止日期以实现传输超时。我使用插件的扩展工作流程是这样的:打开套接字1(这会启动async_receive和截止时间异步等待)写入套接字1获取响应1打开另一个socket2在套接字2中写入写套接字1关闭套接字1(socket.cancel(),deadline.cancel(),socket.shutdown(),socket发布)。获取响应

c++ - 如何 std::hash 一个无序的 std::pair

我希望能够使用std::pair作为unordered_container中的键。我知道我可以通过以下方式做到这一点:templatevoidhash_combine(std::size_t&seed,Tconst&key){std::hashhasher;seed^=hasher(key)+0x9e3779b9+(seed>2);}namespacestd{templatestructhash>{std::size_toperator()(std::pairconst&p)const{std::size_tseed(0);::hash_combine(seed,p.first);::

c++ - typeid/type_info 奇怪的行为

为什么下面的例子:#include#includetemplatevoidfun(constT¶m){std::cout给出以下输出:Tisiparamisi1我知道type_info::name()行为依赖于实现。无论如何,我希望operator==返回false(因为param是一个const引用,而不是一个整数)。 最佳答案 这是在标准中定义的:5.2.8/5:Ifthetypeoftheexpressionortype-idisacv-qualifiedtype,theresultofthetypeidexpress

C++11 unordered_set with std::owner_less-like hashing

我正在使用外部网络库,它返回一些表示打开的套接字的神奇结构,文档说当将它们插入STL容器时,应该使用std::owner_less比较它们。std::map,std::owner_less>sockets;但是我想改用unordered_map。我该怎么做?std::owner_less是一个比较器,它对HashMap毫无用处。挖掘源代码,MagicStructure似乎是std::shared_ptr的类型定义。 最佳答案 不幸的是,您似乎必须使用map,而对于这种情况不能使用unordered_map:http://wg21.c

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++ - 为什么 type_info::name() 未指定?

我完全知道std::type_info::name()的返回值是实现定义的。来自C++标准(ISO/IEC14882:2003§18.5.1.7):Returns:animplementation-definedNTBS.我的问题是:为什么?如果标准规定了返回值应该是什么,这个成员函数不是更有用吗? 最佳答案 基本上,如果一个实现决定他们不能或不想支持RTTI,他们可以return"";。如果标准强制它返回某些东西,他们可能会扼杀任何为RTTI资源不存在或想要禁用的环境(例如微芯片)提供兼容编译器的能力。别忘了我们不想在任何编译器上

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