1 //===----------------------------------------------------------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
12 // template<ForwardIterator Iter, class T, CopyConstructible Compare>
13 // requires Predicate<Compare, T, Iter::value_type>
14 // && Predicate<Compare, Iter::value_type, T>
16 // binary_search(Iter first, Iter last, const T& value, Compare comp);
24 #include "test_iterators.h"
26 template <class Iter, class T>
28 test(Iter first, Iter last, const T& value, bool x)
30 assert(std::binary_search(first, last, value, std::greater<int>()) == x);
37 const unsigned N = 1000;
39 std::vector<int> v(N);
41 for (std::size_t i = 0; i < v.size(); ++i)
47 std::sort(v.begin(), v.end(), std::greater<int>());
48 for (x = 0; x < M; ++x)
49 test(Iter(v.data()), Iter(v.data()+v.size()), x, true);
50 test(Iter(v.data()), Iter(v.data()+v.size()), -1, false);
51 test(Iter(v.data()), Iter(v.data()+v.size()), M, false);
56 int d[] = {6, 4, 2, 0};
57 for (int* e = d; e <= d+4; ++e)
58 for (int x = -1; x <= 7; ++x)
59 test(d, e, x, (x % 2 == 0) && e != d && (-2*(e-d) + 8 <= x));
61 test<forward_iterator<const int*> >();
62 test<bidirectional_iterator<const int*> >();
63 test<random_access_iterator<const int*> >();