Whole document tree
    

Whole document tree

cpp_type_traits.h Source File
Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members  

cpp_type_traits.h

Go to the documentation of this file.
00001 // The  -*- C++ -*- type traits classes for internal use in libstdc++
00002 
00003 // Copyright (C) 2000-2001 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
00007 // terms of the GNU General Public License as published by the
00008 // Free Software Foundation; either version 2, or (at your option)
00009 // any later version.
00010 
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014 // GNU 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, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
00019 // USA.
00020 
00021 // As a special exception, you may use this file as part of a free software
00022 // library without restriction.  Specifically, if other files instantiate
00023 // templates or use macros or inline functions from this file, or you compile
00024 // this file and link it with other files to produce an executable, this
00025 // file does not by itself cause the resulting executable to be covered by
00026 // the GNU General Public License.  This exception does not however
00027 // invalidate any other reasons why the executable file might be covered by
00028 // the GNU General Public License.
00029 
00030 // Written by Gabriel Dos Reis <dosreis@cmla.ens-cachan.fr>
00031 
00032 #ifndef _CPP_BITS_CPP_TYPE_TRAITS_H
00033 #define _CPP_BITS_CPP_TYPE_TRAITS_H 1
00034 
00035 #pragma GCC system_header
00036 
00037 //
00038 // This file provides some compile-time information about various types.
00039 // These representations were designed, on purpose, to be constant-expressions
00040 // and not types as found in <stl/bits/type_traits.h>.  In particular, they
00041 // can be used in control structures and the optimizer hopefully will do
00042 // the obvious thing.
00043 //
00044 // Why integral expressions, and not functions nor types?
00045 // Firstly, these compile-time entities are used as template-arguments
00046 // so function return values won't work:  We need compile-time entities.
00047 // We're left with types and constant  integral expressions.
00048 // Secondly, from the point of view of ease of use, type-based compile-time
00049 // information is -not- *that* convenient.  On has to write lots of
00050 // overloaded functions and to hope that the compiler will select the right
00051 // one. As a net effect, the overall structure isn't very clear at first
00052 // glance.
00053 // Thirdly, partial ordering and overload resolution (of function templates)
00054 // is highly costly in terms of compiler-resource.  It is a Good Thing to
00055 // keep these resource consumption as least as possible.
00056 //
00057 // See valarray_array.h for a case use.
00058 //
00059 // -- Gaby (dosreis@cmla.ens-cachan.fr) 2000-03-06.
00060 //
00061 
00062 namespace std
00063 {
00064   template<typename _Tp>
00065     struct __is_void
00066     {
00067       enum
00068       {
00069         _M_type = 0
00070       };
00071     };
00072 
00073   template<>
00074     struct __is_void<void>
00075     {
00076       enum
00077       {
00078         _M_type = 1
00079       };
00080     };
00081 
00082   //
00083   // Integer types
00084   //
00085   template<typename _Tp>
00086     struct __is_integer
00087     {
00088       enum
00089       {
00090     _M_type = 0
00091       };
00092     };
00093 
00094   // Thirteen specializations (yes there are eleven standard integer
00095   // types; 'long long' and 'unsigned long long' are supported as
00096   // extensions)
00097   template<>
00098     struct __is_integer<bool>
00099     {
00100       enum
00101       {
00102     _M_type = 1
00103       };
00104     };
00105   
00106   template<>
00107     struct __is_integer<char>
00108     {
00109       enum
00110       {
00111     _M_type = 1
00112       };
00113     };
00114 
00115   template<>
00116     struct __is_integer<signed char>
00117     {
00118       enum
00119       {
00120     _M_type = 1
00121       };
00122     };
00123   
00124   template<>
00125   struct __is_integer<unsigned char>
00126   {
00127     enum
00128     {
00129       _M_type = 1
00130     };
00131   };
00132 
00133 # ifdef _GLIBCPP_USE_WCHAR_T
00134   template<>
00135   struct __is_integer<wchar_t>
00136   {
00137     enum
00138     {
00139       _M_type = 1
00140     };
00141   };
00142 # endif
00143   
00144   template<>
00145   struct __is_integer<short>
00146   {
00147     enum
00148     {
00149       _M_type = 1
00150     };
00151   };
00152 
00153   template<>
00154   struct __is_integer<unsigned short>
00155   {
00156     enum
00157     {
00158       _M_type = 1
00159     };
00160   };
00161 
00162   template<>
00163   struct __is_integer<int>
00164   {
00165     enum
00166     {
00167       _M_type = 1
00168     };
00169   };
00170 
00171   template<>
00172   struct __is_integer<unsigned int>
00173   {
00174     enum
00175     {
00176       _M_type = 1
00177     };
00178   };
00179 
00180   template<>
00181   struct __is_integer<long>
00182   {
00183     enum
00184     {
00185       _M_type = 1
00186     };
00187   };
00188 
00189   template<>
00190   struct __is_integer<unsigned long>
00191   {
00192     enum
00193     {
00194       _M_type = 1
00195     };
00196   };
00197 
00198   template<>
00199   struct __is_integer<long long>
00200   {
00201     enum
00202     {
00203       _M_type = 1
00204     };
00205   };
00206 
00207   template<>
00208   struct __is_integer<unsigned long long>
00209   {
00210     enum
00211     {
00212       _M_type = 1
00213     };
00214   };
00215 
00216   //
00217   // Floating point types
00218   //
00219   template<typename _Tp>
00220   struct __is_floating
00221   {
00222     enum
00223     {
00224       _M_type = 0
00225     };
00226   };
00227 
00228   // three specializations (float, double and 'long double')
00229   template<>
00230   struct __is_floating<float>
00231   {
00232     enum
00233     {
00234       _M_type = 1
00235     };
00236   };
00237 
00238   template<>
00239   struct __is_floating<double>
00240   {
00241     enum
00242     {
00243       _M_type = 1
00244     };
00245   };
00246 
00247   template<>
00248   struct __is_floating<long double>
00249   {
00250     enum
00251     {
00252       _M_type = 1
00253     };
00254   };
00255 
00256   //
00257   // An arithmetic type is an integer type or a floating point type
00258   //
00259   template<typename _Tp>
00260   struct __is_arithmetic
00261   {
00262     enum
00263     {
00264       _M_type = __is_integer<_Tp>::_M_type || __is_floating<_Tp>::_M_type
00265     };
00266   };
00267 
00268   //
00269   // A fundamental type is `void' or and arithmetic type
00270   //
00271   template<typename _Tp>
00272   struct __is_fundamental
00273   {
00274     enum
00275     {
00276       _M_type = __is_void<_Tp>::_M_type || __is_arithmetic<_Tp>::_M_type
00277     };
00278   };
00279 
00280   //
00281   // For the immediate use, the following is a good approximation
00282   //
00283   template<typename _Tp>
00284   struct __is_pod
00285   {
00286     enum
00287     {
00288       _M_type = __is_fundamental<_Tp>::_M_type
00289     };
00290   };
00291 
00292 } // namespace std
00293 
00294 
00295 #endif //_CPP_BITS_CPP_TYPE_TRAITS_H

Generated on Mon Apr 8 03:11:24 2002 for libstdc++-v3 Source by doxygen1.2.15