草庐IT

cluster_map

全部标签

c++ - 插入 unordered_map 时没有匹配函数

我声明一个unordered_map如下:boost::unordered_map,t_torrent>torrent_ins;然后向其中插入一个元素(如果键不存在,该映射将返回新元素的引用)t_torrent&torrent_in=torrent_ins[to_array(in)];但是我收到一条错误信息:../src/Tracker/torrent_serialization.cpp:30:instantiatedfromhere/usr/local/include/boost/functional/hash/extensions.hpp:176:error:nomatchingf

c++ - 为什么在使用 std::map::insert() 时编译顺序有时会导致段错误?

我有一个类叫做Controller,在其中,我有一个名为Button的类.Controller包含几个Button不同类型的实例(例如button_type_a、button_type_b)。controller.h#ifndef__controller__#define__controller__classController{public:classButton{public:Button(inttype=-1);private:inttype;};Controller();ButtonA;ButtonB;ButtonX;ButtonY;};#endif按钮类型为ints,我希望能

c++ - STL 允许使用指向不同 map 的迭代器删除 map 的键/值吗?

所以,我偶然发现的是:std::mapmap1;std::mapmap2;map1[2.5]=11;map1[3.5]=12;map2[2.5]=21;map2[3.5]=22;std::map::iteratoriterMap1=map1.find(2.5);//Iwillnowtrytoeraseakey/valuepairinmap2withaniterator//thatpointstomap1.Thisisbad/wrong.ButIamsurprised//thisisallowed.map2.erase(iterMap1);//whatdoyouthinkwouldbep

c++ - 通过 operator[] 访问静态成员 unordered_map

作为C++的新手,我遇到了一些我不太理解的行为,并且即使通过大量谷歌搜索也无法找到解释,所以我希望有人能解释这里到底出了什么问题。//test.h#includetypedefstd::unordered_maptest_type;classtest{public:staticconsttest_typetmap;};//test.cpp#include"test.h"consttest_typetest::tmap={{1,1}};//main.cpp#include"test.h"intmain(){//Attempt1:accesskeyviaoperator[]std::cou

C++ : double iteration through map

我想遍历一个map,但内部循环只会遍历元素的上半部分。使用vector它看起来像这样:for(autoelement1=myVector.begin();element1!=myVector.end();++element1){for(autoelement2=element1+1;element2!=myVector.end();++element2){//mystuff}}但是对于mapelement1+1返回错误nooperatormatchesthisoperand..我相信这是因为元素在map中没有排序.那么我怎样才能正确地做到这一点呢?我目前正在使用这种需要在每个循环中进行

c++ - 使用两个对象作为 unordered_map 或替代方案的哈希键

定义对象myType后,我需要存储这些对象之间的关系。这些关系存储在矩阵中。事先不知道元素的数量,并非所有元素都有关系(element1可以与element3有关系,但可能与5没有关系)并且内存是一个问题。例如它可能看起来像:element45与:具有特征[3,1;1,4]的元素3具有特征[1,1;1,1]的元素12具有特征[8,1;1,4]的元素1780element1661连接到:具有特征[3,1;6,4]的元素3具有特征[1,1;1,9]的元素1具有特征[8,1;1,1]的元素1780拥有:myType*element1;myType*element2;我想要类似的东西(正确指出

c++ - operator[] for std::map 什么情况下可以返回0?

我正在使用LLVM,但我遇到了以下我没有编写的代码段的问题:staticstd::mapNamedValues;...//LotsofothercodeValue*V=NamedValues["Demostring"];returnV?V:ErrorV("VisnotinNamedValuesmap.");根据我对std::map的理解,它永远不应该返回空指针(除非它内存不足?),所以我很难理解V为0如何表示V不在映射中。照原样,我的程序总是在这里出错,但我不明白为什么。对这里发生的事情有什么帮助吗? 最佳答案 std::map::

c++ - 直接放置在 pair 的 std::map 中

为什么这段代码无法编译?std::map>m;m.emplace(1,1,1);假设我们可以编辑std::map::emplace的代码,是否可以更改它以使之前的代码有效? 最佳答案 无效的原因与无效的原因完全相同:std::pair>p{1,1,1};因为上面本质上就是map的emplace归结为。要使其正常工作,您可以使用piecewise_constructconstructorofstd::pair,正是为了这个目的而引入的:m.emplace(std::piecewise_construct,std::forward_as

c++ - 检测类型是否为 "mapping"

我想使用它们的::iterator成员类型将C++容器解析为另一个对象。迭代器成员类型指向单一类型(vector、队列等)的对象的容器将变成类列表对象,迭代器成员类型的容器指向一个std::pair将变成一个类似map的对象。我正在尝试编写一个成员函数来检测后一种容器,但它不起作用。这是我到目前为止所拥有的:#include#include#includetemplatestructis_pair:std::false_type{};templatestructis_pair>:std::true_type{};templateconstexprboolis_pair_v=is_pai

c++ - vector 和 map 抛出异常

我的任务是输出所有十位数字,其中数字不重复。我首先使用的是这样的东西:#include#include#include#include#includeusingnamespacestd;voidTask5(){autoinitialization=[](map*m,intcount){for(inti=0;i*m,intcount,intvalue){for(inti=9;i>count;--i)m[count][i][value]=false;};/*Forcreatecopymap*/automould=[](map*m,map*m_copy,intcount)->map*{if(