boost multi_index简单了解

#include 
#include 
#include 
#include 
#include 
#include 

using namespace boost;
using namespace boost::multi_index;
using namespace std;

struct Employee{
    int id;
    string name;
    int age;

    Employee():id(0),age(0){}
    Employee(int id_,string name_,int age_):id(id_),name(name_),age(age_){}

    friend ostream& operator<<(ostream& os,const Employee& e)
    {
        os<,  
                composite_key<
                    Employee,
                    member,
                    member > >,
        ordered_unique< tag, member >,
        ordered_non_unique< tag, member >,
        ordered_non_unique< tag, member >
    >
> EmployeeContainer;


//模板函数,用法: print_out_by(multi_index_container_instance)
template 
void print_out_by(const MultiIndexContainer &s)
{
    /* obtain a reference to the index tagged by Tag */

    const typename boost::multi_index::index::type &i = get(s);

    typedef typename MultiIndexContainer::value_type value_type;

    /* dump the elements of the index to cout */

    std::copy(i.begin(), i.end(), std::ostream_iterator(std::cout));
}

int main(){
    EmployeeContainer employee;
    employee.insert(Employee(1,"罗一",21));
    employee.insert(Employee(2,"周二",18));
    employee.get().insert(Employee(6,"郑六",21));
    employee.insert(Employee(7,"黄七",20));
    employee.insert(Employee(3,"张三",19));
    employee.insert(Employee(4,"李四",28));
    employee.insert(Employee(5,"李四",23));
    employee.insert(Employee(8,"王八",19));
    employee.insert(Employee(10,"杨十",22));

    //1 打印相关信息
    std::cout<<"Employee by ID"<(employee);
    std::cout<(employee);
    std::cout<(employee);
    std::cout<(employee);

    return 0;
}

你可能感兴趣的:(boost multi_index简单了解)