size_tとstd::stringの間のバイマップを取得するには、〜constant(ハッシュと潜在的な衝突のコストまで)がある場合、unordered_set_ofを使用する必要があります。
#include <boost/bimap.hpp>
#include <boost/bimap/unordered_set_of.hpp>
#include <string>
#include <iostream>
#include <typeinfo>
int main(int argc, char* argv[]) {
typedef boost::bimap< boost::bimaps::unordered_set_of<size_t>, boost::bimaps::unordered_set_of<std::string> > StringMap;
StringMap map;
map.insert(StringMap::value_type(1,std::string("Cheese")));
map.insert(StringMap::value_type(2,std::string("Cheese2")));
typedef StringMap::left_map::const_iterator const_iter_type;
const const_iter_type end = map.left.end();
for ( const_iter_type iter = map.left.begin(); iter != end; iter++ ) {
std::cout << iter->first << " " << map.left.at(iter->first) << "\n";
}
}
戻り値:
1 Cheese
2 Cheese2
unordered_setは、ツリーの代わりにハッシュテーブルを使用して要素を格納するセットのブーストバージョンです。BoostUnorderedドキュメントを参照してください。
Bimapの例のbimapの例の1つからのコメントを見ると、次のようになっています。
左側のマップビューは、std :: unordered_map <std :: string、long>のように機能します。国の名前を指定すると、一定時間で人口を検索するために使用できます。