草庐IT

mapped_type

全部标签

c++ - 带公历日期的 unordered_map

我想将boost::gregorian::date存储为boost::unordered_map的键,但我无法编译代码,因为它缺少适当的哈希这个类的函数。一个简单的解决方案是转换为std::string并存储它。我可能想避免使用此解决方案,因为使用字符串非常昂贵。我试图找到一些将日期导出为数字的函数,但我只能读取day()函数,我不确定这是否真的合适。也许我可以计算出我的日期和引用日期之间的天数?有没有其他更好的方法来存储日期或将日期导出为数字的函数? 最佳答案 为其实现哈希函数:namespaceboost{namespacegr

C++1y/C++14 : Converting static constexpr array to non-type template parameter pack?

假设我有一个静态存储持续时间的constexpr数组(已知范围):constexprTinput[]=/*...*/;我有一个需要打包的输出类模板:templatestructoutput_template;我想像这样实例化output_template:usingoutput=output_template;一种方法是:templatestructmake_output_template{templatestaticconstexproutput_templatef(std::index_sequence){return{};};usingtype=decltype(f(std::m

c++ - 错误 : invalid operands of types 'int' and '<unresolved overloaded function type>' to binary 'operator<<'

我想获取z_Data的第48个字符的第6位{charc=pPkt->z_Data[47];//thisz_Dataisacharbufferstd::cout>3)&1>4)&1>5)&1 最佳答案 优先级高于&,所以你需要:std::cout>3)&1)>4)&1)>5)&1) 关于c++-错误:invalidoperandsoftypes'int'and''tobinary'operator https://stackoverflow.com/questions/246

c++ - QMetaType::Float 不在 QVariant::Type 中

我有一个运行良好的应用程序,但它不是在打开警告的情况下编译的。我正在尝试将其重新打开并整理它们,但没有关于如何解决此问题的想法。我有:QVariantsomeVarQVariant::TypevariantType=someVar.type();switch(variantType){caseQMetaType::QString:doSomething1();break;caseQMetaType::Float:doSomething2();break;}并收到此警告/错误:error:casevalue‘135’notinenumeratedtype‘QVariant::Type’[

c++ - 这是正确的行为吗? std::map 迭代器失效

#include#includeintmain(intargc,char**argv){std::mapmap;map.emplace(1,1);autoreverse_iter=map.rbegin();std::coutfirstsecondfirstsecond打印出来:1,12,2根据标准,这真的应该发生吗?我没有接触reverse_iter但它指向的值正在改变。我认为std::map中的迭代器应该可以安全地防止插入。然而,它似乎决定reverse_iter不再指向我告诉它的值,而是指向“此时map末尾发生的任何事情”。更新:更多信息,以防万一:前向迭代器似乎不会发生这种情况(

c++ - 为什么 vector::operator[] 的实现方式与 map::operator[] 不同?

std::vector的operator[]是否有任何理由只返回一个引用而不是插入一个新元素?vector::operator的cppreference.com页面显示hereUnlikestd::map::operator[],thisoperatorneverinsertsanewelementintothecontainer.map::operator[]的页面says"Returnsareferencetothevaluethatismappedtoakeyequivalenttokey,performinganinsertionifsuchkeydoesnotalreadye

c++ - std::map 的用途是什么?

谁能解释一下我从这个使用std::map的简单程序中得到的输出。请注意,我将p插入到map中,但没有插入q但它说它找到了它们,而且还说map中只有1个元素!#include#includestructscreenPoint{floatx=0,y=0;screenPoint(floatx_,floaty_):x{x_},y{y_}{}};booloperatorpositions;intmain(intargc,constchar*argv[]){autop=screenPoint(1,2);autoq=screenPoint(2,1);positions.emplace(p,3);au

c++ - 当键可能不存在时,如何返回对对象的引用(来自 unordered_map)?

假设我有一个对象:classObject{public:Object(std::vectorstuff){}}这些对象中的每一个都只能从类Foo访问:classFoo{public:std::unordered_map_objects;boolgetObjectForId(constint&objectId,Object&rep){boolfound=false;std::unordered_map::const_iteratorgot=_objects.find(objectId);if(got!=_objects.end()){found=true;rep=_objects[obj

C++ : union of two types without virtual base class inheritance

是否可以在不手动创建交集类型的情况下创建两种类型的并集?问题是在我的上下文中交集类是完全没有意义的,所以创建它会使代码用户感到困惑。我的实际案例:我正在描述一个数字硬件模拟器,它是许多模块的分层树状结构:classport;classmodule0{porta,b,c;}classmodule1{portc,d,e;}我需要创建这两种类型的union:classtop_level_module{porta,b,c,d,e;}我想应该有一些技术来创建union类型(这是我要问的问题):classtop_level_module:union_type{//porta,b,c,d,e;}但是

c++ - 是否允许在 requires 表达式中为 return-type-requirement 指定类型?

看看这个简单的概念示例:templaterequiresrequires(Tt){{t+t}->bool;}voidfn(){}intmain(){fn();}这里,我使用bool作为return-type-requirement的type-constraint。当前稿says:type-constraint:nested-name-specifieroptconcept-namenested-name-specifieroptconcept-name所以type-constraint必须是一个concept-name。bool(或任何类型)是否允许作为概念名称?如果是,那是什么意思,