]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/multi_index/test/test_basic.cpp
1 /* Boost.MultiIndex basic test.
3 * Copyright 2003-2017 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 #include "test_basic.hpp"
13 #include <boost/config.hpp> /* keep it first to prevent nasty warns in MSVC */
16 #include "pre_multi_index.hpp"
17 #include "employee.hpp"
18 #include <boost/detail/lightweight_test.hpp>
20 using namespace boost::multi_index
;
22 struct less_by_employee_age
24 bool operator()(const employee
& e1
,const employee
& e2
)const
30 struct no_addressof_type
32 no_addressof_type(int n
):n(n
){}
34 void operator&()const{}
39 bool operator==(const no_addressof_type
& x
,const no_addressof_type
& y
)
44 bool operator<(const no_addressof_type
& x
,const no_addressof_type
& y
)
49 #if defined(BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP)
53 inline std::size_t hash_value(const no_addressof_type
& x
)
59 #if defined(BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP)
60 } /* namespace boost */
66 std::vector
<employee
> v
;
68 #if defined(BOOST_NO_MEMBER_TEMPLATES)
69 employee_set_by_name
& i1
=get
<by_name
>(es
);
71 employee_set_by_name
& i1
=es
.get
<by_name
>();
74 const employee_set_by_age
& i2
=get
<2>(es
);
75 employee_set_as_inserted
& i3
=get
<3>(es
);
76 employee_set_by_ssn
& i4
=get
<ssn
>(es
);
77 employee_set_randomly
& i5
=get
<randomly
>(es
);
79 es
.insert(employee(0,"Joe",31,1123));
80 es
.insert(employee(5,"Anna",41,1123)); /* clash*/
81 i1
.insert(employee(1,"Robert",27,5601));
82 es
.insert(employee(2,"John",40,7889));
83 i3
.push_back(employee(3,"Albert",20,9012));
84 i4
.insert(employee(4,"John",57,1002));
85 i5
.push_back(employee(0,"Andrew",60,2302)); /* clash */
87 v
.push_back(employee(0,"Joe",31,1123));
88 v
.push_back(employee(1,"Robert",27,5601));
89 v
.push_back(employee(2,"John",40,7889));
90 v
.push_back(employee(3,"Albert",20,9012));
91 v
.push_back(employee(4,"John",57,1002));
94 /* by insertion order */
96 BOOST_TEST(std::equal(i3
.begin(),i3
.end(),v
.begin()));
97 BOOST_TEST(std::equal(i5
.begin(),i5
.end(),v
.begin()));
103 std::sort(v
.begin(),v
.end());
104 BOOST_TEST(std::equal(es
.begin(),es
.end(),v
.begin()));
110 std::sort(v
.begin(),v
.end(),less_by_employee_age());
111 BOOST_TEST(std::equal(i2
.begin(),i2
.end(),v
.begin()));
115 /* testcase for https://svn.boost.org/trac10/ticket/13307 */
117 typedef multi_index_container
<
121 ordered_non_unique
<identity
<no_addressof_type
> >,
123 hashed_non_unique
<identity
<no_addressof_type
> >
128 const multi_index_t
& cc
=c
;
129 no_addressof_type
x(0);
133 c
.insert(c
.end(),a
,a
+2);
134 c
.push_back(no_addressof_type(3));
136 c
.get
<1>().emplace_hint(c
.get
<1>().begin(),5);
137 c
.get
<1>().insert(b
,b
+2);
139 (void)c
.get
<1>().begin()->n
;
140 (void)c
.get
<2>().begin()->n
;
141 (void)c
.get
<3>().begin()->n
;
142 (void)c
.get
<3>().begin(0)->n
;
143 (void)c
.iterator_to(c
.front());
144 (void)cc
.iterator_to(c
.front());
145 (void)c
.get
<1>().iterator_to(c
.front());
146 (void)cc
.get
<1>().iterator_to(c
.front());
147 (void)c
.get
<2>().iterator_to(c
.front());
148 (void)cc
.get
<2>().iterator_to(c
.front());
149 (void)c
.get
<3>().iterator_to(c
.front());
150 (void)cc
.get
<3>().iterator_to(c
.front());
151 (void)c
.get
<3>().local_iterator_to(c
.front());
152 (void)cc
.get
<3>().local_iterator_to(c
.front());
153 multi_index_t c2
=c
;(void)c2
;
155 c
.erase(c
.begin(),c
.end());