1 /* Used in Boost.MultiIndex tests.
3 * Copyright 2003-2015 Joaquin M Lopez Munoz.
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/move/core.hpp>
16 #include <boost/move/utility.hpp>
17 #include <boost/mpl/vector.hpp>
18 #include <boost/multi_index_container.hpp>
19 #include <boost/multi_index/hashed_index.hpp>
20 #include <boost/multi_index/identity.hpp>
21 #include <boost/multi_index/member.hpp>
22 #include <boost/multi_index/ordered_index.hpp>
23 #include <boost/multi_index/random_access_index.hpp>
24 #include <boost/multi_index/ranked_index.hpp>
25 #include <boost/multi_index/sequenced_index.hpp>
29 #include "non_std_allocator.hpp"
38 employee(int id_,std::string name_,int age_,int ssn_):
39 id(id_),name(name_),age(age_),ssn(ssn_)
42 employee(const employee& x):
43 id(x.id),name(x.name),age(x.age),ssn(x.ssn)
46 employee(BOOST_RV_REF(employee) x):
47 id(x.id),name(boost::move(x.name)),age(x.age),ssn(x.ssn)
50 employee& operator=(BOOST_COPY_ASSIGN_REF(employee) x)
59 employee& operator=(BOOST_RV_REF(employee) x)
62 name=boost::move(x.name);
68 bool operator==(const employee& x)const
70 return id==x.id&&name==x.name&&age==x.age;
73 bool operator<(const employee& x)const
78 bool operator!=(const employee& x)const{return !(*this==x);}
79 bool operator> (const employee& x)const{return x<*this;}
80 bool operator>=(const employee& x)const{return !(*this<x);}
81 bool operator<=(const employee& x)const{return !(x<*this);}
85 bool operator()(int x,const employee& e2)const{return x<e2.id;}
86 bool operator()(const employee& e1,int x)const{return e1.id<x;}
89 friend std::ostream& operator<<(std::ostream& os,const employee& e)
91 os<<e.id<<" "<<e.name<<" "<<e.age<<std::endl;
96 BOOST_COPYABLE_AND_MOVABLE(employee)
102 struct as_inserted{};
106 struct employee_set_indices:
108 boost::multi_index::ordered_unique<
109 boost::multi_index::identity<employee> >,
110 boost::multi_index::hashed_non_unique<
111 boost::multi_index::tag<name,by_name>,
112 BOOST_MULTI_INDEX_MEMBER(employee,std::string,name)>,
113 boost::multi_index::ranked_non_unique<
114 boost::multi_index::tag<age>,
115 BOOST_MULTI_INDEX_MEMBER(employee,int,age)>,
116 boost::multi_index::sequenced<
117 boost::multi_index::tag<as_inserted> >,
118 boost::multi_index::hashed_unique<
119 boost::multi_index::tag<ssn>,
120 BOOST_MULTI_INDEX_MEMBER(employee,int,ssn)>,
121 boost::multi_index::random_access<
122 boost::multi_index::tag<randomly> > >
126 boost::multi_index::multi_index_container<
128 employee_set_indices,
129 non_std_allocator<employee> > employee_set;
131 #if defined(BOOST_NO_MEMBER_TEMPLATES)
132 typedef boost::multi_index::nth_index<
133 employee_set,1>::type employee_set_by_name;
135 typedef employee_set::nth_index<1>::type employee_set_by_name;
138 typedef boost::multi_index::index<
139 employee_set,age>::type employee_set_by_age;
140 typedef boost::multi_index::index<
141 employee_set,as_inserted>::type employee_set_as_inserted;
142 typedef boost::multi_index::index<
143 employee_set,ssn>::type employee_set_by_ssn;
145 #if defined(BOOST_NO_MEMBER_TEMPLATES)
146 typedef boost::multi_index::index<
147 employee_set,randomly>::type employee_set_randomly;
149 typedef employee_set::index<
150 randomly>::type employee_set_randomly;