Douglas Gregor | c8ab256 | 2009-05-31 09:31:02 +0000 | [diff] [blame] | 1 | // RUN: clang-cc -fsyntax-only -verify %s |
| 2 | template<typename T> |
| 3 | struct is_pointer { |
| 4 | static const bool value = false; |
| 5 | }; |
| 6 | |
| 7 | template<typename T> |
| 8 | struct is_pointer<T*> { |
| 9 | static const bool value = true; |
| 10 | }; |
| 11 | |
| 12 | template<typename T> |
| 13 | struct is_pointer<const T*> { |
| 14 | static const bool value = true; |
| 15 | }; |
| 16 | |
| 17 | int array0[is_pointer<int>::value? -1 : 1]; |
| 18 | int array1[is_pointer<int*>::value? 1 : -1]; |
| 19 | int array2[is_pointer<const int*>::value? 1 : -1]; // expected-error{{partial ordering}} \ |
| 20 | // expected-error{{negative}} |
Douglas Gregor | 0b9247f | 2009-06-04 00:03:07 +0000 | [diff] [blame] | 21 | |
Douglas Gregor | d560d50 | 2009-06-04 00:21:18 +0000 | [diff] [blame] | 22 | template<typename T> |
| 23 | struct is_lvalue_reference { |
| 24 | static const bool value = false; |
| 25 | }; |
| 26 | |
| 27 | template<typename T> |
| 28 | struct is_lvalue_reference<T&> { |
| 29 | static const bool value = true; |
| 30 | }; |
| 31 | |
| 32 | int lvalue_ref0[is_lvalue_reference<int>::value? -1 : 1]; |
| 33 | int lvalue_ref1[is_lvalue_reference<const int&>::value? 1 : -1]; |
| 34 | |
Douglas Gregor | 0b9247f | 2009-06-04 00:03:07 +0000 | [diff] [blame] | 35 | template<typename T, typename U> |
| 36 | struct is_same { |
| 37 | static const bool value = false; |
| 38 | }; |
| 39 | |
| 40 | template<typename T> |
| 41 | struct is_same<T, T> { |
| 42 | static const bool value = true; |
| 43 | }; |
| 44 | |
| 45 | typedef int INT; |
| 46 | typedef INT* int_ptr; |
| 47 | |
| 48 | int is_same0[is_same<int, int>::value? 1 : -1]; |
| 49 | int is_same1[is_same<int, INT>::value? 1 : -1]; |
| 50 | int is_same2[is_same<const int, int>::value? -1 : 1]; |
| 51 | int is_same3[is_same<int_ptr, int>::value? -1 : 1]; |
Anders Carlsson | 4d6fb50 | 2009-06-04 04:11:30 +0000 | [diff] [blame] | 52 | |
| 53 | template<typename T> |
Douglas Gregor | 199d991 | 2009-06-05 00:53:49 +0000 | [diff] [blame] | 54 | struct remove_reference { |
| 55 | typedef T type; |
| 56 | }; |
| 57 | |
| 58 | template<typename T> |
| 59 | struct remove_reference<T&> { |
| 60 | typedef T type; |
| 61 | }; |
| 62 | |
| 63 | int remove_ref0[is_same<remove_reference<int>::type, int>::value? 1 : -1]; |
| 64 | int remove_ref1[is_same<remove_reference<int&>::type, int>::value? 1 : -1]; |
| 65 | |
| 66 | template<typename T> |
Anders Carlsson | 4d6fb50 | 2009-06-04 04:11:30 +0000 | [diff] [blame] | 67 | struct is_incomplete_array { |
| 68 | static const bool value = false; |
| 69 | }; |
| 70 | |
| 71 | template<typename T> |
| 72 | struct is_incomplete_array<T[]> { |
| 73 | static const bool value = true; |
| 74 | }; |
| 75 | |
| 76 | int incomplete_array0[is_incomplete_array<int>::value ? -1 : 1]; |
| 77 | int incomplete_array1[is_incomplete_array<int[1]>::value ? -1 : 1]; |
| 78 | int incomplete_array2[is_incomplete_array<bool[]>::value ? 1 : -1]; |
| 79 | int incomplete_array3[is_incomplete_array<int[]>::value ? 1 : -1]; |
| 80 | |
| 81 | template<typename T> |
| 82 | struct is_array_with_4_elements { |
| 83 | static const bool value = false; |
| 84 | }; |
| 85 | |
| 86 | template<typename T> |
| 87 | struct is_array_with_4_elements<T[4]> { |
| 88 | static const bool value = true; |
| 89 | }; |
| 90 | |
| 91 | int array_with_4_elements0[is_array_with_4_elements<int[]>::value ? -1 : 1]; |
| 92 | int array_with_4_elements1[is_array_with_4_elements<int[1]>::value ? -1 : 1]; |
| 93 | int array_with_4_elements2[is_array_with_4_elements<int[4]>::value ? 1 : -1]; |
| 94 | int array_with_4_elements3[is_array_with_4_elements<int[4][2]>::value ? 1 : -1]; |
Douglas Gregor | 199d991 | 2009-06-05 00:53:49 +0000 | [diff] [blame] | 95 | |
| 96 | template<typename T> |
| 97 | struct get_array_size; |
| 98 | |
| 99 | template<typename T, unsigned N> |
| 100 | struct get_array_size<T[N]> { |
| 101 | static const unsigned value = N; |
| 102 | }; |
| 103 | |
| 104 | int array_size0[get_array_size<int[12]>::value == 12? 1 : -1]; |
Anders Carlsson | a27fad5 | 2009-06-08 15:19:08 +0000 | [diff] [blame] | 105 | |
| 106 | template<typename T> |
| 107 | struct is_unary_function { |
| 108 | static const bool value = false; |
| 109 | }; |
| 110 | |
| 111 | template<typename T, typename U> |
| 112 | struct is_unary_function<T (*)(U)> { |
| 113 | static const bool value = true; |
| 114 | }; |
| 115 | |
| 116 | int is_unary_function0[is_unary_function<int>::value ? -1 : 1]; |
| 117 | int is_unary_function1[is_unary_function<int (*)()>::value ? -1 : 1]; |
| 118 | int is_unary_function2[is_unary_function<int (*)(int, bool)>::value ? -1 : 1]; |
| 119 | int is_unary_function3[is_unary_function<int (*)(bool)>::value ? 1 : -1]; |
| 120 | int is_unary_function4[is_unary_function<int (*)(int)>::value ? 1 : -1]; |
| 121 | |
| 122 | template<typename T> |
| 123 | struct is_unary_function_with_same_return_type_as_argument_type { |
| 124 | static const bool value = false; |
| 125 | }; |
| 126 | |
| 127 | template<typename T> |
| 128 | struct is_unary_function_with_same_return_type_as_argument_type<T (*)(T)> { |
| 129 | static const bool value = true; |
| 130 | }; |
| 131 | |
| 132 | int is_unary_function5[is_unary_function_with_same_return_type_as_argument_type<int>::value ? -1 : 1]; |
| 133 | int is_unary_function6[is_unary_function_with_same_return_type_as_argument_type<int (*)()>::value ? -1 : 1]; |
| 134 | int is_unary_function7[is_unary_function_with_same_return_type_as_argument_type<int (*)(int, bool)>::value ? -1 : 1]; |
| 135 | int is_unary_function8[is_unary_function_with_same_return_type_as_argument_type<int (*)(bool)>::value ? -1 : 1]; |
| 136 | int is_unary_function9[is_unary_function_with_same_return_type_as_argument_type<int (*)(int)>::value ? 1 : -1]; |
Anders Carlsson | 994b6cb | 2009-06-08 19:22:23 +0000 | [diff] [blame] | 137 | int is_unary_function10[is_unary_function_with_same_return_type_as_argument_type<int (*)(int, ...)>::value ? -1 : 1]; |
| 138 | int is_unary_function11[is_unary_function_with_same_return_type_as_argument_type<int (* const)(int)>::value ? -1 : 1]; |
Douglas Gregor | 1fe067a | 2009-06-08 16:04:08 +0000 | [diff] [blame] | 139 | |
| 140 | template<typename T> |
| 141 | struct is_binary_function { |
| 142 | static const bool value = false; |
| 143 | }; |
| 144 | |
| 145 | template<typename R, typename T1, typename T2> |
| 146 | struct is_binary_function<R(T1, T2)> { |
| 147 | static const bool value = true; |
| 148 | }; |
| 149 | |
| 150 | int is_binary_function0[is_binary_function<int(float, double)>::value? 1 : -1]; |
Douglas Gregor | 949bf69 | 2009-06-09 22:17:39 +0000 | [diff] [blame] | 151 | |
| 152 | template<typename T> |
| 153 | struct is_member_pointer { |
| 154 | static const bool value = false; |
| 155 | }; |
| 156 | |
| 157 | template<typename T, typename Class> |
| 158 | struct is_member_pointer<T Class::*> { |
| 159 | static const bool value = true; |
| 160 | }; |
Douglas Gregor | 637a409 | 2009-06-10 23:47:09 +0000 | [diff] [blame] | 161 | |
| 162 | struct X { }; |
| 163 | |
| 164 | int is_member_pointer0[is_member_pointer<int X::*>::value? 1 : -1]; |
| 165 | int is_member_pointer1[is_member_pointer<const int X::*>::value? 1 : -1]; |
| 166 | int is_member_pointer2[is_member_pointer<int (X::*)()>::value? 1 : -1]; |
| 167 | int is_member_pointer3[is_member_pointer<int (X::*)(int) const>::value? 1 : -1]; |
| 168 | int is_member_pointer4[is_member_pointer<int (X::**)(int) const>::value? -1 : 1]; |
| 169 | int is_member_pointer5[is_member_pointer<int>::value? -1 : 1]; |
| 170 | |
| 171 | template<typename T> |
| 172 | struct is_member_function_pointer { |
| 173 | static const bool value = false; |
| 174 | }; |
| 175 | |
| 176 | template<typename T, typename Class> |
| 177 | struct is_member_function_pointer<T (Class::*)()> { |
| 178 | static const bool value = true; |
| 179 | }; |
| 180 | |
| 181 | template<typename T, typename Class> |
| 182 | struct is_member_function_pointer<T (Class::*)() const> { |
| 183 | static const bool value = true; |
| 184 | }; |
| 185 | |
| 186 | template<typename T, typename Class> |
| 187 | struct is_member_function_pointer<T (Class::*)() volatile> { |
| 188 | static const bool value = true; |
| 189 | }; |
| 190 | |
| 191 | template<typename T, typename Class> |
| 192 | struct is_member_function_pointer<T (Class::*)() const volatile> { |
| 193 | static const bool value = true; |
| 194 | }; |
| 195 | |
| 196 | template<typename T, typename Class, typename A1> |
| 197 | struct is_member_function_pointer<T (Class::*)(A1)> { |
| 198 | static const bool value = true; |
| 199 | }; |
| 200 | |
| 201 | template<typename T, typename Class, typename A1> |
| 202 | struct is_member_function_pointer<T (Class::*)(A1) const> { |
| 203 | static const bool value = true; |
| 204 | }; |
| 205 | |
| 206 | template<typename T, typename Class, typename A1> |
| 207 | struct is_member_function_pointer<T (Class::*)(A1) volatile> { |
| 208 | static const bool value = true; |
| 209 | }; |
| 210 | |
| 211 | template<typename T, typename Class, typename A1> |
| 212 | struct is_member_function_pointer<T (Class::*)(A1) const volatile> { |
| 213 | static const bool value = true; |
| 214 | }; |
| 215 | |
| 216 | int is_member_function_pointer0[ |
| 217 | is_member_function_pointer<int X::*>::value? -1 : 1]; |
| 218 | int is_member_function_pointer1[ |
| 219 | is_member_function_pointer<int (X::*)()>::value? 1 : -1]; |
| 220 | int is_member_function_pointer2[ |
| 221 | is_member_function_pointer<X (X::*)(X&)>::value? 1 : -1]; |
| 222 | int is_member_function_pointer3[ |
| 223 | is_member_function_pointer<int (X::*)() const>::value? 1 : -1]; |
| 224 | int is_member_function_pointer4[ |
| 225 | is_member_function_pointer<int (X::*)(float) const>::value? 1 : -1]; |
| 226 | |
Douglas Gregor | 02cbbd2 | 2009-06-11 18:10:32 +0000 | [diff] [blame] | 227 | // Test substitution of non-dependent arguments back into the template |
| 228 | // argument list of the class template partial specialization. |
Douglas Gregor | 637a409 | 2009-06-10 23:47:09 +0000 | [diff] [blame] | 229 | template<typename T, typename ValueType = T> |
| 230 | struct is_nested_value_type_identity { |
| 231 | static const bool value = false; |
| 232 | }; |
| 233 | |
| 234 | template<typename T> |
| 235 | struct is_nested_value_type_identity<T, typename T::value_type> { |
| 236 | static const bool value = true; |
| 237 | }; |
| 238 | |
| 239 | template<typename T> |
| 240 | struct HasValueType { |
| 241 | typedef T value_type; |
| 242 | }; |
| 243 | |
| 244 | struct HasIdentityValueType { |
| 245 | typedef HasIdentityValueType value_type; |
| 246 | }; |
| 247 | |
| 248 | struct NoValueType { }; |
| 249 | |
Douglas Gregor | 02cbbd2 | 2009-06-11 18:10:32 +0000 | [diff] [blame] | 250 | int is_nested_value_type_identity0[ |
| 251 | is_nested_value_type_identity<HasValueType<int> >::value? -1 : 1]; |
Douglas Gregor | 637a409 | 2009-06-10 23:47:09 +0000 | [diff] [blame] | 252 | int is_nested_value_type_identity1[ |
| 253 | is_nested_value_type_identity<HasIdentityValueType>::value? 1 : -1]; |
| 254 | // FIXME: Enable when we have SFINAE support |
Douglas Gregor | 02cbbd2 | 2009-06-11 18:10:32 +0000 | [diff] [blame] | 255 | //int is_nested_value_type_identity2[ |
Douglas Gregor | 637a409 | 2009-06-10 23:47:09 +0000 | [diff] [blame] | 256 | // is_nested_value_type_identity<NoValueType>::value? -1 : 1]; |
Douglas Gregor | 02cbbd2 | 2009-06-11 18:10:32 +0000 | [diff] [blame] | 257 | |
Douglas Gregor | 16df850 | 2009-06-12 22:21:45 +0000 | [diff] [blame^] | 258 | |
| 259 | // C++ [temp.class.spec]p4: |
| 260 | template<class T1, class T2, int I> class A { }; //#1 |
| 261 | template<class T, int I> class A<T, T*, I> { }; //#2 |
| 262 | template<class T1, class T2, int I> class A<T1*, T2, I> { }; //#3 |
| 263 | template<class T> class A<int, T*, 5> { }; //#4 |
| 264 | template<class T1, class T2, int I> class A<T1, T2*, I> { }; //#5 |