diff options
author | Yvan Roux <yvan.roux@linaro.org> | 2016-07-11 11:29:39 +0200 |
---|---|---|
committer | Yvan Roux <yvan.roux@linaro.org> | 2016-07-11 11:31:40 +0200 |
commit | 58632c1a76afecc82f34a8c875abfe100a6f1fff (patch) | |
tree | a838c594301dda5059a34ea107e37e1f2c9407e0 /libstdc++-v3/testsuite/25_algorithms/binary_search/partitioned.cc | |
parent | 9a84dc335246b2eb2fd2d7b190b5c2aa6e156df4 (diff) |
Merge branches/gcc-6-branch rev 238201.
Change-Id: Ib44920195c04c4e75202c096d6140ff9e9a7c78b
Diffstat (limited to 'libstdc++-v3/testsuite/25_algorithms/binary_search/partitioned.cc')
-rw-r--r-- | libstdc++-v3/testsuite/25_algorithms/binary_search/partitioned.cc | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/libstdc++-v3/testsuite/25_algorithms/binary_search/partitioned.cc b/libstdc++-v3/testsuite/25_algorithms/binary_search/partitioned.cc new file mode 100644 index 00000000000..63a6cada97e --- /dev/null +++ b/libstdc++-v3/testsuite/25_algorithms/binary_search/partitioned.cc @@ -0,0 +1,67 @@ +// Copyright (C) 2016 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// { dg-options "-std=gnu++11 -D_GLIBCXX_DEBUG" } + +#include <algorithm> +#include <functional> +#include <testsuite_iterators.h> +#include <testsuite_hooks.h> + +using __gnu_test::test_container; +using __gnu_test::forward_iterator_wrapper; + +struct X +{ + int val; + + bool odd() const { return val % 2; } + + // Partitioned so that all odd values come before even values: + bool operator<(const X& x) const { return this->odd() && !x.odd(); } +}; + +void +test01() +{ + bool test __attribute((unused)) = true; + + // Test with range that is partitioned, but not sorted. + X seq[] = { 1, 3, 5, 7, 1, 6, 4 }; + test_container<X, forward_iterator_wrapper> c(seq); + + auto b1 = std::binary_search(c.begin(), c.end(), X{2}); + VERIFY( b1 ); + auto b2 = std::binary_search(c.begin(), c.end(), X{2}, std::less<X>{}); + VERIFY( b2 ); + + auto b3 = std::binary_search(c.begin(), c.end(), X{9}); + VERIFY( b3 ); + auto b4 = std::binary_search(c.begin(), c.end(), X{9}, std::less<X>{}); + VERIFY( b4 ); + + auto b5 = std::binary_search(seq, seq+5, X{2}); + VERIFY( !b5 ); + auto b6 = std::binary_search(seq, seq+5, X{2}, std::less<X>{}); + VERIFY( !b6 ); +} + +int +main() +{ + test01(); +} |