1
C++(或C++ 11)中是否有像set
那樣的標準結構或庫,但可能有多個key
。具有多個「索引」的標準C++數據結構
即一組std :: pair可以快速查找a
或b
。
所以你可以做這樣的事情:
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)
基本上就像兩個索引數據庫表。
我寧可不重新發明輪子,如果已經存在。
一個簡單的方法來結合現有的容器,使這個功能的東西也將是很好的。
看看這個例子:http://stackoverflow.com/questions/4450095/maintaining-a-unique-set-of-elements-on-different-criteria-c-stl/4450256#4450256 – AraK