]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/algorithm/test/find_if_not_test1.cpp
2 Copyright (c) Marshall Clow 2011-2012.
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)
7 For more information, see http://www.boost.org
12 #include <boost/config.hpp>
13 #include <boost/algorithm/cxx11/find_if_not.hpp>
15 #define BOOST_TEST_MAIN
16 #include <boost/test/unit_test.hpp>
22 namespace ba
= boost::algorithm
;
23 // namespace ba = boost;
25 BOOST_CXX14_CONSTEXPR
bool is_true ( int v
) { return true; }
26 BOOST_CXX14_CONSTEXPR
bool is_false ( int v
) { return false; }
27 BOOST_CXX14_CONSTEXPR
bool is_not_three ( int v
) { return v
!= 3; }
29 BOOST_CXX14_CONSTEXPR
bool check_constexpr() {
30 int in_data
[] = {1, 2, 3, 4, 5};
33 const int* from
= in_data
;
34 const int* to
= in_data
+ 5;
36 const int* start
= ba::find_if_not (from
, to
, is_false
); // stops on first
37 res
= (res
&& start
== from
);
39 const int* end
= ba::find_if_not(from
, to
, is_true
); // stops on the end
40 res
= (res
&& end
== to
);
42 const int* three
= ba::find_if_not(from
, to
, is_not_three
); // stops on third element
43 res
= (res
&& three
== in_data
+ 2);
48 template <typename Container
>
49 typename
Container::iterator
offset_to_iter ( Container
&v
, int offset
) {
50 typename
Container::iterator retval
;
54 std::advance ( retval
, offset
);
58 std::advance ( retval
, offset
+ 1 );
63 template <typename Container
, typename Predicate
>
64 void test_sequence ( Container
&v
, Predicate comp
, int expected
) {
65 typename
Container::iterator res
, exp
;
67 res
= ba::find_if_not ( v
.begin (), v
.end (), comp
);
68 exp
= offset_to_iter ( v
, expected
);
69 std::cout
<< "Expected(1): " << std::distance ( v
.begin (), exp
)
70 << ", got: " << std::distance ( v
.begin (), res
) << std::endl
;
71 BOOST_CHECK ( exp
== res
);
77 less_than ( T foo
) : val ( foo
) {}
78 less_than ( const less_than
&rhs
) : val ( rhs
.val
) {}
80 bool operator () ( const T
&v
) const { return v
< val
; }
83 less_than
operator = ( const less_than
&rhs
);
88 void test_sequence1 () {
92 for ( int i
= 5; i
< 15; ++i
)
94 test_sequence ( v
, less_than
<int>(3), 0 ); // no elements
95 test_sequence ( v
, less_than
<int>(6), 1 ); // only the first element
96 test_sequence ( v
, less_than
<int>(10), 5 );
97 test_sequence ( v
, less_than
<int>(99), -1 ); // all elements satisfy
99 // With bidirectional iterators.
101 for ( int i
= 5; i
< 15; ++i
)
103 test_sequence ( l
, less_than
<int>(3), 0 ); // no elements
104 test_sequence ( l
, less_than
<int>(6), 1 ); // only the first element
105 test_sequence ( l
, less_than
<int>(10), 5 );
106 test_sequence ( l
, less_than
<int>(99), -1 ); // all elements satisfy
111 BOOST_AUTO_TEST_CASE( test_main
)