Whole document tree
    

Whole document tree

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

type_traits.h

Go to the documentation of this file.
00001 // Type traits implementation -*- C++ -*-
00002 
00003 // Copyright (C) 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 /*
00031  *
00032  * Copyright (c) 1997
00033  * Silicon Graphics Computer Systems, Inc.
00034  *
00035  * Permission to use, copy, modify, distribute and sell this software
00036  * and its documentation for any purpose is hereby granted without fee,
00037  * provided that the above copyright notice appear in all copies and
00038  * that both that copyright notice and this permission notice appear
00039  * in supporting documentation.  Silicon Graphics makes no
00040  * representations about the suitability of this software for any
00041  * purpose.  It is provided "as is" without express or implied warranty.
00042  */
00043 
00044 #ifndef _CPP_BITS_TYPE_TRAITS_H
00045 #define _CPP_BITS_TYPE_TRAITS_H 1
00046 
00047 #pragma GCC system_header
00048 
00049 #include <bits/c++config.h>
00050 
00051 /*
00052 This header file provides a framework for allowing compile time dispatch
00053 based on type attributes. This is useful when writing template code.
00054 For example, when making a copy of an array of an unknown type, it helps
00055 to know if the type has a trivial copy constructor or not, to help decide
00056 if a memcpy can be used.
00057 
00058 The class template __type_traits provides a series of typedefs each of
00059 which is either __true_type or __false_type. The argument to
00060 __type_traits can be any type. The typedefs within this template will
00061 attain their correct values by one of these means:
00062     1. The general instantiation contain conservative values which work
00063        for all types.
00064     2. Specializations may be declared to make distinctions between types.
00065     3. Some compilers (such as the Silicon Graphics N32 and N64 compilers)
00066        will automatically provide the appropriate specializations for all
00067        types.
00068 
00069 EXAMPLE:
00070 
00071 //Copy an array of elements which have non-trivial copy constructors
00072 template <class _Tp> void 
00073   copy(_Tp* __source,_Tp* __destination,int __n,__false_type);
00074 //Copy an array of elements which have trivial copy constructors. Use memcpy.
00075 template <class _Tp> void 
00076   copy(_Tp* __source,_Tp* __destination,int __n,__true_type);
00077 
00078 //Copy an array of any type by using the most efficient copy mechanism
00079 template <class _Tp> inline void copy(_Tp* __source,_Tp* __destination,int __n) {
00080    copy(__source,__destination,__n,
00081         typename __type_traits<_Tp>::has_trivial_copy_constructor());
00082 }
00083 */
00084 
00085 
00086 template <bool _Truth> struct _Bool {};
00087 typedef _Bool<true>  __true_type;
00088 typedef _Bool<false> __false_type;
00089 
00090 template <class _Tp>
00091 struct __type_traits { 
00092    typedef __true_type     this_dummy_member_must_be_first;
00093                    /* Do not remove this member. It informs a compiler which
00094                       automatically specializes __type_traits that this
00095                       __type_traits template is special. It just makes sure that
00096                       things work if an implementation is using a template
00097                       called __type_traits for something unrelated. */
00098 
00099    /* The following restrictions should be observed for the sake of
00100       compilers which automatically produce type specific specializations 
00101       of this class:
00102           - You may reorder the members below if you wish
00103           - You may remove any of the members below if you wish
00104           - You must not rename members without making the corresponding
00105             name change in the compiler
00106           - Members you add will be treated like regular members unless
00107             you add the appropriate support in the compiler. */
00108  
00109 
00110    typedef __false_type    has_trivial_default_constructor;
00111    typedef __false_type    has_trivial_copy_constructor;
00112    typedef __false_type    has_trivial_assignment_operator;
00113    typedef __false_type    has_trivial_destructor;
00114    typedef __false_type    is_POD_type;
00115 };
00116 
00117 
00118 // Provide some specializations.
00119 
00120 template<> struct __type_traits<bool> {
00121    typedef __true_type    has_trivial_default_constructor;
00122    typedef __true_type    has_trivial_copy_constructor;
00123    typedef __true_type    has_trivial_assignment_operator;
00124    typedef __true_type    has_trivial_destructor;
00125    typedef __true_type    is_POD_type;
00126 };
00127 
00128 template<> struct __type_traits<char> {
00129    typedef __true_type    has_trivial_default_constructor;
00130    typedef __true_type    has_trivial_copy_constructor;
00131    typedef __true_type    has_trivial_assignment_operator;
00132    typedef __true_type    has_trivial_destructor;
00133    typedef __true_type    is_POD_type;
00134 };
00135 
00136 template<> struct __type_traits<signed char> {
00137    typedef __true_type    has_trivial_default_constructor;
00138    typedef __true_type    has_trivial_copy_constructor;
00139    typedef __true_type    has_trivial_assignment_operator;
00140    typedef __true_type    has_trivial_destructor;
00141    typedef __true_type    is_POD_type;
00142 };
00143 
00144 template<> struct __type_traits<unsigned char> {
00145    typedef __true_type    has_trivial_default_constructor;
00146    typedef __true_type    has_trivial_copy_constructor;
00147    typedef __true_type    has_trivial_assignment_operator;
00148    typedef __true_type    has_trivial_destructor;
00149    typedef __true_type    is_POD_type;
00150 };
00151 
00152 template<> struct __type_traits<wchar_t> {
00153    typedef __true_type    has_trivial_default_constructor;
00154    typedef __true_type    has_trivial_copy_constructor;
00155    typedef __true_type    has_trivial_assignment_operator;
00156    typedef __true_type    has_trivial_destructor;
00157    typedef __true_type    is_POD_type;
00158 };
00159 
00160 template<> struct __type_traits<short> {
00161    typedef __true_type    has_trivial_default_constructor;
00162    typedef __true_type    has_trivial_copy_constructor;
00163    typedef __true_type    has_trivial_assignment_operator;
00164    typedef __true_type    has_trivial_destructor;
00165    typedef __true_type    is_POD_type;
00166 };
00167 
00168 template<> struct __type_traits<unsigned short> {
00169    typedef __true_type    has_trivial_default_constructor;
00170    typedef __true_type    has_trivial_copy_constructor;
00171    typedef __true_type    has_trivial_assignment_operator;
00172    typedef __true_type    has_trivial_destructor;
00173    typedef __true_type    is_POD_type;
00174 };
00175 
00176 template<> struct __type_traits<int> {
00177    typedef __true_type    has_trivial_default_constructor;
00178    typedef __true_type    has_trivial_copy_constructor;
00179    typedef __true_type    has_trivial_assignment_operator;
00180    typedef __true_type    has_trivial_destructor;
00181    typedef __true_type    is_POD_type;
00182 };
00183 
00184 template<> struct __type_traits<unsigned int> {
00185    typedef __true_type    has_trivial_default_constructor;
00186    typedef __true_type    has_trivial_copy_constructor;
00187    typedef __true_type    has_trivial_assignment_operator;
00188    typedef __true_type    has_trivial_destructor;
00189    typedef __true_type    is_POD_type;
00190 };
00191 
00192 template<> struct __type_traits<long> {
00193    typedef __true_type    has_trivial_default_constructor;
00194    typedef __true_type    has_trivial_copy_constructor;
00195    typedef __true_type    has_trivial_assignment_operator;
00196    typedef __true_type    has_trivial_destructor;
00197    typedef __true_type    is_POD_type;
00198 };
00199 
00200 template<> struct __type_traits<unsigned long> {
00201    typedef __true_type    has_trivial_default_constructor;
00202    typedef __true_type    has_trivial_copy_constructor;
00203    typedef __true_type    has_trivial_assignment_operator;
00204    typedef __true_type    has_trivial_destructor;
00205    typedef __true_type    is_POD_type;
00206 };
00207 
00208 template<> struct __type_traits<long long> {
00209    typedef __true_type    has_trivial_default_constructor;
00210    typedef __true_type    has_trivial_copy_constructor;
00211    typedef __true_type    has_trivial_assignment_operator;
00212    typedef __true_type    has_trivial_destructor;
00213    typedef __true_type    is_POD_type;
00214 };
00215 
00216 template<> struct __type_traits<unsigned long long> {
00217    typedef __true_type    has_trivial_default_constructor;
00218    typedef __true_type    has_trivial_copy_constructor;
00219    typedef __true_type    has_trivial_assignment_operator;
00220    typedef __true_type    has_trivial_destructor;
00221    typedef __true_type    is_POD_type;
00222 };
00223 
00224 template<> struct __type_traits<float> {
00225    typedef __true_type    has_trivial_default_constructor;
00226    typedef __true_type    has_trivial_copy_constructor;
00227    typedef __true_type    has_trivial_assignment_operator;
00228    typedef __true_type    has_trivial_destructor;
00229    typedef __true_type    is_POD_type;
00230 };
00231 
00232 template<> struct __type_traits<double> {
00233    typedef __true_type    has_trivial_default_constructor;
00234    typedef __true_type    has_trivial_copy_constructor;
00235    typedef __true_type    has_trivial_assignment_operator;
00236    typedef __true_type    has_trivial_destructor;
00237    typedef __true_type    is_POD_type;
00238 };
00239 
00240 template<> struct __type_traits<long double> {
00241    typedef __true_type    has_trivial_default_constructor;
00242    typedef __true_type    has_trivial_copy_constructor;
00243    typedef __true_type    has_trivial_assignment_operator;
00244    typedef __true_type    has_trivial_destructor;
00245    typedef __true_type    is_POD_type;
00246 };
00247 
00248 template <class _Tp>
00249 struct __type_traits<_Tp*> {
00250    typedef __true_type    has_trivial_default_constructor;
00251    typedef __true_type    has_trivial_copy_constructor;
00252    typedef __true_type    has_trivial_assignment_operator;
00253    typedef __true_type    has_trivial_destructor;
00254    typedef __true_type    is_POD_type;
00255 };
00256 
00257 
00258 // The following could be written in terms of numeric_limits.  
00259 // We're doing it separately to reduce the number of dependencies.
00260 
00261 template <class _Tp> struct _Is_integer {
00262   typedef __false_type _Integral;
00263 };
00264 
00265 template<> struct _Is_integer<bool> {
00266   typedef __true_type _Integral;
00267 };
00268 
00269 template<> struct _Is_integer<char> {
00270   typedef __true_type _Integral;
00271 };
00272 
00273 template<> struct _Is_integer<signed char> {
00274   typedef __true_type _Integral;
00275 };
00276 
00277 template<> struct _Is_integer<unsigned char> {
00278   typedef __true_type _Integral;
00279 };
00280 
00281 template<> struct _Is_integer<wchar_t> {
00282   typedef __true_type _Integral;
00283 };
00284 
00285 template<> struct _Is_integer<short> {
00286   typedef __true_type _Integral;
00287 };
00288 
00289 template<> struct _Is_integer<unsigned short> {
00290   typedef __true_type _Integral;
00291 };
00292 
00293 template<> struct _Is_integer<int> {
00294   typedef __true_type _Integral;
00295 };
00296 
00297 template<> struct _Is_integer<unsigned int> {
00298   typedef __true_type _Integral;
00299 };
00300 
00301 template<> struct _Is_integer<long> {
00302   typedef __true_type _Integral;
00303 };
00304 
00305 template<> struct _Is_integer<unsigned long> {
00306   typedef __true_type _Integral;
00307 };
00308 
00309 template<> struct _Is_integer<long long> {
00310   typedef __true_type _Integral;
00311 };
00312 
00313 template<> struct _Is_integer<unsigned long long> {
00314   typedef __true_type _Integral;
00315 };
00316 
00317 template<typename _Tp> struct _Is_normal_iterator {
00318    typedef __false_type _Normal;
00319 };
00320 
00321 // Forward declaration hack, should really include this from somewhere.
00322 namespace std {
00323    template<typename _Iterator, typename _Container> class __normal_iterator;
00324 };
00325 
00326 template<typename _Iterator, typename _Container>
00327 struct _Is_normal_iterator< std::__normal_iterator<_Iterator, _Container> > {
00328    typedef __true_type _Normal;
00329 };
00330 
00331 #endif /* _CPP_BITS_TYPE_TRAITS_H */
00332 
00333 // Local Variables:
00334 // mode:C++
00335 // End:

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