]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/phoenix/test/algorithm/querying.cpp
1 /*=============================================================================
2 Copyright (c) 2005 Dan Marsden
3 Copyright (c) 2005-2007 Joel de Guzman
4 Copyright (c) 2007 Hartmut Kaiser
5 Copyright (c) 2015 John Fletcher
7 Distributed under the Boost Software License, Version 1.0. (See accompanying
8 file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
9 ==============================================================================*/
11 #include <boost/phoenix/core.hpp>
12 #include <boost/phoenix/stl/algorithm/querying.hpp>
13 #include <boost/detail/lightweight_test.hpp>
14 #include <boost/assign/list_of.hpp>
16 #include <boost/config.hpp>
18 #ifdef BOOST_PHOENIX_HAS_HASH
19 #define _GLIBCXX_PERMIT_BACKWARD_HASH
20 #include BOOST_PHOENIX_HASH_SET_HEADER
21 #include BOOST_PHOENIX_HASH_MAP_HEADER
32 bool operator()(const int i
) const
38 struct mod_2_comparison
44 return lhs
% 2 == rhs
% 2;
50 using boost::phoenix::arg_names::arg1
;
51 int array
[] = {1,2,3};
52 BOOST_TEST(boost::phoenix::find(arg1
,2)(array
) == array
+ 1);
54 std::set
<int> s(array
, array
+ 3);
55 BOOST_TEST(boost::phoenix::find(arg1
, 2)(s
) == s
.find(2));
57 #if !(defined(BOOST_MSVC) && (BOOST_MSVC >= 1900))
58 std::map
<int, int> m
= boost::assign::map_list_of(0, 1)(2, 3)(4, 5);
59 BOOST_TEST(boost::phoenix::find(arg1
, 2)(m
) == m
.find(2));
62 #ifdef BOOST_PHOENIX_HAS_HASH
64 BOOST_PHOENIX_HASH_NAMESPACE::hash_set
<int> hs(array
, array
+ 3);
65 BOOST_TEST(boost::phoenix::find(arg1
, 2)(hs
) == hs
.find(2));
67 BOOST_PHOENIX_HASH_NAMESPACE::hash_map
<int, int> hm
= boost::assign::map_list_of(0, 1)(2, 3)(4, 5);
68 BOOST_TEST(boost::phoenix::find(arg1
, 2)(hm
) == hm
.find(2));
78 using boost::phoenix::arg_names::arg1
;
79 int array
[] = {1,2,3};
80 BOOST_TEST(boost::phoenix::find_if(arg1
, even())(array
) == array
+ 1);
86 using boost::phoenix::arg_names::arg1
;
87 using boost::phoenix::arg_names::arg2
;
88 int array
[] = {1,2,3,1,2,3,1};
89 int pattern
[] = {1,2,3};
90 BOOST_TEST(boost::phoenix::find_end(arg1
, arg2
)(array
, pattern
) == array
+ 3);
91 int pattern2
[] = {5,6,5};
92 BOOST_TEST(boost::phoenix::find_end(arg1
, arg2
, mod_2_comparison())(array
, pattern2
) == array
+ 3);
96 void find_first_of_test()
98 using boost::phoenix::arg_names::arg1
;
99 using boost::phoenix::arg_names::arg2
;
100 int array
[] = {1,2,3};
101 int search_for
[] = {2,3,4};
102 BOOST_TEST(boost::phoenix::find_first_of(arg1
, arg2
)(array
, search_for
) == array
+ 1);
104 int search_for2
[] = {0};
105 BOOST_TEST(boost::phoenix::find_first_of(arg1
, arg2
, mod_2_comparison())(array
, search_for2
) == array
+ 1);
109 void adjacent_find_test()
111 using boost::phoenix::arg_names::arg1
;
112 int array
[] = {0,1,3,4,4};
113 BOOST_TEST(boost::phoenix::adjacent_find(arg1
)(array
) == array
+ 3);
114 BOOST_TEST(boost::phoenix::adjacent_find(arg1
, mod_2_comparison())(array
) == array
+ 1);
120 using boost::phoenix::arg_names::arg1
;
121 int array
[] = {1,1,0,1,1};
122 BOOST_TEST(boost::phoenix::count(arg1
, 1)(array
) == 4);
128 using boost::phoenix::arg_names::arg1
;
129 int array
[] = {1,2,3,4,5};
130 BOOST_TEST(boost::phoenix::count_if(arg1
, even())(array
) == 2);
136 using boost::phoenix::arg_names::arg1
;
137 int array
[] = {1,1,0,1,1};
138 BOOST_TEST(boost::phoenix::distance(arg1
)(array
) == 5);
144 using boost::phoenix::arg_names::arg1
;
145 using boost::phoenix::arg_names::arg2
;
146 int array
[] = {1,2,3,4,5};
147 int search
[] = {1,2,4};
150 boost::phoenix::mismatch(arg1
, arg2
)(array
, search
) ==
151 std::make_pair(array
+ 2, search
+ 2));
152 int search2
[] = {1,2,1,1};
154 boost::phoenix::mismatch(arg1
, arg2
, mod_2_comparison())(array
, search2
)
155 == std::make_pair(array
+ 3, search2
+ 3));
162 using boost::phoenix::arg_names::arg1
;
163 using boost::phoenix::arg_names::arg2
;
164 int array
[] = {1,2,3};
165 int array2
[] = {1,2,3};
166 int array3
[] = {1,2,4};
168 boost::phoenix::equal(arg1
, arg2
)(array
, array2
));
170 !boost::phoenix::equal(arg1
, arg2
)(array
, array3
));
173 boost::phoenix::equal(arg1
, arg2
, mod_2_comparison())(array
, array2
));
175 !boost::phoenix::equal(arg1
, arg2
, mod_2_comparison())(array
, array3
));
181 using boost::phoenix::arg_names::arg1
;
182 using boost::phoenix::arg_names::arg2
;
183 int array
[] = {1,2,3,1,2,3};
184 int pattern
[] = {2,3};
186 boost::phoenix::search(arg1
, arg2
)(array
, pattern
) == array
+ 1);
187 int pattern2
[] = {1,1};
189 boost::phoenix::search(arg1
, arg2
, mod_2_comparison())(array
, pattern2
) == array
+ 2);
193 void lower_bound_test()
195 using boost::phoenix::arg_names::arg1
;
196 int array
[] = {1,2,3};
197 const std::set
<int> test_set(array
, array
+ 3);
198 BOOST_TEST(boost::phoenix::lower_bound(arg1
, 2)(array
) == array
+ 1);
199 BOOST_TEST(boost::phoenix::lower_bound(arg1
, 2)(test_set
) == test_set
.lower_bound(2));
201 int array2
[] = {3,2,1};
202 const std::set
<int, std::greater
<int> > test_set2(array2
, array2
+ 3);
203 BOOST_TEST(boost::phoenix::lower_bound(arg1
, 2, std::greater
<int>())(array2
) ==
205 BOOST_TEST(boost::phoenix::lower_bound(arg1
, 2, std::greater
<int>())(test_set2
) ==
206 test_set2
.lower_bound(2));
210 void upper_bound_test()
212 using boost::phoenix::arg_names::arg1
;
213 int array
[] = {1,2,3};
214 const std::set
<int> test_set(array
, array
+ 3);
215 BOOST_TEST(upper_bound(arg1
, 2)(array
) == array
+ 2);
216 BOOST_TEST(upper_bound(arg1
, 2)(test_set
) == test_set
.upper_bound(2));
218 int array2
[] = {3,2,1};
219 const std::set
<int, std::greater
<int> > test_set2(array2
, array2
+ 3);
220 BOOST_TEST(boost::phoenix::upper_bound(arg1
, 2, std::greater
<int>())(array2
) ==
222 BOOST_TEST(boost::phoenix::upper_bound(arg1
, 2, std::greater
<int>())(test_set2
) ==
223 test_set2
.upper_bound(2));
227 void equal_range_test()
229 using boost::phoenix::arg_names::arg1
;
230 int array
[] = {1,2,2,3};
231 const std::set
<int> test_set(array
, array
+ 4);
232 BOOST_TEST(boost::phoenix::equal_range(arg1
, 2)(array
).first
==
234 BOOST_TEST(boost::phoenix::equal_range(arg1
, 2)(array
).second
==
237 BOOST_TEST(boost::phoenix::equal_range(arg1
, 2)(test_set
).first
==
238 test_set
.equal_range(2).first
);
239 BOOST_TEST(boost::phoenix::equal_range(arg1
, 2)(test_set
).second
==
240 test_set
.equal_range(2).second
);
242 int array2
[] = {3,2,2,1};
243 const std::set
<int, std::greater
<int> > test_set2(array2
, array2
+ 4);
244 BOOST_TEST(boost::phoenix::equal_range(arg1
, 2, std::greater
<int>())(array2
).first
==
246 BOOST_TEST(boost::phoenix::equal_range(arg1
, 2, std::greater
<int>())(array2
).second
==
249 BOOST_TEST(boost::phoenix::equal_range(arg1
, 2, std::greater
<int>())(test_set2
).first
==
250 test_set2
.equal_range(2).first
);
251 BOOST_TEST(boost::phoenix::equal_range(arg1
, 2, std::greater
<int>())(test_set2
).second
==
252 test_set2
.equal_range(2).second
);
257 void binary_search_test()
259 using boost::phoenix::arg_names::arg1
;
260 int array
[] = {1,2,3};
261 BOOST_TEST(boost::phoenix::binary_search(arg1
, 2)(array
));
262 BOOST_TEST(!boost::phoenix::binary_search(arg1
, 4)(array
));
273 find_first_of_test();
274 adjacent_find_test();
284 binary_search_test();
285 return boost::report_errors();