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

Generated at Tue May 1 16:28:40 2001 for libstdc++-v3 by doxygen1.2.6 written by Dimitri van Heesch, © 1997-2001