1 //===----------------------------------------------------------------------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 // <algorithm>
11
12 // template<ForwardIterator Iter, class T, CopyConstructible Compare>
13 // requires Predicate<Compare, T, Iter::value_type>
14 // && Predicate<Compare, Iter::value_type, T>
15 // pair<Iter, Iter>
16 // equal_range(Iter first, Iter last, const T& value, Compare comp);
17
18 #include <algorithm>
19 #include <functional>
20 #include <vector>
21 #include <cassert>
22
23 #include "test_iterators.h"
24
25 template <class Iter, class T>
26 void
test(Iter first,Iter last,const T & value)27 test(Iter first, Iter last, const T& value)
28 {
29 std::pair<Iter, Iter> i = std::equal_range(first, last, value, std::greater<int>());
30 for (Iter j = first; j != i.first; ++j)
31 assert(std::greater<int>()(*j, value));
32 for (Iter j = i.first; j != last; ++j)
33 assert(!std::greater<int>()(*j, value));
34 for (Iter j = first; j != i.second; ++j)
35 assert(!std::greater<int>()(value, *j));
36 for (Iter j = i.second; j != last; ++j)
37 assert(std::greater<int>()(value, *j));
38 }
39
40 template <class Iter>
41 void
test()42 test()
43 {
44 const unsigned N = 1000;
45 const unsigned M = 10;
46 std::vector<int> v(N);
47 int x = 0;
48 for (int i = 0; i < v.size(); ++i)
49 {
50 v[i] = x;
51 if (++x == M)
52 x = 0;
53 }
54 std::sort(v.begin(), v.end(), std::greater<int>());
55 for (x = 0; x <= M; ++x)
56 test(Iter(v.data()), Iter(v.data()+v.size()), x);
57 }
58
main()59 int main()
60 {
61 int d[] = {3, 2, 1, 0};
62 for (int* e = d; e <= d+4; ++e)
63 for (int x = -1; x <= 4; ++x)
64 test(d, e, x);
65
66 test<forward_iterator<const int*> >();
67 test<bidirectional_iterator<const int*> >();
68 test<random_access_iterator<const int*> >();
69 test<const int*>();
70 }
71