// 忽略警告
#define _SCL_SECURE_NO_WARNINGS
#pragma warning(disable : 4996)
#include <iostream>
#include <boost/bimap.hpp>// map的双向映射
#include <boost/typeof/typeof.hpp>// BOOST_AUTO
#include <boost/bimap/unordered_set_of.hpp>// unordered_set_of
using namespace boost;
using namespace std;
using namespace boost::bimaps;
int main()
{
bimap<int,string> bmp;// 默认为<int,set_of>相当于std::map
// 左视图left相当于map<int,string> // 按int有序
bmp.left.insert(make_pair(1, "one"));
bmp.left.insert(make_pair(1, "one1")); // 1已经存在,插入无效
bimap<int, string>::value_type vt(2, "two");
bmp.insert(vt);
bmp.left.insert(make_pair(5, "two")); // two已经存在,插入无效
BOOST_AUTO(it, bmp.left.begin());
while (it != bmp.left.end())
{
cout << "key:" << it->first << " value:" << it->second << endl;// 1 2
it++;
}
// 右视图right相当于map<string,int>// 按string有序
bmp.right.insert(make_pair("three",3));
bmp.right.insert(make_pair("one1111", 1)); // 1已经存在,插入无效
bmp.right.insert(make_pair("one", 11)); // one已经存在,插入无效
bmp.right.insert(make_pair("four", 4));
BOOST_AUTO(it1, bmp.right.begin());
while (it1 != bmp.right.end())
{
cout << "key:" << it1->first << " value:" << it1->second << endl;//foue one three two
it1++;
}
cout << "-----------------unordered_set_of-------------------" << endl;
bimap<int, unordered_set_of<string>> bmp1;// 右视图相当于std::unordered_map
bimap<int, string>::value_type vt1(2, "two");
bmp1.insert(vt);
bmp1.left.insert(make_pair(1, "one"));
bmp1.left.insert(make_pair(4, "four"));
bmp1.left.insert(make_pair(3, "three"));
BOOST_AUTO(it2, bmp1.right.begin());
while (it2 != bmp1.right.end())
{
cout << "key:" << it2->first << " value:" << it2->second << endl;// two one four three
it2++;
}
return 0;
}