1 // Copyright (C) 2001-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 // 25.3.3 [lib.alg.binary.search] Binary search algorithms.
21 #include <testsuite_hooks.h>
23 const int A
[] = {1, 2, 3, 3, 3, 5, 8};
24 const int C
[] = {8, 5, 3, 3, 3, 2, 1};
25 const int N
= sizeof(A
) / sizeof(int);
27 // A comparison, equalivalent to std::greater<int> without the
28 // dependency on <functional>.
32 operator()(const int& x
, const int& y
) const
36 // Each test performs general-case, bookend, not-found condition,
37 // and predicate functional checks.
39 // 25.3.3.1 lower_bound, with and without comparison predicate
43 using std::lower_bound
;
45 const int first
= A
[0];
46 const int last
= A
[N
- 1];
48 const int* p
= lower_bound(A
, A
+ N
, 3);
51 const int* q
= lower_bound(A
, A
+ N
, first
);
54 const int* r
= lower_bound(A
, A
+ N
, last
);
55 VERIFY(r
== A
+ N
- 1);
57 const int* s
= lower_bound(A
, A
+ N
, 4);
60 const int* t
= lower_bound(C
, C
+ N
, 3, gt());
63 const int* u
= lower_bound(C
, C
+ N
, first
, gt());
64 VERIFY(u
== C
+ N
- 1);
66 const int* v
= lower_bound(C
, C
+ N
, last
, gt());
69 const int* w
= lower_bound(C
, C
+ N
, 4, gt());