我的計劃是根據各地對的集合,即STL集合::發現重新定義搜索
typedef std::pair<int,int> innerPair;
typedef std::pair<innerPair,int> setElement;
std::set<setElement> Foo;
的innerPair
元素是真正定義setElement,但我需要一組ID附加到每一個元素,因此後者定義爲setElement
。
在程序的其餘部分,我需要找到innerPair
無論其組ID,所以我基本上需要一個功能
std::set<setElement>::iterator find(innePair);
會找到innerPair不管其組ID。就目前而言,我可以簡單地遍歷所有可用的組ID,並執行多個find()調用,但效率不高。
有定義執行某種通配符搜索,或者我需要用我自己的定義重載它find(...)
成員函數的一個簡潔的方式?
你是說'innerPair'是關鍵,並且組ID是值?如果是這樣,爲什麼不使用「地圖」? – Mehrdad
看起來你實際上想要'std :: map'。 –
您是否在尋找特定的innerpair,或者您是否在尋找具有給定組ID的所有innerPairs? – didierc