草庐IT

hash_value

全部标签

c++ - "warning C4800: ' int' : forcing value to bool 'true' or 'false' "不同场景下的不同行为

我无法理解此警告的以下行为。case1:boolread=(33&3);//NoWarningissuedbyvs2013case2:intb=33;boolread=(b&3);//NowcompilerisgeneratingC4800warning.为什么编译器在情况2中生成警告,而在情况1中不发出任何警告。 最佳答案 C4800是一个性能警告-在运行时将整数强制转换为bool会产生成本。这与逻辑正确性无关。最常见的强制转换(和警告)发生在您与使用整数(VC++中的BOOL)作为bool值的代码交互时。第一个代码段中的编译时强

c++ - C++初始化中的 "several values"是什么?

这是一道关于C++Primer(5thedition)Chapter3.2,Page84,85的问题。Whenwehaveasingleinitializer,wecanuseeitherthedirectorcopyformofinitialization.Whenweinitializeavariablefrommorethanonevalue,suchasintheinitializationofs4,wemustusethedirectformofinitialization:strings4(10,'c');//s4is"cccccccccc"strings5="hiya";

c++ - g++ 链接器错误:获取 std::hash 的 undefined reference 错误

我在我的代码中使用了TR1实现的unordered_map,链接器给出了我什至无法破译的奇怪错误:BPCFG.o:Infunction`std::__detail::_Hash_code_base,std::_Select1st>,eqDottedRule,std::hash,std::__detail::_Mod_range_hashing,std::__detail::_Default_ranged_hash,false>::_M_hash_code(DottedRuleconst&)const':BPCFG.cpp:(.text._ZNKSt8__detail15_Hash_co

c++ - QtableWidget : How to find value in specific column

我需要使用qtablewidget检查特定值是否在特定列中。在我的例子中,我需要检查第一列ID是否已经存在,如果是,我需要包含行的编号来更新该行,否则我想添加该行。QT有没有提供查列或者shou的解决方案 最佳答案 我假设您正在寻找第一列中的值(这就是为什么item(int,int)中的第二个参数为0)并且表名是myQTableWidgetintrows=myQTableWidget->rowCount();boolfound=false;for(inti=0;iitem(i,0)->text()=="Something"){//w

c++ - 如何编写模板将 vector 转换为 Json::Value (jsoncpp)

我写了一个模板(如下所示)但是编译失败templateclassiterable>Json::Valueiterable2json(constiterable&cont){Json::Valuev;for(constt&elt:cont){v.append(elt);}returnv;}std::vectorvec{1,2,3};Json::Valuev=iterable2json(vec)错误C3312:找不到类型“conststd::_Vector_val”的可调用“开始”函数与[_Val_types=std::_Simple_types]参见正在编译的函数模板实例化'Json::

c++ - 如何在 C++ 中为不同的迭代器 value_types 重载函数

我想在C++11中实现一个带有一对迭代器的模板函数。如果传递了一对迭代器,其值类型是任意类型的std::pair,则实现应该做一些特殊处理。我试图提出以下定义://arbitraryvaluetypestemplatevoidprocess(Iterbegin,Iterend){for(Iteriter=begin;iter!=end;++iter){std::cout::value_type,std::pair>::value>::type*=0>voidprocess(Iterbegin,Iterend){for(Iteriter=begin;iter!=end;++iter){s

c++ - <hash_set> 相等运算符在 VS2010 中不起作用

示例代码:std::hash_seths1;//alsoitrystd::unordered_set-sameeffectstd::hash_seths2;hs1.insert(15);hs1.insert(20);hs2.insert(20);hs2.insert(15);assert(hs1==hs2);hash_set不按照散列函数定义的某种顺序存储元素...为什么?请注意,此代码使用stdext::hash_set在VS2008中工作。 最佳答案 在VisualC++2010中,hash_set和unordered_set的

c++ - 从 json-spirit 获取值(value)

我正在使用Json-Spirit库,但是我不确定如何在不遍历每个名​​称-值对的情况下从对象中读取值。如果我有一个这样的对象:{"boids":{"width":10,"count":5,"maxSpeedMin":2,"maxSpeedMax":80,"maxForceMin":0.5,"maxForceMax":40}}例如,如何通过名称访问width值? 最佳答案 json_spirit添加了对std::map的支持,以便您可以查找值。json_spirit下载中的项目之一是json_map_demo。这将帮助您更好地理解它。

c++ - 为什么我机器上的 hash_map 和 unordered_map 非常慢?

我用这段代码测试了它们(在VisualStudio2010sp1上):#include#include#include#include#includeintmain(){clock_ttime;intLOOP=(1my_map;std::unordered_mapmap_unordered_map;std::hash_mapmy_hash_map;time=clock();for(inti=0;i!=LOOP;++i){my_map[i]=i;}std::cout结果很奇怪:在调试中:map:0.289无序map:10.738HashMap:10.58按任意键继续。..在发布中:map

c++ - 了解 C++ 内存模型 : Different values on different runs

下面的代码有什么问题?我希望看到10由consumer1和consumer2生产,但有时我会看到-1。#include#include#include#includestd::atomicglobal;voidproducer(){global.store(10,std::memory_order_release);}voidconsumer1(){inta=global.load(std::memory_order_acquire);printf("ainconsumer1%d\n",a);}voidconsumer2(){inta=global.load(std::memory_o