First public contribution.
1 /* Used in Boost.MultiIndex tests.
3 * Copyright 2003-2006 Joaquín M López Muñoz.
4 * Distributed under the Boost Software License, Version 1.0.
5 * (See accompanying file LICENSE_1_0.txt or copy at
6 * http://www.boost.org/LICENSE_1_0.txt)
8 * See http://www.boost.org/libs/multi_index for library home page.
11 #ifndef BOOST_MULTI_INDEX_TEST_EMPLOYEE_HPP
12 #define BOOST_MULTI_INDEX_TEST_EMPLOYEE_HPP
14 #include <boost/config.hpp> /* keep it first to prevent nasty warns in MSVC */
15 #include <boost/mpl/vector.hpp>
16 #include <boost/multi_index_container.hpp>
17 #include <boost/multi_index/hashed_index.hpp>
18 #include <boost/multi_index/identity.hpp>
19 #include <boost/multi_index/member.hpp>
20 #include <boost/multi_index/ordered_index.hpp>
21 #include <boost/multi_index/random_access_index.hpp>
22 #include <boost/multi_index/sequenced_index.hpp>
34 employee(int id_,std::string name_,int age_,int ssn_):
35 id(id_),name(name_),age(age_),ssn(ssn_)
38 bool operator==(const employee& x)const
40 return id==x.id&&name==x.name&&age==x.age;
43 bool operator<(const employee& x)const
48 bool operator!=(const employee& x)const{return !(*this==x);}
49 bool operator> (const employee& x)const{return x<*this;}
50 bool operator>=(const employee& x)const{return !(*this<x);}
51 bool operator<=(const employee& x)const{return !(x<*this);}
55 bool operator()(int x,const employee& e2)const{return x<e2.id;}
56 bool operator()(const employee& e1,int x)const{return e1.id<x;}
59 friend std::ostream& operator<<(std::ostream& os,const employee& e)
61 os<<e.id<<" "<<e.name<<" "<<e.age<<std::endl;
73 struct employee_set_indices:
75 boost::multi_index::ordered_unique<
76 boost::multi_index::identity<employee> >,
77 boost::multi_index::hashed_non_unique<
78 boost::multi_index::tag<name,by_name>,
79 BOOST_MULTI_INDEX_MEMBER(employee,std::string,name)>,
80 boost::multi_index::ordered_non_unique<
81 boost::multi_index::tag<age>,
82 BOOST_MULTI_INDEX_MEMBER(employee,int,age)>,
83 boost::multi_index::sequenced<
84 boost::multi_index::tag<as_inserted> >,
85 boost::multi_index::hashed_unique<
86 boost::multi_index::tag<ssn>,
87 BOOST_MULTI_INDEX_MEMBER(employee,int,ssn)>,
88 boost::multi_index::random_access<
89 boost::multi_index::tag<randomly> > >
93 boost::multi_index::multi_index_container<
95 employee_set_indices> employee_set;
97 #if defined(BOOST_NO_MEMBER_TEMPLATES)
98 typedef boost::multi_index::nth_index<
99 employee_set,1>::type employee_set_by_name;
101 typedef employee_set::nth_index<1>::type employee_set_by_name;
104 typedef boost::multi_index::index<
105 employee_set,age>::type employee_set_by_age;
106 typedef boost::multi_index::index<
107 employee_set,as_inserted>::type employee_set_as_inserted;
108 typedef boost::multi_index::index<
109 employee_set,ssn>::type employee_set_by_ssn;
111 #if defined(BOOST_NO_MEMBER_TEMPLATES)
112 typedef boost::multi_index::index<
113 employee_set,randomly>::type employee_set_randomly;
115 typedef employee_set::index<
116 randomly>::type employee_set_randomly;