]>
Commit | Line | Data |
---|---|---|
b2dad0e3 BK |
1 | // 2000-03-29 sss/bkoz |
2 | ||
7ec22717 | 3 | // Copyright (C) 2000, 2003 Free Software Foundation, Inc. |
b2dad0e3 BK |
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 2, 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 COPYING. If not, write to the Free | |
18 | // Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, | |
19 | // USA. | |
20 | ||
21 | #include <algorithm> | |
7ec22717 | 22 | #include <functional> |
fe413112 | 23 | #include <testsuite_hooks.h> |
b2dad0e3 BK |
24 | |
25 | void test01() | |
26 | { | |
11f10e6b | 27 | bool test __attribute__((unused)) = true; |
7ec22717 | 28 | |
b2dad0e3 | 29 | const int& x = std::max(1, 2); |
7ec22717 | 30 | const int& y = std::max(4, 3); |
aa1b2f7d BV |
31 | VERIFY( x == 2 ); |
32 | VERIFY( y == 4 ); | |
b2dad0e3 | 33 | |
7ec22717 NM |
34 | const int& xc = std::max(1, 2, std::greater<int>()); |
35 | const int& yc = std::max(4, 3, std::greater<int>()); | |
36 | VERIFY( xc == 1 ); | |
37 | VERIFY( yc == 3 ); | |
38 | ||
b2dad0e3 | 39 | const int& z = std::min(1, 2); |
7ec22717 | 40 | const int& w = std::min(4, 3); |
aa1b2f7d BV |
41 | VERIFY( z == 1 ); |
42 | VERIFY( w == 3 ); | |
b2dad0e3 | 43 | |
7ec22717 NM |
44 | const int& zc = std::min(1, 2, std::greater<int>()); |
45 | const int& wc = std::min(4, 3, std::greater<int>()); | |
46 | VERIFY( zc == 2 ); | |
47 | VERIFY( wc == 4 ); | |
48 | } | |
49 | ||
50 | template<typename T> | |
51 | struct A { static const T a; }; | |
52 | ||
53 | template<typename T> | |
54 | const T A<T>::a = T(3); | |
55 | ||
d67b7799 BK |
56 | #if !__GXX_WEAK__ |
57 | // Explicitly instantiate for systems with no COMDAT or weak support. | |
58 | template int A<int>::a; | |
59 | template int A<unsigned int>::a; | |
60 | template int A<short>::a; | |
61 | template int A<unsigned short>::a; | |
62 | template int A<long>::a; | |
63 | template int A<unsigned long>::a; | |
64 | template int A<long long>::a; | |
65 | template int A<unsigned long long>::a; | |
66 | template int A<char>::a; | |
67 | template int A<signed char>::a; | |
68 | template int A<unsigned char>::a; | |
69 | template int A<wchar_t>::a; | |
70 | template int A<float>::a; | |
71 | template int A<double>::a; | |
72 | template int A<long double>::a; | |
73 | #endif | |
74 | ||
7ec22717 NM |
75 | void test02() |
76 | { | |
11f10e6b | 77 | bool test __attribute__((unused)) = true; |
7ec22717 NM |
78 | |
79 | VERIFY( 2 == std::min(A<int>::a, 2) ); | |
80 | VERIFY( 3 == std::min(A<int>::a, 4) ); | |
81 | ||
82 | VERIFY( 2u == std::min(A<unsigned int>::a, 2u) ); | |
83 | VERIFY( 3u == std::min(A<unsigned int>::a, 4u) ); | |
84 | ||
85 | VERIFY( 2l == std::min(A<long>::a, 2l) ); | |
86 | VERIFY( 3l == std::min(A<long>::a, 4l) ); | |
87 | ||
88 | VERIFY( 2ul == std::min(A<unsigned long>::a, 2ul) ); | |
89 | VERIFY( 3ul == std::min(A<unsigned long>::a, 4ul) ); | |
90 | ||
3d7c150e | 91 | #ifdef _GLIBCXX_USE_LONG_LONG |
7ec22717 NM |
92 | VERIFY( 2ll == std::min(A<long long>::a, 2ll) ); |
93 | VERIFY( 3ll == std::min(A<long long>::a, 4ll) ); | |
94 | ||
95 | VERIFY( 2ull == std::min(A<unsigned long long>::a, 2ull) ); | |
96 | VERIFY( 3ull == std::min(A<unsigned long long>::a, 4ull) ); | |
b2dad0e3 | 97 | #endif |
7ec22717 NM |
98 | |
99 | VERIFY( short(2) == std::min(A<short>::a, short(2)) ); | |
100 | VERIFY( short(3) == std::min(A<short>::a, short(4)) ); | |
101 | ||
102 | VERIFY( (unsigned short)2 == std::min(A<unsigned short>::a, (unsigned short)2) ); | |
103 | VERIFY( (unsigned short)3 == std::min(A<unsigned short>::a, (unsigned short)4) ); | |
104 | ||
105 | VERIFY( (char)2 == std::min(A<char>::a, (char)2) ); | |
106 | VERIFY( (char)3 == std::min(A<char>::a, (char)4) ); | |
107 | ||
108 | VERIFY( (signed char)2 == std::min(A<signed char>::a, (signed char)2) ); | |
109 | VERIFY( (signed char)3 == std::min(A<signed char>::a, (signed char)4) ); | |
110 | ||
111 | VERIFY( (unsigned char)2 == std::min(A<unsigned char>::a, (unsigned char)2) ); | |
112 | VERIFY( (unsigned char)3 == std::min(A<unsigned char>::a, (unsigned char)4) ); | |
113 | ||
114 | VERIFY( (wchar_t)2 == std::min(A<wchar_t>::a, (wchar_t)2) ); | |
115 | VERIFY( (wchar_t)3 == std::min(A<wchar_t>::a, (wchar_t)4) ); | |
116 | ||
117 | VERIFY( 2.0 == std::min(A<double>::a, 2.0) ); | |
118 | VERIFY( 3.0 == std::min(A<double>::a, 4.0) ); | |
119 | ||
120 | VERIFY( float(2) == std::min(A<float>::a, float(2)) ); | |
121 | VERIFY( float(3) == std::min(A<float>::a, float(4)) ); | |
122 | ||
123 | VERIFY( (long double)2 == std::min(A<long double>::a, (long double)2) ); | |
124 | VERIFY( (long double)3 == std::min(A<long double>::a, (long double)4) ); | |
125 | ||
126 | ||
127 | VERIFY( 3 == std::max(A<int>::a, 2) ); | |
128 | VERIFY( 4 == std::max(A<int>::a, 4) ); | |
129 | ||
130 | VERIFY( 3u == std::max(A<unsigned int>::a, 2u) ); | |
131 | VERIFY( 4u == std::max(A<unsigned int>::a, 4u) ); | |
132 | ||
133 | VERIFY( 3l == std::max(A<long>::a, 2l) ); | |
134 | VERIFY( 4l == std::max(A<long>::a, 4l) ); | |
135 | ||
136 | VERIFY( 3ul == std::max(A<unsigned long>::a, 2ul) ); | |
137 | VERIFY( 4ul == std::max(A<unsigned long>::a, 4ul) ); | |
138 | ||
3d7c150e | 139 | #ifdef _GLIBCXX_USE_LONG_LONG |
7ec22717 NM |
140 | VERIFY( 3ll == std::max(A<long long>::a, 2ll) ); |
141 | VERIFY( 4ll == std::max(A<long long>::a, 4ll) ); | |
142 | ||
143 | VERIFY( 3ull == std::max(A<unsigned long long>::a, 2ull) ); | |
144 | VERIFY( 4ull == std::max(A<unsigned long long>::a, 4ull) ); | |
145 | #endif | |
146 | ||
147 | VERIFY( short(3) == std::max(A<short>::a, short(2)) ); | |
148 | VERIFY( short(4) == std::max(A<short>::a, short(4)) ); | |
149 | ||
150 | VERIFY( (unsigned short)3 == std::max(A<unsigned short>::a, (unsigned short)2) ); | |
151 | VERIFY( (unsigned short)4 == std::max(A<unsigned short>::a, (unsigned short)4) ); | |
152 | ||
153 | VERIFY( (char)3 == std::max(A<char>::a, (char)2) ); | |
154 | VERIFY( (char)4 == std::max(A<char>::a, (char)4) ); | |
155 | ||
156 | VERIFY( (signed char)3 == std::max(A<signed char>::a, (signed char)2) ); | |
157 | VERIFY( (signed char)4 == std::max(A<signed char>::a, (signed char)4) ); | |
158 | ||
159 | VERIFY( (unsigned char)3 == std::max(A<unsigned char>::a, (unsigned char)2) ); | |
160 | VERIFY( (unsigned char)4 == std::max(A<unsigned char>::a, (unsigned char)4) ); | |
161 | ||
162 | VERIFY( (wchar_t)3 == std::max(A<wchar_t>::a, (wchar_t)2) ); | |
163 | VERIFY( (wchar_t)4 == std::max(A<wchar_t>::a, (wchar_t)4) ); | |
b2dad0e3 BK |
164 | } |
165 | ||
166 | int main() | |
167 | { | |
168 | test01(); | |
7ec22717 | 169 | test02(); |
b2dad0e3 BK |
170 | return 0; |
171 | } |