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 // min_element(Iter first, Iter last, Compare comp);
22 #include "test_macros.h"
23 #include "test_iterators.h"
25 std::mt19937 randomness;
29 test(Iter first, Iter last)
31 Iter i = std::min_element(first, last, std::greater<int>());
34 for (Iter j = first; j != last; ++j)
35 assert(!std::greater<int>()(*j, *i));
46 for (int i = 0; i < N; ++i)
48 std::shuffle(a, a+N, randomness);
49 test(Iter(a), Iter(a+N));
65 template <class Iter, class Pred>
66 void test_eq0(Iter first, Iter last, Pred p)
68 assert(first == std::min_element(first, last, p));
75 for (int i = 0; i < N; ++i)
76 a[i] = 10; // all the same
77 test_eq0(a, a+N, std::less<int>());
78 test_eq0(a, a+N, std::greater<int>());
82 #if TEST_STD_VER >= 14
83 constexpr int il[] = { 2, 4, 6, 8, 7, 5, 3, 1 };
84 struct less { constexpr bool operator ()( const int &x, const int &y) const { return x < y; }};
89 #if TEST_STD_VER >= 14
90 constexpr auto p = std::min_element(il, il+8, less());
91 static_assert(*p == 1, "");
97 test<forward_iterator<const int*> >();
98 test<bidirectional_iterator<const int*> >();
99 test<random_access_iterator<const int*> >();