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