2011-10-11 38 views
1

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

回答

8

我不確定你對「標準C++」的定義是什麼,但Boost.MultiIndex適用於任何標準的C++編譯器。