00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef _STLP_TYPE_TRAITS_H
00024 #define _STLP_TYPE_TRAITS_H
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058 #ifdef __WATCOMC__
00059 # include <cwchar>
00060 #endif
00061
00062 _STLP_BEGIN_NAMESPACE
00063
00064 struct __true_type {};
00065 struct __false_type {};
00066
00067
00068 template <int _Is> struct __bool2type { };
00069
00070 _STLP_TEMPLATE_NULL
00071 struct __bool2type<1> { typedef __true_type _Ret; };
00072
00073 _STLP_TEMPLATE_NULL
00074 struct __bool2type<0> { typedef __false_type _Ret; };
00075
00076
00077 template <class _P1, class _P2, class _P3>
00078 struct _Land3 {
00079 typedef __false_type _Ret;
00080 };
00081
00082 _STLP_TEMPLATE_NULL
00083 struct _Land3<__true_type, __true_type, __true_type> {
00084 typedef __true_type _Ret;
00085 };
00086
00087
00088
00089 template <class _Tp> struct __type_traits;
00090 template <int _IsPOD> struct __type_traits_aux {
00091 typedef __false_type has_trivial_default_constructor;
00092 typedef __false_type has_trivial_copy_constructor;
00093 typedef __false_type has_trivial_assignment_operator;
00094 typedef __false_type has_trivial_destructor;
00095 typedef __false_type is_POD_type;
00096 };
00097
00098 _STLP_TEMPLATE_NULL
00099 struct __type_traits_aux<0> {
00100 typedef __false_type has_trivial_default_constructor;
00101 typedef __false_type has_trivial_copy_constructor;
00102 typedef __false_type has_trivial_assignment_operator;
00103 typedef __false_type has_trivial_destructor;
00104 typedef __false_type is_POD_type;
00105 };
00106
00107 _STLP_TEMPLATE_NULL
00108 struct __type_traits_aux<1> {
00109 typedef __true_type has_trivial_default_constructor;
00110 typedef __true_type has_trivial_copy_constructor;
00111 typedef __true_type has_trivial_assignment_operator;
00112 typedef __true_type has_trivial_destructor;
00113 typedef __true_type is_POD_type;
00114 };
00115
00116 # ifdef _STLP_SIMULATE_PARTIAL_SPEC_FOR_TYPE_TRAITS
00117
00118
00119
00120
00121
00122
00123
00124 struct _PointerShim {
00125
00126
00127
00128
00129 _PointerShim(const volatile void*);
00130 };
00131
00132
00133
00134 char _STLP_CALL _IsP(bool, _PointerShim);
00135 char* _STLP_CALL _IsP(bool, ...);
00136
00137 template <class _Tp>
00138 struct _IsPtr {
00139
00140
00141
00142
00143
00144 static _Tp& __null_rep();
00145 enum { _Ret = (sizeof(_IsP(false,__null_rep())) == sizeof(char)) };
00146
00147 };
00148
00149 template <class _Tp>
00150 struct _IsPtrType {
00151 enum { _Is = _IsPtr<_Tp>::_Ret } ;
00152 typedef __bool2type< _Is > _BT;
00153 typedef typename _BT::_Ret _Type;
00154 static _Type _Ret() { return _Type(); }
00155 };
00156
00157 template <class _Tp1, class _Tp2>
00158 struct _BothPtrType {
00159 typedef __bool2type< _IsPtr<_Tp1>::_Ret> _B1;
00160 typedef __bool2type< _IsPtr<_Tp2>::_Ret> _B2;
00161 typedef typename _B1::_Ret _Type1;
00162 typedef typename _B2::_Ret _Type2;
00163 typedef typename _Land3<_Type1, _Type2, __true_type>::_Ret _Type;
00164 static _Type _Ret() { return _Type(); }
00165 };
00166
00167
00168
00169 template <class _Tp>
00170 struct __type_traits : __type_traits_aux<_IsPtr<_Tp>::_Ret> {};
00171
00172 # else
00173
00174 template <class _Tp>
00175 struct __type_traits {
00176 typedef __true_type this_dummy_member_must_be_first;
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192 typedef __false_type has_trivial_default_constructor;
00193 typedef __false_type has_trivial_copy_constructor;
00194 typedef __false_type has_trivial_assignment_operator;
00195 typedef __false_type has_trivial_destructor;
00196 typedef __false_type is_POD_type;
00197 };
00198
00199
00200 template <class _Tp> struct _IsPtr { enum { _Ret = 0 }; };
00201 template <class _Tp> struct _IsPtrType {
00202 static __false_type _Ret() { return __false_type();}
00203 };
00204 template <class _Tp1, class _Tp2> struct _BothPtrType {
00205 static __false_type _Ret() { return __false_type();}
00206 };
00207
00208 # ifdef _STLP_CLASS_PARTIAL_SPECIALIZATION
00209 template <class _Tp> struct _IsPtr<_Tp*> { enum { _Ret = 1 }; };
00210 template <class _Tp> struct _IsPtrType<_Tp*> {
00211 static __true_type _Ret() { return __true_type();}
00212 };
00213 template <class _Tp1, class _Tp2> struct _BothPtrType<_Tp1*, _Tp2*> {
00214 static __true_type _Ret() { return __true_type();}
00215 };
00216 # endif
00217
00218 # endif
00219
00220
00221
00222
00223 #ifndef _STLP_NO_BOOL
00224 _STLP_TEMPLATE_NULL struct __type_traits<bool> : __type_traits_aux<1> {};
00225 #endif
00226 _STLP_TEMPLATE_NULL struct __type_traits<char> : __type_traits_aux<1> {};
00227 #ifndef _STLP_NO_SIGNED_BUILTINS
00228 _STLP_TEMPLATE_NULL struct __type_traits<signed char> : __type_traits_aux<1> {};
00229 # endif
00230 _STLP_TEMPLATE_NULL struct __type_traits<unsigned char> : __type_traits_aux<1> {};
00231 #if defined ( _STLP_HAS_WCHAR_T ) && ! defined (_STLP_WCHAR_T_IS_USHORT)
00232 _STLP_TEMPLATE_NULL struct __type_traits<wchar_t> : __type_traits_aux<1> {};
00233 #endif
00234
00235 _STLP_TEMPLATE_NULL struct __type_traits<short> : __type_traits_aux<1> {};
00236 _STLP_TEMPLATE_NULL struct __type_traits<unsigned short> : __type_traits_aux<1> {};
00237 _STLP_TEMPLATE_NULL struct __type_traits<int> : __type_traits_aux<1> {};
00238 _STLP_TEMPLATE_NULL struct __type_traits<unsigned int> : __type_traits_aux<1> {};
00239 _STLP_TEMPLATE_NULL struct __type_traits<long> : __type_traits_aux<1> {};
00240 _STLP_TEMPLATE_NULL struct __type_traits<unsigned long> : __type_traits_aux<1> {};
00241
00242 #ifdef _STLP_LONG_LONG
00243 _STLP_TEMPLATE_NULL struct __type_traits<_STLP_LONG_LONG> : __type_traits_aux<1> {};
00244 _STLP_TEMPLATE_NULL struct __type_traits<unsigned _STLP_LONG_LONG> : __type_traits_aux<1> {};
00245 #endif
00246
00247 _STLP_TEMPLATE_NULL struct __type_traits<float> : __type_traits_aux<1> {};
00248 _STLP_TEMPLATE_NULL struct __type_traits<double> : __type_traits_aux<1> {};
00249
00250 # if !defined ( _STLP_NO_LONG_DOUBLE )
00251 _STLP_TEMPLATE_NULL struct __type_traits<long double> : __type_traits_aux<1> {};
00252 # endif
00253
00254 #ifdef _STLP_CLASS_PARTIAL_SPECIALIZATION
00255 template <class _Tp> struct __type_traits<_Tp*> : __type_traits_aux<1> {};
00256 #endif
00257
00258
00259
00260
00261 template <class _Tp> struct _Is_integer {
00262 typedef __false_type _Integral;
00263 };
00264
00265 #ifndef _STLP_NO_BOOL
00266
00267 _STLP_TEMPLATE_NULL struct _Is_integer<bool> {
00268 typedef __true_type _Integral;
00269 };
00270
00271 #endif
00272
00273 _STLP_TEMPLATE_NULL struct _Is_integer<char> {
00274 typedef __true_type _Integral;
00275 };
00276
00277 #ifndef _STLP_NO_SIGNED_BUILTINS
00278
00279 _STLP_TEMPLATE_NULL struct _Is_integer<signed char> {
00280 typedef __true_type _Integral;
00281 };
00282 #endif
00283
00284 _STLP_TEMPLATE_NULL struct _Is_integer<unsigned char> {
00285 typedef __true_type _Integral;
00286 };
00287
00288 #if defined ( _STLP_HAS_WCHAR_T ) && ! defined (_STLP_WCHAR_T_IS_USHORT)
00289
00290 _STLP_TEMPLATE_NULL struct _Is_integer<wchar_t> {
00291 typedef __true_type _Integral;
00292 };
00293
00294 #endif
00295
00296 _STLP_TEMPLATE_NULL struct _Is_integer<short> {
00297 typedef __true_type _Integral;
00298 };
00299
00300 _STLP_TEMPLATE_NULL struct _Is_integer<unsigned short> {
00301 typedef __true_type _Integral;
00302 };
00303
00304 _STLP_TEMPLATE_NULL struct _Is_integer<int> {
00305 typedef __true_type _Integral;
00306 };
00307
00308 _STLP_TEMPLATE_NULL struct _Is_integer<unsigned int> {
00309 typedef __true_type _Integral;
00310 };
00311
00312 _STLP_TEMPLATE_NULL struct _Is_integer<long> {
00313 typedef __true_type _Integral;
00314 };
00315
00316 _STLP_TEMPLATE_NULL struct _Is_integer<unsigned long> {
00317 typedef __true_type _Integral;
00318 };
00319
00320 #ifdef _STLP_LONG_LONG
00321
00322 _STLP_TEMPLATE_NULL struct _Is_integer<_STLP_LONG_LONG> {
00323 typedef __true_type _Integral;
00324 };
00325
00326 _STLP_TEMPLATE_NULL struct _Is_integer<unsigned _STLP_LONG_LONG> {
00327 typedef __true_type _Integral;
00328 };
00329
00330 #endif
00331
00332 template <class _Tp1, class _Tp2>
00333 struct _OKToMemCpy {
00334 enum { _SameSize = (sizeof(_Tp1) == sizeof(_Tp2)) } ;
00335 typedef typename __type_traits<_Tp1>::has_trivial_assignment_operator _Tr1;
00336 typedef typename __type_traits<_Tp2>::has_trivial_assignment_operator _Tr2;
00337 typedef typename __bool2type< _SameSize >::_Ret _Tr3;
00338 typedef typename _Land3<_Tr1, _Tr2, _Tr3>::_Ret _Type;
00339 static _Type _Ret() { return _Type(); }
00340 };
00341
00342 template <class _Tp1, class _Tp2>
00343 inline _OKToMemCpy<_Tp1, _Tp2> _IsOKToMemCpy(_Tp1*, _Tp2*) {
00344 return _OKToMemCpy<_Tp1, _Tp2>();
00345 }
00346
00347 template <class _Tp>
00348 struct _IsPOD {
00349 typedef typename __type_traits<_Tp>::is_POD_type _Type;
00350 static _Type _Ret() { return _Type(); }
00351 };
00352
00353 template <class _Tp>
00354 inline _IsPOD<_Tp> _Is_POD (_Tp*) { return _IsPOD<_Tp>(); }
00355
00356 # ifdef _STLP_CLASS_PARTIAL_SPECIALIZATION
00357 # if defined (__BORLANDC__) || defined (__SUNPRO_CC) || ( defined (__MWERKS__) && (__MWERKS__ <= 0x2303)) || ( defined (__sgi) && defined (_COMPILER_VERSION))
00358 # define _IS_POD_ITER(_It, _Tp) __type_traits< typename iterator_traits< _Tp >::value_type >::is_POD_type()
00359 # else
00360 # define _IS_POD_ITER(_It, _Tp) typename __type_traits< typename iterator_traits< _Tp >::value_type >::is_POD_type()
00361 # endif
00362 # else
00363 # define _IS_POD_ITER(_It, _Tp) _Is_POD( _STLP_VALUE_TYPE( _It, _Tp ) )._Ret()
00364 # endif
00365
00366 # ifdef _STLP_DEFAULT_CONSTRUCTOR_BUG
00367
00368
00369 template <class _Tp>
00370 inline _Tp __default_constructed_aux(_Tp*, const __false_type&) {
00371 return _Tp();
00372 }
00373 template <class _Tp>
00374 inline _Tp __default_constructed_aux(_Tp*, const __true_type&) {
00375 return _Tp(0);
00376 }
00377
00378 template <class _Tp>
00379 inline _Tp __default_constructed(_Tp* __p) {
00380 typedef typename _Is_integer<_Tp>::_Integral _Is_Integral;
00381 return __default_constructed_aux(__p, _Is_Integral());
00382 }
00383
00384 # define _STLP_DEFAULT_CONSTRUCTED(_TTp) __default_constructed((_TTp*)0)
00385 # else
00386 # define _STLP_DEFAULT_CONSTRUCTED(_TTp) _TTp()
00387 # endif
00388
00389 _STLP_END_NAMESPACE
00390
00391 #endif
00392
00393
00394
00395
00396