00001 // -*- C++ -*- 00002 00003 // Copyright (C) 2005, 2006, 2007 Free Software Foundation, Inc. 00004 // 00005 // This file is part of the GNU ISO C++ Library. This library is free 00006 // software; you can redistribute it and/or modify it under the terms 00007 // of the GNU General Public License as published by the Free Software 00008 // Foundation; either version 2, or (at your option) any later 00009 // version. 00010 00011 // This library is distributed in the hope that it will be useful, but 00012 // WITHOUT ANY WARRANTY; without even the implied warranty of 00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00014 // General Public License for more details. 00015 00016 // You should have received a copy of the GNU General Public License along 00017 // with this library; see the file COPYING. If not, write to the Free 00018 // Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 00019 // USA. 00020 00021 // As a special exception, you may use this file as part of a free 00022 // software library without restriction. Specifically, if other files 00023 // instantiate templates or use macros or inline functions from this 00024 // file, or you compile this file and link it with other files to 00025 // produce an executable, this file does not by itself cause the 00026 // resulting executable to be covered by the GNU General Public 00027 // License. This exception does not however invalidate any other 00028 // reasons why the executable file might be covered by the GNU General 00029 // Public License. 00030 00031 /** @file ext/type_traits.h 00032 * This file is a GNU extension to the Standard C++ Library. 00033 */ 00034 00035 #ifndef _EXT_TYPE_TRAITS 00036 #define _EXT_TYPE_TRAITS 1 00037 00038 #pragma GCC system_header 00039 00040 #include <cstddef> 00041 #include <utility> 00042 #include <bits/cpp_type_traits.h> 00043 00044 _GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx) 00045 00046 // Define a nested type if some predicate holds. 00047 template<bool, typename> 00048 struct __enable_if 00049 { }; 00050 00051 template<typename _Tp> 00052 struct __enable_if<true, _Tp> 00053 { typedef _Tp __type; }; 00054 00055 00056 // Conditional expression for types. If true, first, if false, second. 00057 template<bool _Cond, typename _Iftrue, typename _Iffalse> 00058 struct __conditional_type 00059 { typedef _Iftrue __type; }; 00060 00061 template<typename _Iftrue, typename _Iffalse> 00062 struct __conditional_type<false, _Iftrue, _Iffalse> 00063 { typedef _Iffalse __type; }; 00064 00065 00066 // Given an integral builtin type, return the corresponding unsigned type. 00067 template<typename _Tp> 00068 struct __add_unsigned 00069 { 00070 private: 00071 typedef __enable_if<std::__is_integer<_Tp>::__value, _Tp> __if_type; 00072 00073 public: 00074 typedef typename __if_type::__type __type; 00075 }; 00076 00077 template<> 00078 struct __add_unsigned<char> 00079 { typedef unsigned char __type; }; 00080 00081 template<> 00082 struct __add_unsigned<signed char> 00083 { typedef unsigned char __type; }; 00084 00085 template<> 00086 struct __add_unsigned<short> 00087 { typedef unsigned short __type; }; 00088 00089 template<> 00090 struct __add_unsigned<int> 00091 { typedef unsigned int __type; }; 00092 00093 template<> 00094 struct __add_unsigned<long> 00095 { typedef unsigned long __type; }; 00096 00097 template<> 00098 struct __add_unsigned<long long> 00099 { typedef unsigned long long __type; }; 00100 00101 // Declare but don't define. 00102 template<> 00103 struct __add_unsigned<bool>; 00104 00105 template<> 00106 struct __add_unsigned<wchar_t>; 00107 00108 00109 // Given an integral builtin type, return the corresponding signed type. 00110 template<typename _Tp> 00111 struct __remove_unsigned 00112 { 00113 private: 00114 typedef __enable_if<std::__is_integer<_Tp>::__value, _Tp> __if_type; 00115 00116 public: 00117 typedef typename __if_type::__type __type; 00118 }; 00119 00120 template<> 00121 struct __remove_unsigned<char> 00122 { typedef signed char __type; }; 00123 00124 template<> 00125 struct __remove_unsigned<unsigned char> 00126 { typedef signed char __type; }; 00127 00128 template<> 00129 struct __remove_unsigned<unsigned short> 00130 { typedef short __type; }; 00131 00132 template<> 00133 struct __remove_unsigned<unsigned int> 00134 { typedef int __type; }; 00135 00136 template<> 00137 struct __remove_unsigned<unsigned long> 00138 { typedef long __type; }; 00139 00140 template<> 00141 struct __remove_unsigned<unsigned long long> 00142 { typedef long long __type; }; 00143 00144 // Declare but don't define. 00145 template<> 00146 struct __remove_unsigned<bool>; 00147 00148 template<> 00149 struct __remove_unsigned<wchar_t>; 00150 00151 _GLIBCXX_END_NAMESPACE 00152 00153 #endif