3 // Copyright (C) 2005 Free Software Foundation, Inc.
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)
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, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
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.
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
62 struct static_assert<true>
66 struct static_assert_dummy_class
74 template<class T, class U>
105 template<typename Type>
128 typedef typename unconst_imp<T>::type type;
136 struct unreference_imp
142 struct unreference_imp<U&>
147 typedef typename unreference_imp<T>::type type;
151 * Idea by Andrei Alecsandrescu
152 * (Modern C++ Design: Generic Programming and Design Patterns Applied)
159 struct is_const_type_imp
168 struct is_const_type_imp<const U>
179 value = is_const_type_imp<T>::value
186 class is_pointer_type
190 struct is_pointer_type_imp
199 struct is_pointer_type_imp
211 value = is_pointer_type_imp<T>::value
218 class is_const_pointer_type
222 struct is_const_pointer_type_imp
231 struct is_const_pointer_type_imp
243 value = is_const_pointer_type_imp<T>::value
248 class is_reference_type
252 struct is_reference_type_imp
261 struct is_reference_type_imp<U& >
272 value = is_reference_type_imp<T>::value
277 class is_const_reference_type
281 struct is_const_reference_type_imp
290 struct is_const_reference_type_imp<U& >
301 value = is_const_reference_type_imp<T>::value
306 class is_member_pointer_type
310 struct is_member_pointer_type_imp
318 template<typename U, typename V>
319 struct is_member_pointer_type_imp<
331 value = is_member_pointer_type_imp<T>::value
335 #define PB_ASSOC_IS_SAME_TYPE(TYPE) is_same_type<T, TYPE>::value
341 struct is_simple_type_imp
349 template<class U, size_t M>
350 struct is_simple_type_imp<
355 value = is_simple_type<U>::value
360 struct is_simple_type_imp<
365 value = is_simple_type<U>::value
369 template<typename T0, typename T1>
370 struct is_simple_type_imp<
377 value = is_simple_type<T0>::value&&
378 is_simple_type<T1>::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>
427 template<class A, class B>
436 template<class A, class B>
445 } // namespace detail
447 } // namespace pb_assoc
449 #endif // #ifndef TYPE_UTILS_HPP