]>
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-2014 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(es
.count(employee(10,"",-1,0))==0);
76 BOOST_TEST(i4
.count(7881)==0);
81 i2
.upper_bound(60))==3);
83 std::pair
<employee_set_by_name::iterator
,employee_set_by_name::iterator
> p
=
84 i1
.equal_range("John");
85 BOOST_TEST(std::distance(p
.first
,p
.second
)==2);
87 p
=i1
.equal_range("Serena");
88 BOOST_TEST(p
.first
==i1
.end()&&p
.second
==i1
.end());
90 std::pair
<employee_set_by_age::iterator
,employee_set_by_age::iterator
> p2
=
92 BOOST_TEST(p2
.first
==p2
.second
&&p2
.first
->age
==31);
94 /* check promotion detection plays nice with private conversion */
96 multi_index_container
<
99 ordered_unique
<identity
<type1
>,less_type12
>,
100 hashed_unique
<identity
<type1
>,hash_type12
,eq_type12
>
105 BOOST_TEST(c
.find(type2())==c
.begin());
106 BOOST_TEST(c
.count(type2())==1);
107 BOOST_TEST(c
.lower_bound(type2())==c
.begin());
108 BOOST_TEST(c
.upper_bound(type2())==c
.end());
109 BOOST_TEST(c
.equal_range(type2())==std::make_pair(c
.begin(),c
.end()));
111 BOOST_TEST(c
.get
<1>().find(type2())==c
.get
<1>().begin());
112 BOOST_TEST(c
.get
<1>().count(type2())==1);
113 BOOST_TEST(c
.get
<1>().equal_range(type2())==
114 std::make_pair(c
.get
<1>().begin(),c
.get
<1>().end()));
116 /* check promotion detection does not break with functions */
118 multi_index_container
<
121 ordered_unique
<identity
<type1
>,bool(*)(type1
,type1
)>
123 > c2(boost::make_tuple(boost::make_tuple(identity
<type1
>(),&less_type1_f
)));
126 BOOST_TEST(c2
.find(type3())==c2
.begin());