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, StrictWeakOrder<auto, Iter::value_type> Compare>
13 // requires CopyConstructible<Compare>
15 // max_element(Iter first, Iter last, Compare comp);
21 #include "test_iterators.h"
25 test(Iter first, Iter last)
27 Iter i = std::max_element(first, last, std::greater<int>());
30 for (Iter j = first; j != last; ++j)
31 assert(!std::greater<int>()(*i, *j));
42 for (int i = 0; i < N; ++i)
44 std::random_shuffle(a, a+N);
45 test(Iter(a), Iter(a+N));
61 template <class Iter, class Pred>
62 void test_eq0(Iter first, Iter last, Pred p)
64 assert(first == std::max_element(first, last, p));
71 for (int i = 0; i < N; ++i)
72 a[i] = 10; // all the same
73 test_eq0(a, a+N, std::less<int>());
74 test_eq0(a, a+N, std::greater<int>());
80 test<forward_iterator<const int*> >();
81 test<bidirectional_iterator<const int*> >();
82 test<random_access_iterator<const int*> >();