]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/multi_index/test/employee.hpp
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / boost / libs / multi_index / test / employee.hpp
1 /* Used in Boost.MultiIndex tests.
2 *
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)
7 *
8 * See http://www.boost.org/libs/multi_index for library home page.
9 */
10
11 #ifndef BOOST_MULTI_INDEX_TEST_EMPLOYEE_HPP
12 #define BOOST_MULTI_INDEX_TEST_EMPLOYEE_HPP
13
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>
26 #include <cstddef>
27 #include <ostream>
28 #include <string>
29 #include "non_std_allocator.hpp"
30
31 struct employee
32 {
33 int id;
34 std::string name;
35 int age;
36 int ssn;
37
38 employee(int id_,std::string name_,int age_,int ssn_):
39 id(id_),name(name_),age(age_),ssn(ssn_)
40 {}
41
42 employee(const employee& x):
43 id(x.id),name(x.name),age(x.age),ssn(x.ssn)
44 {}
45
46 employee(BOOST_RV_REF(employee) x):
47 id(x.id),name(boost::move(x.name)),age(x.age),ssn(x.ssn)
48 {}
49
50 employee& operator=(BOOST_COPY_ASSIGN_REF(employee) x)
51 {
52 id=x.id;
53 name=x.name;
54 age=x.age;
55 ssn=x.ssn;
56 return *this;
57 };
58
59 employee& operator=(BOOST_RV_REF(employee) x)
60 {
61 id=x.id;
62 name=boost::move(x.name);
63 age=x.age;
64 ssn=x.ssn;
65 return *this;
66 }
67
68 bool operator==(const employee& x)const
69 {
70 return id==x.id&&name==x.name&&age==x.age;
71 }
72
73 bool operator<(const employee& x)const
74 {
75 return id<x.id;
76 }
77
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);}
82
83 struct comp_id
84 {
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;}
87 };
88
89 friend std::ostream& operator<<(std::ostream& os,const employee& e)
90 {
91 os<<e.id<<" "<<e.name<<" "<<e.age<<std::endl;
92 return os;
93 }
94
95 private:
96 BOOST_COPYABLE_AND_MOVABLE(employee)
97 };
98
99 struct name{};
100 struct by_name{};
101 struct age{};
102 struct as_inserted{};
103 struct ssn{};
104 struct randomly{};
105
106 struct employee_set_indices:
107 boost::mpl::vector<
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> > >
123 {};
124
125 typedef
126 boost::multi_index::multi_index_container<
127 employee,
128 employee_set_indices,
129 non_std_allocator<employee> > employee_set;
130
131 #if defined(BOOST_NO_MEMBER_TEMPLATES)
132 typedef boost::multi_index::nth_index<
133 employee_set,1>::type employee_set_by_name;
134 #else
135 typedef employee_set::nth_index<1>::type employee_set_by_name;
136 #endif
137
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;
144
145 #if defined(BOOST_NO_MEMBER_TEMPLATES)
146 typedef boost::multi_index::index<
147 employee_set,randomly>::type employee_set_randomly;
148 #else
149 typedef employee_set::index<
150 randomly>::type employee_set_randomly;
151 #endif
152
153 #endif