]>
git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/25_algorithms/lower_bound/partitioned.cc
1 // Copyright (C) 2016 Free Software Foundation, Inc.
3 // This file is part of the GNU ISO C++ Library. This library is free
4 // software; you can redistribute it and/or modify it under the
5 // terms of the GNU General Public License as published by the
6 // Free Software Foundation; either version 3, or (at your option)
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License along
15 // with this library; see the file COPYING3. If not see
16 // <http://www.gnu.org/licenses/>.
18 // { dg-options "-std=gnu++11 -D_GLIBCXX_DEBUG" }
22 #include <testsuite_iterators.h>
23 #include <testsuite_hooks.h>
25 using __gnu_test::test_container
;
26 using __gnu_test::forward_iterator_wrapper
;
32 bool odd() const { return val
% 2; }
34 // Partitioned so that all odd values come before even values:
35 bool operator<(const X
& x
) const { return this->odd() && !x
.odd(); }
41 bool test
__attribute((unused
)) = true;
43 // Test with range that is partitioned, but not sorted.
44 X seq
[] = { 1, 3, 5, 7, 1, 6, 4, 2 };
45 test_container
<X
, forward_iterator_wrapper
> c(seq
);
47 auto part1
= std::lower_bound(c
.begin(), c
.end(), X
{2});
48 VERIFY( part1
!= c
.end() );
49 VERIFY( part1
->val
== 6 );
50 auto part2
= std::lower_bound(c
.begin(), c
.end(), X
{2}, std::less
<X
>{});
51 VERIFY( part2
!= c
.end() );
52 VERIFY( part2
->val
== 6 );
54 auto part3
= std::lower_bound(c
.begin(), c
.end(), X
{9});
55 VERIFY( part3
!= c
.end() );
56 VERIFY( part3
->val
== 1 );
57 auto part4
= std::lower_bound(c
.begin(), c
.end(), X
{9}, std::less
<X
>{});
58 VERIFY( part4
!= c
.end() );
59 VERIFY( part4
->val
== 1 );
66 // Not irreflexive, so not a strict weak order.
67 bool operator<(const Y
& y
) const { return val
< int(y
.val
); }
73 bool test
__attribute((unused
)) = true;
75 // Test that Debug Mode checks don't fire (libstdc++/71545)
77 Y seq
[] = { -0.1, 1.2, 5.0, 5.2, 5.1, 5.9, 5.5, 6.0 };
78 test_container
<Y
, forward_iterator_wrapper
> c(seq
);
80 auto part1
= std::lower_bound(c
.begin(), c
.end(), Y
{5.5});
81 VERIFY( part1
!= c
.end() );
82 VERIFY( part1
->val
== 5.0 );
83 auto part2
= std::lower_bound(c
.begin(), c
.end(), Y
{5.5}, std::less
<Y
>{});
84 VERIFY( part2
!= c
.end() );
85 VERIFY( part2
->val
== 5.0 );
87 auto part3
= std::lower_bound(c
.begin(), c
.end(), Y
{1.0});
88 VERIFY( part3
!= c
.end() );
89 VERIFY( part3
->val
== 1.2 );
90 auto part4
= std::lower_bound(c
.begin(), c
.end(), Y
{1.0}, std::less
<Y
>{});
91 VERIFY( part4
!= c
.end() );
92 VERIFY( part4
->val
== 1.2 );