草庐IT

map_region

全部标签

c++ - 使用以位集为键的 map 时出现问题

我正在尝试使用bitset作为键在C++中创建一个map。但是编译器会生成以下错误消息Infileincludedfrom/usr/include/c++/4.6/string:50:0,from/usr/include/c++/4.6/bits/locale_classes.h:42,from/usr/include/c++/4.6/bits/ios_base.h:43,from/usr/include/c++/4.6/ios:43,from/usr/include/c++/4.6/ostream:40,from/usr/include/c++/4.6/iostream:40,fro

c++ - 是否有 auto_ptr 的替代品可以与 c++11 中的 boost ptr_map 一起使用

在c++11中,auto_ptr已弃用,取而代之的是更合理的unique_ptr。唉,如果你使用boost::ptr_map,auto_ptr就完成了一个非常方便的用途:std::auto_ptrpLayer(newLayer());mRawLayerPtrMap.insert(layerName,pLayer);是否有可能使用与c++11类似的东西。这个我知道Layer*pLayer=newLayer();mFusedLayers.insert(fusedLayerName,pLayer);有效,但auto_ptr在一些更复杂的场景中有它的优点。是否有适用于C++11的替代品?

c++ - std::size 和 std::map 的最大大小?

std::size和std::map的最大大小是多少?有没有办法增加这个数字?谢谢! 最佳答案 您可以通过调用Container::max_size()获得每个标准库容器的最大大小在上面。如果在编译时需要理论最大大小值,请使用std::numeric_limits::max(). 关于c++-std::size和std::map的最大大小?,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.com/questi

c++ - std::map::clear 和元素的析构函数

析构函数是否在std::map上被调用?std::map::clear时的元素用来?我尝试调试std::map但看不到std::string析构函数被调用。任何人都可以帮助我理解吗?文档说明它被调用了,但我没有注意到它。 最佳答案 文档是正确的,它确实被调用了。销毁将通过方法std::allocator::deallocate()完成。.在调试器中跟踪它。http://www.cplusplus.com/reference/std/memory/allocator/ 关于c++-std:

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;我想要类似的东西(正确指出