]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/detail/test/is_sorted_test.cpp
1 /*==============================================================================
2 Copyright (c) 2010-2011 Bryce Lelbach
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 ==============================================================================*/
9 #include <boost/config.hpp>
10 #include <boost/array.hpp>
11 #include <boost/detail/is_sorted.hpp>
12 #include <boost/detail/lightweight_test.hpp>
15 struct tracking_less
: std::binary_function
<T
, T
, bool> {
16 typedef bool result_type
;
18 #if defined(__PATHSCALE__)
19 tracking_less (void) { }
20 ~tracking_less (void) { }
23 bool operator() (T
const& x
, T
const& y
) const {
24 std::cout
<< x
<< " < " << y
<< " == " << (x
< y
) << "\n";
30 struct tracking_less_equal
: std::binary_function
<T
, T
, bool> {
31 typedef bool result_type
;
33 #if defined(__PATHSCALE__)
34 tracking_less_equal (void) { }
35 ~tracking_less_equal (void) { }
38 bool operator() (T
const& x
, T
const& y
) const {
39 std::cout
<< x
<< " <= " << y
<< " == " << (x
<= y
) << "\n";
45 struct tracking_greater
: std::binary_function
<T
, T
, bool> {
46 typedef bool result_type
;
48 #if defined(__PATHSCALE__)
49 tracking_greater (void) { }
50 ~tracking_greater (void) { }
53 bool operator() (T
const& x
, T
const& y
) const {
54 std::cout
<< x
<< " > " << y
<< " == " << (x
> y
) << "\n";
60 struct tracking_greater_equal
: std::binary_function
<T
, T
, bool> {
61 typedef bool result_type
;
63 #if defined(__PATHSCALE__)
64 tracking_greater_equal (void) { }
65 ~tracking_greater_equal (void) { }
68 bool operator() (T
const& x
, T
const& y
) const {
69 std::cout
<< x
<< " >= " << y
<< " == " << (x
>= y
) << "\n";
76 #define IS_SORTED ::boost::detail::is_sorted
77 #define IS_SORTED_UNTIL ::boost::detail::is_sorted_until
79 using boost::report_errors
;
81 std::cout
<< std::boolalpha
;
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 } };
87 tracking_less
<int> lt
;
88 tracking_less_equal
<int> lte
;
89 tracking_greater
<int> gt
;
90 tracking_greater_equal
<int> gte
;
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());
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);
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]);
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);
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]);
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);
128 return report_errors();