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, StrictWeakOrder<auto, Iter::value_type> Compare>
13//   requires CopyConstructible<Compare>
14//   Iter
15//   max_element(Iter first, Iter last, Compare comp);
16
17#include <algorithm>
18#include <functional>
19#include <cassert>
20
21#include "test_iterators.h"
22
23template <class Iter>
24void
25test(Iter first, Iter last)
26{
27    Iter i = std::max_element(first, last, std::greater<int>());
28    if (first != last)
29    {
30        for (Iter j = first; j != last; ++j)
31            assert(!std::greater<int>()(*i, *j));
32    }
33    else
34        assert(i == last);
35}
36
37template <class Iter>
38void
39test(unsigned N)
40{
41    int* a = new int[N];
42    for (int i = 0; i < N; ++i)
43        a[i] = i;
44    std::random_shuffle(a, a+N);
45    test(Iter(a), Iter(a+N));
46    delete [] a;
47}
48
49template <class Iter>
50void
51test()
52{
53    test<Iter>(0);
54    test<Iter>(1);
55    test<Iter>(2);
56    test<Iter>(3);
57    test<Iter>(10);
58    test<Iter>(1000);
59}
60
61int main()
62{
63    test<forward_iterator<const int*> >();
64    test<bidirectional_iterator<const int*> >();
65    test<random_access_iterator<const int*> >();
66    test<const int*>();
67}
68