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>
13 // requires LessThanComparable<Iter::value_type>
15 // minmax_element(Iter first, Iter last);
21 #include "test_iterators.h"
23 std::mt19937 randomness;
27 test(Iter first, Iter last)
29 std::pair<Iter, Iter> p = std::minmax_element(first, last);
32 for (Iter j = first; j != last; ++j)
34 assert(!(*j < *p.first));
35 assert(!(*p.second < *j));
40 assert(p.first == last);
41 assert(p.second == last);
50 for (int i = 0; i < N; ++i)
52 std::shuffle(a, a+N, randomness);
53 test(Iter(a), Iter(a+N));
70 for (int i = 0; i < N; ++i)
72 std::shuffle(a, a+N, randomness);
73 std::pair<Iter, Iter> p = std::minmax_element(Iter(a), Iter(a+N));
74 assert(base(p.first) == a);
75 assert(base(p.second) == a+N-1);
80 #if TEST_STD_VER >= 14
81 constexpr int il[] = { 2, 4, 6, 8, 7, 5, 3, 1 };
86 #if TEST_STD_VER >= 14
87 constexpr auto p = std::minmax_element(il, il+8);
88 static_assert ( *(p.first) == 1, "" );
89 static_assert ( *(p.second) == 8, "" );
95 test<forward_iterator<const int*> >();
96 test<bidirectional_iterator<const int*> >();
97 test<random_access_iterator<const int*> >();