Dead
[official-gcc.git] / gomp-20050608-branch / libstdc++-v3 / include / ext / pb_assoc / detail / type_utils.hpp
blob6c6a4e5c72b66839117763179950844a30a6eeb0
1 // -*- C++ -*-
3 // Copyright (C) 2005 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 2, or (at your option)
9 // any later version.
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.
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, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
19 // USA.
21 // As a special exception, you may use this file as part of a free software
22 // library without restriction. Specifically, if other files instantiate
23 // templates or use macros or inline functions from this file, or you compile
24 // this file and link it with other files to produce an executable, this
25 // file does not by itself cause the resulting executable to be covered by
26 // the GNU General Public License. This exception does not however
27 // invalidate any other reasons why the executable file might be covered by
28 // the GNU General Public License.
30 // Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL.
32 // Permission to use, copy, modify, sell, and distribute this software
33 // is hereby granted without fee, provided that the above copyright
34 // notice appears in all copies, and that both that copyright notice and
35 // this permission notice appear in supporting documentation. None of
36 // the above authors, nor IBM Haifa Research Laboratories, make any
37 // representation about the suitability of this software for any
38 // purpose. It is provided "as is" without express or implied warranty.
40 /**
41 * @file type_utils.hpp
42 * Contains utilities for handnling types. All of these classes are based on
43 * "Modern C++" by Andrei Alxandrescu.
46 #ifndef TYPE_UTILS_HPP
47 #define TYPE_UTILS_HPP
49 #include <cstddef>
50 #include <utility>
52 namespace pb_assoc
55 namespace detail
58 template<bool>
59 struct static_assert;
61 template<>
62 struct static_assert<true>
63 { };
65 template<int>
66 struct static_assert_dummy_class
68 enum
70 v = 1
74 template<class T, class U>
75 class is_same_type
77 public:
78 enum
80 value = false
84 template<class T>
85 class is_same_type<
89 public:
90 enum
92 value = true
96 template<int n>
97 struct int_to_type
99 enum
101 value = n
105 template<typename Type>
106 struct type_to_type
108 typedef Type type;
111 template<typename T>
112 class unconst
114 private:
115 template<class U>
116 struct unconst_imp
118 typedef U type;
121 template<class U>
122 struct unconst_imp<
123 const U>
125 typedef U type;
127 public:
128 typedef typename unconst_imp<T>::type type;
131 template<typename T>
132 class unreference
134 private:
135 template<class U>
136 struct unreference_imp
138 typedef U type;
141 template<class U>
142 struct unreference_imp<U&>
144 typedef U type;
146 public:
147 typedef typename unreference_imp<T>::type type;
150 /* is_const_type
151 * Idea by Andrei Alecsandrescu
152 * (Modern C++ Design: Generic Programming and Design Patterns Applied)
154 template<typename T>
155 class is_const_type
157 private:
158 template<class U>
159 struct is_const_type_imp
161 enum
163 value = 0
167 template<class U>
168 struct is_const_type_imp<const U>
170 enum
172 value = 1
176 public:
177 enum
179 value = is_const_type_imp<T>::value
183 /* is_pointer_type
185 template<typename T>
186 class is_pointer_type
188 private:
189 template<class U>
190 struct is_pointer_type_imp
192 enum
194 value = 0
198 template<class U>
199 struct is_pointer_type_imp
200 <U* >
202 enum
204 value = 1
208 public:
209 enum
211 value = is_pointer_type_imp<T>::value
215 /* is_pointer_type
217 template<typename T>
218 class is_const_pointer_type
220 private:
221 template<class U>
222 struct is_const_pointer_type_imp
224 enum
226 value = 0
230 template<class U>
231 struct is_const_pointer_type_imp
232 <const U* >
234 enum
236 value = 1
240 public:
241 enum
243 value = is_const_pointer_type_imp<T>::value
247 template<typename T>
248 class is_reference_type
250 private:
251 template<class U>
252 struct is_reference_type_imp
254 enum
256 value = 0
260 template<class U>
261 struct is_reference_type_imp<U& >
263 enum
265 value = 1
269 public:
270 enum
272 value = is_reference_type_imp<T>::value
276 template<typename T>
277 class is_const_reference_type
279 private:
280 template<class U>
281 struct is_const_reference_type_imp
283 enum
285 value = 0
289 template<class U>
290 struct is_const_reference_type_imp<U& >
292 enum
294 value = 1
298 public:
299 enum
301 value = is_const_reference_type_imp<T>::value
305 template<typename T>
306 class is_member_pointer_type
308 private:
309 template<typename U>
310 struct is_member_pointer_type_imp
312 enum
314 value = 0
318 template<typename U, typename V>
319 struct is_member_pointer_type_imp<
320 U V::*>
322 enum
324 value = 1
328 public:
329 enum
331 value = is_member_pointer_type_imp<T>::value
335 #define PB_ASSOC_IS_SAME_TYPE(TYPE) is_same_type<T, TYPE>::value
337 template<class T>
338 class is_simple_type
340 template<class U>
341 struct is_simple_type_imp
343 enum
345 value = 0
349 template<class U, size_t M>
350 struct is_simple_type_imp<
351 U[M]>
353 enum
355 value = is_simple_type<U>::value
359 template<class U>
360 struct is_simple_type_imp<
361 U[]>
363 enum
365 value = is_simple_type<U>::value
369 template<typename T0, typename T1>
370 struct is_simple_type_imp<
371 std::pair<
373 T1> >
375 enum
377 value = is_simple_type<T0>::value&&
378 is_simple_type<T1>::value
382 public:
383 enum
385 value =
386 PB_ASSOC_IS_SAME_TYPE(void) ||
387 PB_ASSOC_IS_SAME_TYPE(size_t) ||
388 PB_ASSOC_IS_SAME_TYPE(const void) ||
389 PB_ASSOC_IS_SAME_TYPE(unsigned char) ||
390 PB_ASSOC_IS_SAME_TYPE(unsigned short int) ||
391 PB_ASSOC_IS_SAME_TYPE(unsigned int) ||
392 PB_ASSOC_IS_SAME_TYPE(unsigned long int) ||
393 PB_ASSOC_IS_SAME_TYPE(signed char) ||
394 PB_ASSOC_IS_SAME_TYPE(signed short int) ||
395 PB_ASSOC_IS_SAME_TYPE(int) ||
396 PB_ASSOC_IS_SAME_TYPE(long int) ||
397 PB_ASSOC_IS_SAME_TYPE(bool) ||
398 PB_ASSOC_IS_SAME_TYPE(char) ||
399 PB_ASSOC_IS_SAME_TYPE(float) ||
400 PB_ASSOC_IS_SAME_TYPE(double) ||
401 PB_ASSOC_IS_SAME_TYPE(long double) ||
402 PB_ASSOC_IS_SAME_TYPE(const unsigned char) ||
403 PB_ASSOC_IS_SAME_TYPE(const unsigned short int) ||
404 PB_ASSOC_IS_SAME_TYPE(const unsigned int) ||
405 PB_ASSOC_IS_SAME_TYPE(const unsigned long int) ||
406 PB_ASSOC_IS_SAME_TYPE(const signed char) ||
407 PB_ASSOC_IS_SAME_TYPE(const signed short int) ||
408 PB_ASSOC_IS_SAME_TYPE(const int) ||
409 PB_ASSOC_IS_SAME_TYPE(const long int) ||
410 PB_ASSOC_IS_SAME_TYPE(const bool) ||
411 PB_ASSOC_IS_SAME_TYPE(const char) ||
412 PB_ASSOC_IS_SAME_TYPE(const float) ||
413 PB_ASSOC_IS_SAME_TYPE(const double) ||
414 PB_ASSOC_IS_SAME_TYPE(const long double) ||
415 is_pointer_type<T>::value ||
416 is_const_pointer_type<T>::value ||
417 is_member_pointer_type<T>::value ||
418 is_simple_type_imp<T>::value
422 #undef PB_ASSOC_IS_SAME_TYPE
424 template<bool Cond, class A, class B>
425 struct cond_type;
427 template<class A, class B>
428 struct cond_type<
429 true,
433 typedef A type;
436 template<class A, class B>
437 struct cond_type<
438 false,
442 typedef B type;
445 } // namespace detail
447 } // namespace pb_assoc
449 #endif // #ifndef TYPE_UTILS_HPP