具有多个“索引”的标准C++数据结构

问题描述:

C++(或C++ 11)中是否有像set那样的标准结构或库,但可能有多个key具有多个“索引”的标准C++数据结构

即一组std :: pair可以快速查找ab

所以你可以做这样的事情:

std::string a = "hello"; 
std::string b = "world"; 

x.insert(a, b); 

x.get<1>("hello") => std::pair("hello", "world"); // (fast lookup) 
x.get<2>("world") => std::pair("hello", "world"); // (fast lookup) 

基本上就像两个索引数据库表。

我宁可不重新发明轮子,如果已经存在。

一个简单的方法来结合现有的容器,使这个功能的东西也将是很好的。

+1

看看这个例子:http://stackoverflow.com/questions/4450095/maintaining-a-unique-set-of-elements-on-different-criteria-c-stl/4450256#4450256 – AraK

我不确定你对“标准C++”的定义是什么,但Boost.MultiIndex适用于任何标准的C++编译器。