根据不同的索引排序结构体。其中tag的意思是指定一个标记,如果不指定的话默认是从0开始,以下例子展示了这两种情况
代码:
#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 Person{
int id;
int age;
int height;
string name;
Person(int id_,int age_,int height_,std::string name_):
id(id_),
age(age_),
height(height_),
name(name_)
{}
};
std::ostream& operator<<(std::ostream& os,const Person& ps)
{
os<<ps.id<<" "<<ps.age<<" "<<ps.height<<" "<<ps.name<<" "<<std::endl;
return os;
}
typedef multi_index_container<
Person,
indexed_by<
ordered_unique<member<Person, int, &Person::id> >,
ordered_non_unique<member<Person, int,