Boost Multi-index Containers Library定义了multi_index_container模板类,可以从不同的维度建索引、排序和存取。
如上图,容器multi_index_container分别从shape,number和sequenced(默认插入的顺序)三个维度对元素进行管理。
使用如下:
#include <string>
#include <iostream>
#include <boost/multi_index_container.hpp>
#include <boost/multi_index/member.hpp>
#include <boost/multi_index/ordered_index.hpp>
using namespace boost;
using namespace boost::multi_index;
using namespace std;
struct Employee{
int id;
string name;
int age;
Employee(int id_,std::string name_,int age_):id(id_),name(name_),age(age_){}
friend std::ostream& operator<<(std::ostream& os,const Employee& e)
{
os<<e.id<<" "<<e.name<<" "<<e.age<<std::endl;
return os;
}
};
typedef multi_index_con