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 //   min_element(Iter first, Iter last);
16 
17 #include <algorithm>
18 #include <cassert>
19 
20 #include "test_iterators.h"
21 
22 template <class Iter>
23 void
test(Iter first,Iter last)24 test(Iter first, Iter last)
25 {
26     Iter i = std::min_element(first, last);
27     if (first != last)
28     {
29         for (Iter j = first; j != last; ++j)
30             assert(!(*j < *i));
31     }
32     else
33         assert(i == last);
34 }
35 
36 template <class Iter>
37 void
test(unsigned N)38 test(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 
48 template <class Iter>
49 void
test()50 test()
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 
main()60 int 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