]>
git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/25_algorithms/binary_search/partitioned.cc
1 // Copyright (C) 2016-2019 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 "-D_GLIBCXX_DEBUG" }
19 // { dg-do run { target c++11 } }
20 // { dg-skip-if "" { *-*-* } { "-D_GLIBCXX_PROFILE" } }
24 #include <testsuite_iterators.h>
25 #include <testsuite_hooks.h>
27 using __gnu_test::test_container
;
28 using __gnu_test::forward_iterator_wrapper
;
34 bool odd() const { return val
% 2; }
36 // Partitioned so that all odd values come before even values:
37 bool operator<(const X
& x
) const { return this->odd() && !x
.odd(); }
43 // Test with range that is partitioned, but not sorted.
44 X seq
[] = { 1, 3, 5, 7, 1, 6, 4 };
45 test_container
<X
, forward_iterator_wrapper
> c(seq
);
47 auto b1
= std::binary_search(c
.begin(), c
.end(), X
{2});
49 auto b2
= std::binary_search(c
.begin(), c
.end(), X
{2}, std::less
<X
>{});
52 auto b3
= std::binary_search(c
.begin(), c
.end(), X
{9});
54 auto b4
= std::binary_search(c
.begin(), c
.end(), X
{9}, std::less
<X
>{});
57 auto b5
= std::binary_search(seq
, seq
+5, X
{2});
59 auto b6
= std::binary_search(seq
, seq
+5, X
{2}, std::less
<X
>{});