草庐IT

unordered_multimap

全部标签

c++ - 使用 STL map/set/multiset/multimap,如何找到大于或等于搜索键的第一个值?

假设我有一组值,存储在std::set中:{1,2,6,8}我有一个搜索键,比如3。我想将3放入函数中并获取大于或等于3的第一个值,在本例中我想要获取6。map/set/multimap/andset中提供的find()函数当然会返回这种情况的结束迭代器。在这种情况下是否有类似的find函数会返回6? 最佳答案 是的:upper_bound(X)返回一个指向第一个大于X的元素的迭代器。还有一个lower_bound(X)函数,它返回一个指向第一个不小于X的元素的迭代器。因此,半开区间[lower_bound(X),upper_bou

c++ - lambda 签名 for_each + unordered_map

#include#include#include#include#includeintmain(){std::unordered_maphash{{"a",1},{"b",2},{"c",3}};//CaseA(NO-ERROR)std::for_each(hash.begin(),hash.end(),[](conststd::pair&p){std::cout"p){std::cout"p){std::cout"&p){std::cout"Q1>为什么CaseD是错误的?Q2>CaseA真的是推荐的方式吗?谢谢 最佳答案 val

c++ - std::unordered_map 使用 Visual C++ 2008 的未声明标识符

#include#include#includeusingnamespacestd;intmain(){unordered_mapm;m[1]="one";m[2]="two";m[4]="four";m[3]="three";m[2]="TWO!";cout正在学习,想不通。编译器抛出类型unordered_map未声明的错误。我使用的是VisualC++2008ExpressEdition。 最佳答案 在VisualStudio2008中,技术报告1(TR1)中的类位于命名空间std::tr1中。添加:usingnamespac

c++ - 我不明白 std::tr1::unordered_map

我需要一个关联容器,它可以让我通过字符串索引某个对象,但它也保持插入顺序,这样我就可以通过名称查找特定对象,或者只是迭代它并在同一个对象中检索对象我插入它们的顺序。我觉得这个hybridoflinkedlistandhashmap应该完成这项工作,但在我尝试使用std::tr1::unordered_map之前认为它以我描述的方式工作,但事实并非如此。那么有人可以向我解释unordered_map的含义和行为吗?@wesc:我确定std::map是由STL实现的,同时我确定std::hash_map不在STL中(我认为旧版本的VisualStudio将它放在名为stdext的命名空间中

c++ - 自引用使用 unordered_map 会导致 gcc 5.3 出现问题但不会导致 clang

以下代码无法在gcc5.3下编译(它是从较大代码段中提取的缩减版本):#include#includeclassFoo{std::unordered_mapm;//"self-referential"};intmain(){Foof;return0;}有以下错误:g++--std=c++1y-crh.cppInfileincludedfrom/usr/local/include/c++/5.3.0/utility:70:0,from/usr/local/include/c++/5.3.0/unordered_map:38,fromrh.cpp:1:/usr/local/include/

c++ - 如何使用 Boost 的 vf2_subgraph_iso 检测 multimap 上的子图同构?

我正在尝试使用Boost的vf2_subgraph_iso()检测子图同构。我可以在简单的图表上成功做到这一点,但不能在multigraph上做到这一点(允许有多个边的图)。考虑检测以下G1和G2之间的子图同构:G1是G2的子图,我想使用以下代码检测它:#include#include#includeintmain(){//Defineedgepropertytypedefboost::propertyedge_property;//Definegraphtypetypedefboost::adjacency_listMyGraphType;//BuildgraphG1MyGraphT

c++ - std::unordered_map::find 使用与 Key 类型不同的类型?

我有一个unordered_map使用字符串类型作为键:std::unordered_mapmap;Astd::hash为string提供特化,以及ASA适合operator==.现在我还有一个“字符串View”类,它是指向现有字符串的弱指针,避免了堆分配:classstring_view{string*data;size_tbegin,len;//...};现在我希望能够使用string_view检查map中是否存在键目的。不幸的是,std::unordered_map::find需要Key参数,不是通用的T争论。(当然,我可以将一个“提升”为string,但这会导致我想避免的分配。

c++ - 结构作为 unordered_map 的键

我在使用结构作为键将数据放入unordered_map时遇到问题:typedefstructosdpi_flow_identificator{u32lower_ip;u32upper_ip;u16lower_port;u16upper_port;u8protocol;}osdpi_flow_identificator_t;//customhashfunctionforosdpi_flow_identificatorstructosdpi_flow_hash{std::size_toperator()(osdpi_flow_identificator*key)const{hashhash

c++ - 将 boost::unordered_set 作为结果映射传递给 boost::split

有谁知道将boost::unordered_set作为第一个参数传递给boost::split是否合理?在libboost1.42-dev下,这似乎会导致问题。这是导致问题的一个小示例程序,将其称为test-split.cc:#include#include#include#includeintmain(intargc,char**argv){boost::unordered_settags_set;boost::split(tags_set,"a^b^c^",boost::is_any_of(std::string(1,'^')));return0;}然后,如果我运行以下命令:g++

c++ - 使用 unordered_map 而不是 map 时出现链接器错误?

这是一个很奇怪的问题。我有两个类:一个自定义控制台类(CConsole)和一个测试类(CHashTableTest),我制作它们是为了玩弄map和unordered_maps以了解它们的工作原理。在我的控制台类中,我有一个CConsole的公共(public)静态成员变量,它向项目的其余部分公开一个静态控制台对象,这样我就可以在需要时写入此控制台。这适用于我所有的类,包括测试类,但仅当测试类使用map而不是unordered_map时!我收到的错误是:错误LNK2001:未解析的外部符号“publicstaticclassCConsoleCConsole:output”(?output