]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/detail/test/is_sorted_test.cpp
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / boost / libs / detail / test / is_sorted_test.cpp
1 /*==============================================================================
2 Copyright (c) 2010-2011 Bryce Lelbach
3
4 Distributed under the Boost Software License, Version 1.0. (See accompanying
5 file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6 ==============================================================================*/
7
8 #include <ios>
9 #include <boost/config.hpp>
10 #include <boost/array.hpp>
11 #include <boost/detail/is_sorted.hpp>
12 #include <boost/detail/lightweight_test.hpp>
13
14 template<class T>
15 struct tracking_less: std::binary_function <T, T, bool> {
16 typedef bool result_type;
17
18 #if defined(__PATHSCALE__)
19 tracking_less (void) { }
20 ~tracking_less (void) { }
21 #endif
22
23 bool operator() (T const& x, T const& y) const {
24 std::cout << x << " < " << y << " == " << (x < y) << "\n";
25 return x < y;
26 }
27 };
28
29 template<class T>
30 struct tracking_less_equal: std::binary_function <T, T, bool> {
31 typedef bool result_type;
32
33 #if defined(__PATHSCALE__)
34 tracking_less_equal (void) { }
35 ~tracking_less_equal (void) { }
36 #endif
37
38 bool operator() (T const& x, T const& y) const {
39 std::cout << x << " <= " << y << " == " << (x <= y) << "\n";
40 return x <= y;
41 }
42 };
43
44 template<class T>
45 struct tracking_greater: std::binary_function <T, T, bool> {
46 typedef bool result_type;
47
48 #if defined(__PATHSCALE__)
49 tracking_greater (void) { }
50 ~tracking_greater (void) { }
51 #endif
52
53 bool operator() (T const& x, T const& y) const {
54 std::cout << x << " > " << y << " == " << (x > y) << "\n";
55 return x > y;
56 }
57 };
58
59 template<class T>
60 struct tracking_greater_equal: std::binary_function <T, T, bool> {
61 typedef bool result_type;
62
63 #if defined(__PATHSCALE__)
64 tracking_greater_equal (void) { }
65 ~tracking_greater_equal (void) { }
66 #endif
67
68 bool operator() (T const& x, T const& y) const {
69 std::cout << x << " >= " << y << " == " << (x >= y) << "\n";
70 return x >= y;
71 }
72 };
73
74
75 int main (void) {
76 #define IS_SORTED ::boost::detail::is_sorted
77 #define IS_SORTED_UNTIL ::boost::detail::is_sorted_until
78 using boost::array;
79 using boost::report_errors;
80
81 std::cout << std::boolalpha;
82
83 array<int, 10> a = { { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 } };
84 array<int, 10> b = { { 0, 1, 1, 2, 5, 8, 13, 34, 55, 89 } };
85 array<int, 10> c = { { 0, 1, -1, 2, -3, 5, -8, 13, -21, 34 } };
86
87 tracking_less<int> lt;
88 tracking_less_equal<int> lte;
89 tracking_greater<int> gt;
90 tracking_greater_equal<int> gte;
91
92 BOOST_TEST_EQ(IS_SORTED_UNTIL(a.begin(), a.end()), a.end());
93 BOOST_TEST_EQ(IS_SORTED_UNTIL(a.begin(), a.end(), lt), a.end());
94 BOOST_TEST_EQ(IS_SORTED_UNTIL(a.begin(), a.end(), lte), a.end());
95 BOOST_TEST_EQ(IS_SORTED_UNTIL(a.rbegin(), a.rend(), gt).base(), a.rend().base());
96 BOOST_TEST_EQ(IS_SORTED_UNTIL(a.rbegin(), a.rend(), gte).base(), a.rend().base());
97
98 BOOST_TEST_EQ(IS_SORTED(a.begin(), a.end()), true);
99 BOOST_TEST_EQ(IS_SORTED(a.begin(), a.end(), lt), true);
100 BOOST_TEST_EQ(IS_SORTED(a.begin(), a.end(), lte), true);
101 BOOST_TEST_EQ(IS_SORTED(a.rbegin(), a.rend(), gt), true);
102 BOOST_TEST_EQ(IS_SORTED(a.rbegin(), a.rend(), gte), true);
103
104 BOOST_TEST_EQ(IS_SORTED_UNTIL(b.begin(), b.end()), b.end());
105 BOOST_TEST_EQ(IS_SORTED_UNTIL(b.begin(), b.end(), lt), b.end());
106 BOOST_TEST_EQ(IS_SORTED_UNTIL(b.begin(), b.end(), lte), &b[2]);
107 BOOST_TEST_EQ(IS_SORTED_UNTIL(b.rbegin(), b.rend(), gt).base(), b.rend().base());
108 BOOST_TEST_EQ(IS_SORTED_UNTIL(b.rbegin(), b.rend(), gte).base(), &b[2]);
109
110 BOOST_TEST_EQ(IS_SORTED(b.begin(), b.end()), true);
111 BOOST_TEST_EQ(IS_SORTED(b.begin(), b.end(), lt), true);
112 BOOST_TEST_EQ(IS_SORTED(b.begin(), b.end(), lte), false);
113 BOOST_TEST_EQ(IS_SORTED(b.rbegin(), b.rend(), gt), true);
114 BOOST_TEST_EQ(IS_SORTED(b.rbegin(), b.rend(), gte), false);
115
116 BOOST_TEST_EQ(IS_SORTED_UNTIL(c.begin(), c.end()), &c[2]);
117 BOOST_TEST_EQ(IS_SORTED_UNTIL(c.begin(), c.end(), lt), &c[2]);
118 BOOST_TEST_EQ(IS_SORTED_UNTIL(c.begin(), c.end(), lte), &c[2]);
119 BOOST_TEST_EQ(IS_SORTED_UNTIL(c.rbegin(), c.rend(), gt).base(), &c[8]);
120 BOOST_TEST_EQ(IS_SORTED_UNTIL(c.rbegin(), c.rend(), gte).base(), &c[8]);
121
122 BOOST_TEST_EQ(IS_SORTED(c.begin(), c.end()), false);
123 BOOST_TEST_EQ(IS_SORTED(c.begin(), c.end(), lt), false);
124 BOOST_TEST_EQ(IS_SORTED(c.begin(), c.end(), lte), false);
125 BOOST_TEST_EQ(IS_SORTED(c.rbegin(), c.rend(), gt), false);
126 BOOST_TEST_EQ(IS_SORTED(c.rbegin(), c.rend(), gte), false);
127
128 return report_errors();
129 }
130