草庐IT

unordered_container

全部标签

c++ - BOOST_FOREACH : What is the error on using this of a STL container?

有谁知道为什么以下会在VC9上产生错误?classElem;classElemVec:publicvector{public:voidfoo();};voidElemVec::foo(){BOOST_FOREACH(Elem&elem,*this){//Dosomethingwithelem}return;}我得到的错误是:errorC2355:'this':canonlybereferencedinsidenon-staticmemberfunctions我现在拥有的唯一(hack)解决方案是:voidElemVec::foo(){ElemVec*This=this;BOOST_FO

c++ - QMap::contains() 未返回预期值

我有一个包含QMap对象的类:QMapusers;现在,在下面的函数Foo()中,if子句总是返回false,但是当我遍历映射时,比较的QString,即str1出现在键中。voidFoo(QString&str1,QString&str2){if(users.contains(str1))users[str1]->doStuff(str2);else{for(QMap::iteratoriter=users.begin();iter!=users.end();iter++)qDebug()我做错了什么吗?为什么contains()不返回true? 最佳答案

c++ - boost::unordered_map 中的迭代器失效

我正在使用boost::unordered_map如下typedefboost::shared_ptrPtrWriter;typedefstd::listPtrList;boost::unordered_map,PtrList>MapMapinstrMap;现在我正在循环中对PtrList类型的列表进行一些更改for(autoit=instrMap.begin();it!=instrMap.end();++it){autokey=it->first();autolist&=it->second();//Makesomechangetoanelementinlistif(list.emp

c++ - std::containers 的日志分配器?

X:我需要知道程序的每个部分使用了多少内存。我的程序经常使用C++std库。特别是,我想知道每个对象使用了多少内存。我是怎么做的:要记录some_vector的消耗,只需写my::vectorsome_vector;在哪里namespacemy{templateusingvector=std::vector>;}登录分配器实现如下:templatestructLoggingAllocator{//...boilerplate...pointerallocate(size_typen,std::allocator::const_pointerhint=0){log_allocation(

c++ - 键不存在时 unordered_multimap::bucket() 的返回值?

当key不存在时,unordered_multimap::bucket(key)是什么应该回来吗?引用资料说它应该返回包含键的桶的桶号,但没有说明当unordered_multimap中不存在该键时会发生什么。Itrieditmyself但我得到的结果不正确:std::unordered_multimapm={{"jack","foo"},{"jill","bar"}};std::cout输出是:jackisinbucket3jillisinbucket4bjarneisinbucket4这是否意味着我必须使用unordered_multimap::count(key)==0来捕获不存

c++ - 当 wordCount 中不存在键时,我应该对 unordered_map<string, int> 使用++wordCount[key] 吗?

见下面的代码:unordered_mapwordCount;for(stringword:words)++wordCount[word];问题:当wordCount中不存在word时,是否可以使用++wordCount[word];?我总是看到有人这样使用,但我不太确定。说明here说:Ifkdoesnotmatchthekeyofanyelementinthecontainer,thefunctioninsertsanewelementwiththatkeyandreturnsareferencetoitsmappedvalue.Noticethatthisalwaysincreas

c++ - 在 std::unordered_map 中使用模板化键

我不明白为什么我的编译器不接受下面的代码#include#includetemplateusingM=std::unordered_set;templateusingD=M;templateusingDM=std::unordered_map::const_iterator//Problem,typenameD::const_iterator>;//Problemintmain(intargc,char**argv){Dd;Mm;DMdm;//Problem}编译命令是clang++-std=c++14test.cpp-otest编译器错误消息摘录是/usr/bin/../lib/gc

c++ - 奇怪的迭代器行为 + unordered_set 的段错误

我有一个类有一个unordered_set成员如下:我有以下类定义,后面是它的常规构造函数和复制构造函数,以及一些其他修改集合的函数(删除了不相关的代码段,因为类很长):#include#include#includeclassHexBoard{public:HexBoard(intn);HexBoard(constHexBoard&obj);std::unordered_setemptyPositions();private:std::unordered_setempty_positions;};HexBoard::HexBoard(intn){for(inti=0;i=nempty

c++ - boost::container::allocator_traits::is_partially_propagable 是什么意思?

我很想理解boost::container::allocator_traits当我遇到boost::container::allocator_traits::is_partially_propagable时。我在网上找不到任何其他关于它的文档,我可以理解boost::container::allocator_traits除了is_partially_propagable和storage_is_unpropagable之外的所有其他成员。编辑:以及,它们是如何实现的以及在编写容器时如何使用它们? 最佳答案 它(is_partially

c++ - boost::unordered_map -- 需要指定自定义哈希函数来散列 std::set<int> 吗?

我想使用boost::unordered_map,其中key是std::set.由于一组整数不是内置类型,我假设我必须提供我自己的散列函数(或者,更确切地说,我正在考虑使用boost'shash_range)。但是,现在我尝试像这样初始化散列映射,既不提供散列函数也不提供相等谓词——而且gcc没有提示。这里发生了什么?boost是否足够聪明,可以自行散列所有STL容器?这会比我使用自定义哈希函数慢吗?使用boost::hash_range怎么样??提前致谢。 最佳答案 根据theBoostdocumentation:thedefau