]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/multi_index/test/test_set_ops.cpp
1 /* Boost.MultiIndex test for standard set operations.
3 * Copyright 2003-2022 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_set_ops.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
;
27 operator type1()const{return type1();}
32 operator type1()const{return type1();}
37 bool operator()(type1
,type1
)const{return false;}
38 bool operator()(type1
,type2
)const{return false;}
39 bool operator()(type2
,type1
)const{return false;}
42 bool less_type1_f(type1
,type1
){return false;}
46 std::size_t operator()(type1
)const{return 0;}
47 std::size_t operator()(type2
)const{return 0;}
52 bool operator()(type1
,type1
)const{return true;}
53 bool operator()(type1
,type2
)const{return true;}
54 bool operator()(type2
,type1
)const{return true;}
60 employee_set_by_name
& i1
=get
<by_name
>(es
);
61 const employee_set_by_age
& i2
=get
<age
>(es
);
62 employee_set_by_ssn
& i4
=get
<ssn
>(es
);
64 es
.insert(employee(0,"Joe",31,1123));
65 es
.insert(employee(1,"Robert",27,5601));
66 es
.insert(employee(2,"John",40,7889));
67 es
.insert(employee(3,"Albert",20,9012));
68 es
.insert(employee(4,"John",57,1002));
70 BOOST_TEST(i1
.find("John")->name
=="John");
71 BOOST_TEST(i2
.find(41)==i2
.end());
72 BOOST_TEST(i4
.find(5601)->name
=="Robert");
74 BOOST_TEST(i1
.count("John")==2);
75 BOOST_TEST(i2
.count(20)==1);
76 BOOST_TEST(es
.count(employee(10,"",-1,0))==0);
77 BOOST_TEST(i4
.count(7881)==0);
79 BOOST_TEST(i1
.contains("John"));
80 BOOST_TEST(!es
.contains(employee(10,"",-1,0)));
81 BOOST_TEST(!i4
.contains(7881));
86 i2
.upper_bound(60))==3);
88 std::pair
<employee_set_by_name::iterator
,employee_set_by_name::iterator
> p
=
89 i1
.equal_range("John");
90 BOOST_TEST(std::distance(p
.first
,p
.second
)==2);
92 p
=i1
.equal_range("Serena");
93 BOOST_TEST(p
.first
==i1
.end()&&p
.second
==i1
.end());
95 std::pair
<employee_set_by_age::iterator
,employee_set_by_age::iterator
> p2
=
97 BOOST_TEST(p2
.first
==p2
.second
&&p2
.first
->age
==31);
99 /* check promotion detection plays nice with private conversion */
101 multi_index_container
<
104 ordered_unique
<identity
<type1
>,less_type12
>,
105 hashed_unique
<identity
<type1
>,hash_type12
,eq_type12
>
110 BOOST_TEST(c
.find(type2())==c
.begin());
111 BOOST_TEST(c
.count(type2())==1);
112 BOOST_TEST(c
.contains(type2()));
113 BOOST_TEST(c
.lower_bound(type2())==c
.begin());
114 BOOST_TEST(c
.upper_bound(type2())==c
.end());
115 BOOST_TEST(c
.equal_range(type2())==std::make_pair(c
.begin(),c
.end()));
117 BOOST_TEST(c
.get
<1>().find(type2())==c
.get
<1>().begin());
118 BOOST_TEST(c
.get
<1>().count(type2())==1);
119 BOOST_TEST(c
.get
<1>().contains(type2()));
120 BOOST_TEST(c
.get
<1>().equal_range(type2())==
121 std::make_pair(c
.get
<1>().begin(),c
.get
<1>().end()));
123 /* check promotion detection does not break with functions */
125 multi_index_container
<
128 ordered_unique
<identity
<type1
>,bool(*)(type1
,type1
)>
130 > c2(boost::make_tuple(boost::make_tuple(identity
<type1
>(),&less_type1_f
)));
133 BOOST_TEST(c2
.find(type3())==c2
.begin());