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 // minmax_element(Iter first, Iter last, Compare comp);
21 #include "test_macros.h"
22 #include "test_iterators.h"
26 test(Iter first, Iter last)
28 typedef std::greater<int> Compare;
30 std::pair<Iter, Iter> p = std::minmax_element(first, last, comp);
33 for (Iter j = first; j != last; ++j)
35 assert(!comp(*j, *p.first));
36 assert(!comp(*p.second, *j));
41 assert(p.first == last);
42 assert(p.second == last);
51 for (int i = 0; i < N; ++i)
53 std::random_shuffle(a, a+N);
54 test(Iter(a), Iter(a+N));
71 for (int i = 0; i < N; ++i)
73 std::random_shuffle(a, a+N);
74 typedef std::greater<int> Compare;
76 std::pair<Iter, Iter> p = std::minmax_element(Iter(a), Iter(a+N), comp);
77 assert(base(p.first) == a);
78 assert(base(p.second) == a+N-1);
83 #if TEST_STD_VER >= 14
84 constexpr int il[] = { 2, 4, 6, 8, 7, 5, 3, 1 };
85 struct less { constexpr bool operator ()( const int &x, const int &y) const { return x < y; }};
90 #if TEST_STD_VER >= 14
91 constexpr auto p = std::minmax_element(il, il+8, less());
92 static_assert ( *(p.first) == 1, "" );
93 static_assert ( *(p.second) == 8, "" );
99 test<forward_iterator<const int*> >();
100 test<bidirectional_iterator<const int*> >();
101 test<random_access_iterator<const int*> >();