1 // { dg-options "-std=gnu++0x" }
2 
3 // Copyright (C) 2007-2013 Free Software Foundation, Inc.
4 //
5 // This file is part of the GNU ISO C++ Library.  This library is free
6 // software; you can redistribute it and/or modify it under the
7 // terms of the GNU General Public License as published by the
8 // Free Software Foundation; either version 3, or (at your option)
9 // any later version.
10 
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 // GNU General Public License for more details.
15 
16 // You should have received a copy of the GNU General Public License along
17 // with this library; see the file COPYING3.  If not see
18 // <http://www.gnu.org/licenses/>.
19 
20 #include <algorithm>
21 #include <testsuite_iterators.h>
22 #include <testsuite_hooks.h>
23 
24 using __gnu_test::test_container;
25 using __gnu_test::forward_iterator_wrapper;
26 using std::minmax_element;
27 
28 typedef test_container<int, forward_iterator_wrapper> Container;
29 typedef std::pair<forward_iterator_wrapper<int>, forward_iterator_wrapper<int> > pair_type;
30 
31 void
test1()32 test1()
33 {
34   bool test __attribute__((unused)) = true;
35 
36   int array[] = {0};
37   Container con(array, array);
38   pair_type p1 = minmax_element(con.begin(), con.end());
39   VERIFY( p1.first.ptr == array );
40   VERIFY( p1.second.ptr == array );
41 }
42 
43 void
test2()44 test2()
45 {
46   bool test __attribute__((unused)) = true;
47 
48   int array[] = {0};
49   Container con(array, array + 1);
50   pair_type p1 = minmax_element(con.begin(), con.end());
51   VERIFY( p1.first.ptr == array );
52   VERIFY( p1.second.ptr == array );
53 }
54 
55 void
test3()56 test3()
57 {
58   bool test __attribute__((unused)) = true;
59 
60   int array[] = {0, 3};
61   Container con(array, array + 2);
62   pair_type p1 = minmax_element(con.begin(), con.end());
63   VERIFY( p1.first.ptr == array );
64   VERIFY( p1.second.ptr == array + 1 );
65 }
66 
67 void
test4()68 test4()
69 {
70   bool test __attribute__((unused)) = true;
71 
72   int array[] = {3, 0};
73   Container con(array, array + 2);
74   pair_type p1 = minmax_element(con.begin(), con.end());
75   VERIFY( p1.first.ptr == array + 1 );
76   VERIFY( p1.second.ptr == array );
77 }
78 
79 void
test5()80 test5()
81 {
82   bool test __attribute__((unused)) = true;
83 
84   int array[] = {3, 3};
85   Container con(array, array + 2);
86   pair_type p1 = minmax_element(con.begin(), con.end());
87   VERIFY( p1.first.ptr == array );
88   VERIFY( p1.second.ptr == array + 1 );
89 }
90 
91 void
test6()92 test6()
93 {
94   bool test __attribute__((unused)) = true;
95 
96   int array[] = {6, 3, 0, 2, 6, 4, 0};
97   Container con(array, array + 7);
98   pair_type p1 = minmax_element(con.begin(), con.end());
99   VERIFY( p1.first.ptr == array + 2 );
100   VERIFY( p1.second.ptr == array + 4 );
101 }
102 
103 void
test7()104 test7()
105 {
106   bool test __attribute__((unused)) = true;
107 
108   int array[] = {4, 4, 4, 6, 6, 6, 1, 1, 0, 0, 0, 2, 2};
109   Container con(array, array + 13);
110   pair_type p1 = minmax_element(con.begin(), con.end());
111   VERIFY( p1.first.ptr == array + 8 );
112   VERIFY( p1.second.ptr == array + 5 );
113 }
114 
115 void
test8()116 test8()
117 {
118   bool test __attribute__((unused)) = true;
119 
120   int array[] = {1, 7, 5, 5, 10, 1, 0, 0, 8, 4, 4, 0, 10, 10, 10, 1};
121   Container con(array, array + 16);
122   pair_type p1 = minmax_element(con.begin(), con.end());
123   VERIFY( p1.first.ptr == array + 6 );
124   VERIFY( p1.second.ptr == array + 14 );
125 }
126 
main()127 int main()
128 {
129   test1();
130   test2();
131   test3();
132   test4();
133   test5();
134   test6();
135   test7();
136   test8();
137   return 0;
138 }
139