type_traits.h 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626
  1. /*
  2. *
  3. * Copyright (c) 1996,1997
  4. * Silicon Graphics Computer Systems, Inc.
  5. *
  6. * Copyright (c) 1997
  7. * Moscow Center for SPARC Technology
  8. *
  9. * Copyright (c) 1999
  10. * Boris Fomitchev
  11. *
  12. * This material is provided "as is", with absolutely no warranty expressed
  13. * or implied. Any use is at your own risk.
  14. *
  15. * Permission to use or copy this software for any purpose is hereby granted
  16. * without fee, provided the above notices are retained on all copies.
  17. * Permission to modify the code and to distribute modified code is granted,
  18. * provided the above notices are retained, and a notice that the code was
  19. * modified is included with the above copyright notice.
  20. *
  21. */
  22. #ifndef _STLP_TYPE_TRAITS_H
  23. #define _STLP_TYPE_TRAITS_H
  24. /*
  25. This header file provides a framework for allowing compile time dispatch
  26. based on type attributes. This is useful when writing template code.
  27. For example, when making a copy of an array of an unknown type, it helps
  28. to know if the type has a trivial copy constructor or not, to help decide
  29. if a memcpy can be used.
  30. The class template __type_traits provides a series of typedefs each of
  31. which is either __true_type or __false_type. The argument to
  32. __type_traits can be any type. The typedefs within this template will
  33. attain their correct values by one of these means:
  34. 1. The general instantiation contain conservative values which work
  35. for all types.
  36. 2. Specializations may be declared to make distinctions between types.
  37. 3. Some compilers (such as the Silicon Graphics N32 and N64 compilers)
  38. will automatically provide the appropriate specializations for all
  39. types.
  40. EXAMPLE:
  41. //Copy an array of elements which have non-trivial copy constructors
  42. template <class T> void copy(T* source, T* destination, int n, __false_type);
  43. //Copy an array of elements which have trivial copy constructors. Use memcpy.
  44. template <class T> void copy(T* source, T* destination, int n, __true_type);
  45. //Copy an array of any type by using the most efficient copy mechanism
  46. template <class T> inline void copy(T* source,T* destination,int n) {
  47. copy(source, destination, n,
  48. typename __type_traits<T>::has_trivial_copy_constructor());
  49. }
  50. */
  51. #ifdef __WATCOMC__
  52. # include <stl/_cwchar.h>
  53. #endif
  54. #ifndef _STLP_TYPE_MANIPS_H
  55. # include <stl/type_manips.h>
  56. #endif
  57. #ifdef _STLP_USE_BOOST_SUPPORT
  58. # include <stl/boost_type_traits.h>
  59. # include <boost/type_traits/add_reference.hpp>
  60. # include <boost/type_traits/add_const.hpp>
  61. #endif /* _STLP_USE_BOOST_SUPPORT */
  62. _STLP_BEGIN_NAMESPACE
  63. #if !defined (_STLP_USE_BOOST_SUPPORT)
  64. // The following could be written in terms of numeric_limits.
  65. // We're doing it separately to reduce the number of dependencies.
  66. template <class _Tp> struct _IsIntegral
  67. { typedef __false_type _Ret; };
  68. # ifndef _STLP_NO_BOOL
  69. _STLP_TEMPLATE_NULL struct _IsIntegral<bool>
  70. { typedef __true_type _Ret; };
  71. # endif /* _STLP_NO_BOOL */
  72. _STLP_TEMPLATE_NULL struct _IsIntegral<char>
  73. { typedef __true_type _Ret; };
  74. # ifndef _STLP_NO_SIGNED_BUILTINS
  75. _STLP_TEMPLATE_NULL struct _IsIntegral<signed char>
  76. { typedef __true_type _Ret; };
  77. # endif
  78. _STLP_TEMPLATE_NULL struct _IsIntegral<unsigned char>
  79. { typedef __true_type _Ret; };
  80. # if defined ( _STLP_HAS_WCHAR_T ) && ! defined (_STLP_WCHAR_T_IS_USHORT)
  81. _STLP_TEMPLATE_NULL struct _IsIntegral<wchar_t>
  82. { typedef __true_type _Ret; };
  83. # endif /* _STLP_HAS_WCHAR_T */
  84. _STLP_TEMPLATE_NULL struct _IsIntegral<short>
  85. { typedef __true_type _Ret; };
  86. _STLP_TEMPLATE_NULL struct _IsIntegral<unsigned short>
  87. { typedef __true_type _Ret; };
  88. _STLP_TEMPLATE_NULL struct _IsIntegral<int>
  89. { typedef __true_type _Ret; };
  90. _STLP_TEMPLATE_NULL struct _IsIntegral<unsigned int>
  91. { typedef __true_type _Ret; };
  92. _STLP_TEMPLATE_NULL struct _IsIntegral<long>
  93. { typedef __true_type _Ret; };
  94. _STLP_TEMPLATE_NULL struct _IsIntegral<unsigned long>
  95. { typedef __true_type _Ret; };
  96. # ifdef _STLP_LONG_LONG
  97. _STLP_TEMPLATE_NULL struct _IsIntegral<_STLP_LONG_LONG>
  98. { typedef __true_type _Ret; };
  99. _STLP_TEMPLATE_NULL struct _IsIntegral<unsigned _STLP_LONG_LONG>
  100. { typedef __true_type _Ret; };
  101. # endif /* _STLP_LONG_LONG */
  102. template <class _Tp> struct _IsRational
  103. { typedef __false_type _Ret; };
  104. _STLP_TEMPLATE_NULL struct _IsRational<float>
  105. { typedef __true_type _Ret; };
  106. _STLP_TEMPLATE_NULL struct _IsRational<double>
  107. { typedef __true_type _Ret; };
  108. # if !defined ( _STLP_NO_LONG_DOUBLE )
  109. _STLP_TEMPLATE_NULL struct _IsRational<long double>
  110. { typedef __true_type _Ret; };
  111. # endif
  112. // Forward declarations.
  113. template <class _Tp> struct __type_traits;
  114. template <class _IsPOD> struct __type_traits_aux {
  115. typedef __false_type has_trivial_default_constructor;
  116. typedef __false_type has_trivial_copy_constructor;
  117. typedef __false_type has_trivial_assignment_operator;
  118. typedef __false_type has_trivial_destructor;
  119. typedef __false_type is_POD_type;
  120. };
  121. _STLP_TEMPLATE_NULL
  122. struct __type_traits_aux<__false_type> {
  123. typedef __false_type has_trivial_default_constructor;
  124. typedef __false_type has_trivial_copy_constructor;
  125. typedef __false_type has_trivial_assignment_operator;
  126. typedef __false_type has_trivial_destructor;
  127. typedef __false_type is_POD_type;
  128. };
  129. _STLP_TEMPLATE_NULL
  130. struct __type_traits_aux<__true_type> {
  131. typedef __true_type has_trivial_default_constructor;
  132. typedef __true_type has_trivial_copy_constructor;
  133. typedef __true_type has_trivial_assignment_operator;
  134. typedef __true_type has_trivial_destructor;
  135. typedef __true_type is_POD_type;
  136. };
  137. template <class _Tp>
  138. struct _IsRef {
  139. typedef __false_type _Ret;
  140. };
  141. # if defined (_STLP_SIMULATE_PARTIAL_SPEC_FOR_TYPE_TRAITS)
  142. /*
  143. * Boris : simulation technique is used here according to Adobe Open Source License Version 1.0.
  144. * Copyright 2000 Adobe Systems Incorporated and others. All rights reserved.
  145. * Authors: Mat Marcus and Jesse Jones
  146. * The original version of this source code may be found at
  147. * http://opensource.adobe.com.
  148. */
  149. struct _PointerShim {
  150. /*
  151. * Since the compiler only allows at most one non-trivial
  152. * implicit conversion we can make use of a shim class to
  153. * be sure that IsPtr below doesn't accept classes with
  154. * implicit pointer conversion operators
  155. */
  156. _PointerShim(const volatile void*); // no implementation
  157. };
  158. // These are the discriminating functions
  159. char _STLP_CALL _IsP(bool, _PointerShim); // no implementation is required
  160. char* _STLP_CALL _IsP(bool, ...); // no implementation is required
  161. template <class _Tp>
  162. struct _IsPtr {
  163. /*
  164. * This template meta function takes a type T
  165. * and returns true exactly when T is a pointer.
  166. * One can imagine meta-functions discriminating on
  167. * other criteria.
  168. */
  169. static _Tp& __null_rep();
  170. enum { _Ptr = (sizeof(_IsP(false,__null_rep())) == sizeof(char)) };
  171. typedef typename __bool2type<_Ptr>::_Ret _Ret;
  172. };
  173. // we make general case dependant on the fact the type is actually a pointer.
  174. template <class _Tp>
  175. struct __type_traits : __type_traits_aux<typename _IsPtr<_Tp>::_Ret> {};
  176. # else /* _STLP_SIMULATE_PARTIAL_SPEC_FOR_TYPE_TRAITS */
  177. template <class _Tp> struct _IsPtr {
  178. typedef __false_type _Ret;
  179. };
  180. template <class _Tp>
  181. struct __type_traits {
  182. typedef __true_type this_dummy_member_must_be_first;
  183. /* Do not remove this member. It informs a compiler which
  184. automatically specializes __type_traits that this
  185. __type_traits template is special. It just makes sure that
  186. things work if an implementation is using a template
  187. called __type_traits for something unrelated. */
  188. /* The following restrictions should be observed for the sake of
  189. compilers which automatically produce type specific specializations
  190. of this class:
  191. - You may reorder the members below if you wish
  192. - You may remove any of the members below if you wish
  193. - You must not rename members without making the corresponding
  194. name change in the compiler
  195. - Members you add will be treated like regular members unless
  196. you add the appropriate support in the compiler. */
  197. # if !defined (_STLP_HAS_TYPE_TRAITS_INTRINSICS)
  198. typedef __false_type has_trivial_default_constructor;
  199. typedef __false_type has_trivial_copy_constructor;
  200. typedef __false_type has_trivial_assignment_operator;
  201. typedef __false_type has_trivial_destructor;
  202. typedef __false_type is_POD_type;
  203. # else
  204. typedef typename __bool2type<_STLP_HAS_TRIVIAL_CONSTRUCTOR(_Tp)>::_Ret has_trivial_default_constructor;
  205. typedef typename __bool2type<_STLP_HAS_TRIVIAL_COPY(_Tp)>::_Ret has_trivial_copy_constructor;
  206. typedef typename __bool2type<_STLP_HAS_TRIVIAL_ASSIGN(_Tp)>::_Ret has_trivial_assignment_operator;
  207. typedef typename __bool2type<_STLP_HAS_TRIVIAL_DESTRUCTOR(_Tp)>::_Ret has_trivial_destructor;
  208. typedef typename __bool2type<_STLP_IS_POD(_Tp)>::_Ret is_POD_type;
  209. # endif
  210. };
  211. # if defined (_STLP_CLASS_PARTIAL_SPECIALIZATION)
  212. template <class _Tp> struct _IsPtr<_Tp*>
  213. { typedef __true_type _Ret; };
  214. template <class _Tp> struct _IsRef<_Tp&>
  215. { typedef __true_type _Ret; };
  216. template <class _Tp> struct __type_traits<_Tp*> : __type_traits_aux<__true_type>
  217. {};
  218. # endif /* _STLP_CLASS_PARTIAL_SPECIALIZATION */
  219. # endif /* _STLP_SIMULATE_PARTIAL_SPEC_FOR_TYPE_TRAITS */
  220. // Provide some specializations. This is harmless for compilers that
  221. // have built-in __types_traits support, and essential for compilers
  222. // that don't.
  223. # if !defined (_STLP_QUALIFIED_SPECIALIZATION_BUG)
  224. # define _STLP_DEFINE_TYPE_TRAITS_FOR(Type) \
  225. _STLP_TEMPLATE_NULL struct __type_traits< Type > : __type_traits_aux<__true_type> {}; \
  226. _STLP_TEMPLATE_NULL struct __type_traits< const Type > : __type_traits_aux<__true_type> {}; \
  227. _STLP_TEMPLATE_NULL struct __type_traits< volatile Type > : __type_traits_aux<__true_type> {}; \
  228. _STLP_TEMPLATE_NULL struct __type_traits< const volatile Type > : __type_traits_aux<__true_type> {}
  229. # else
  230. # define _STLP_DEFINE_TYPE_TRAITS_FOR(Type) \
  231. _STLP_TEMPLATE_NULL struct __type_traits< Type > : __type_traits_aux<__true_type> {};
  232. # endif
  233. # ifndef _STLP_NO_BOOL
  234. _STLP_DEFINE_TYPE_TRAITS_FOR(bool);
  235. # endif /* _STLP_NO_BOOL */
  236. _STLP_DEFINE_TYPE_TRAITS_FOR(char);
  237. # ifndef _STLP_NO_SIGNED_BUILTINS
  238. _STLP_DEFINE_TYPE_TRAITS_FOR(signed char);
  239. # endif
  240. _STLP_DEFINE_TYPE_TRAITS_FOR(unsigned char);
  241. # if defined ( _STLP_HAS_WCHAR_T ) && ! defined (_STLP_WCHAR_T_IS_USHORT)
  242. _STLP_DEFINE_TYPE_TRAITS_FOR(wchar_t);
  243. # endif /* _STLP_HAS_WCHAR_T */
  244. _STLP_DEFINE_TYPE_TRAITS_FOR(short);
  245. _STLP_DEFINE_TYPE_TRAITS_FOR(unsigned short);
  246. _STLP_DEFINE_TYPE_TRAITS_FOR(int);
  247. _STLP_DEFINE_TYPE_TRAITS_FOR(unsigned int);
  248. _STLP_DEFINE_TYPE_TRAITS_FOR(long);
  249. _STLP_DEFINE_TYPE_TRAITS_FOR(unsigned long);
  250. # ifdef _STLP_LONG_LONG
  251. _STLP_DEFINE_TYPE_TRAITS_FOR(_STLP_LONG_LONG);
  252. _STLP_DEFINE_TYPE_TRAITS_FOR(unsigned _STLP_LONG_LONG);
  253. # endif /* _STLP_LONG_LONG */
  254. _STLP_DEFINE_TYPE_TRAITS_FOR(float);
  255. _STLP_DEFINE_TYPE_TRAITS_FOR(double);
  256. # if !defined ( _STLP_NO_LONG_DOUBLE )
  257. _STLP_DEFINE_TYPE_TRAITS_FOR(long double);
  258. # endif
  259. # if defined (_STLP_CLASS_PARTIAL_SPECIALIZATION)
  260. template <class _ArePtrs, class _Src, class _Dst>
  261. struct _IsCVConvertibleIf
  262. { typedef typename _IsCVConvertible<_Src, _Dst>::_Ret _Ret; };
  263. template <class _Src, class _Dst>
  264. struct _IsCVConvertibleIf<__false_type, _Src, _Dst>
  265. { typedef __false_type _Ret; };
  266. # else
  267. # if defined (_STLP_MEMBER_TEMPLATE_CLASSES)
  268. template <class _ArePtrs>
  269. struct _IsCVConvertibleIfAux {
  270. template <class _Src, class _Dst>
  271. struct _In
  272. { typedef typename _IsCVConvertible<_Src, _Dst>::_Ret _Ret; };
  273. };
  274. _STLP_TEMPLATE_NULL
  275. struct _IsCVConvertibleIfAux<__false_type> {
  276. template <class _Src, class _Dst>
  277. struct _In
  278. { typedef __false_type _Ret; };
  279. };
  280. template <class _ArePtrs, class _Src, class _Dst>
  281. struct _IsCVConvertibleIf {
  282. typedef typename _IsCVConvertibleIfAux<_ArePtrs>::_STLP_TEMPLATE _In<_Src, _Dst>::_Ret _Ret;
  283. };
  284. # else
  285. /* default behavior: we prefer to miss an optimization rather than taking the risk of
  286. * a compilation error if playing with types with exotic memory alignment.
  287. */
  288. template <class _ArePtrs, class _Src, class _Dst>
  289. struct _IsCVConvertibleIf
  290. { typedef __false_type _Ret; };
  291. # endif
  292. # endif
  293. template <class _Src, class _Dst>
  294. struct _TrivialNativeTypeCopy {
  295. typedef typename _IsPtr<_Src>::_Ret _Ptr1;
  296. typedef typename _IsPtr<_Dst>::_Ret _Ptr2;
  297. typedef typename _Land2<_Ptr1, _Ptr2>::_Ret _BothPtrs;
  298. typedef typename _IsCVConvertibleIf<_BothPtrs, _Src, _Dst>::_Ret _Convertible;
  299. typedef typename _Land2<_BothPtrs, _Convertible>::_Ret _Trivial1;
  300. typedef typename __bool2type<(sizeof(_Src) == sizeof(_Dst))>::_Ret _SameSize;
  301. #if !defined (__BORLANDC__) || (__BORLANDC__ < 0x564)
  302. typedef typename _IsIntegral<_Src>::_Ret _Int1;
  303. #else
  304. typedef typename _UnQual<_Src>::_Type _UnQuSrc;
  305. typedef typename _IsIntegral<_UnQuSrc>::_Ret _Int1;
  306. #endif
  307. typedef typename _IsIntegral<_Dst>::_Ret _Int2;
  308. typedef typename _Land2<_Int1, _Int2>::_Ret _BothInts;
  309. typedef typename _IsRational<_Src>::_Ret _Rat1;
  310. typedef typename _IsRational<_Dst>::_Ret _Rat2;
  311. typedef typename _Land2<_Rat1, _Rat2>::_Ret _BothRats;
  312. typedef typename _Lor2<_BothInts, _BothRats>::_Ret _BothNatives;
  313. #if !defined (__BORLANDC__) || (__BORLANDC__ >= 0x564)
  314. typedef typename _Land2<_BothNatives, _SameSize>::_Ret _Trivial2;
  315. #else
  316. typedef typename _IsUnQual<_Dst>::_Ret _UnQualDst;
  317. typedef typename _Land3<_BothNatives, _SameSize, _UnQualDst>::_Ret _Trivial2;
  318. #endif
  319. typedef typename _Lor2<_Trivial1, _Trivial2>::_Ret _Ret;
  320. };
  321. template <class _Src, class _Dst>
  322. struct _TrivialCopy {
  323. typedef typename _TrivialNativeTypeCopy<_Src, _Dst>::_Ret _NativeRet;
  324. # if !defined (__BORLANDC__) || (__BORLANDC__ != 0x560)
  325. typedef typename __type_traits<_Src>::has_trivial_assignment_operator _Tr1;
  326. # else
  327. typedef typename _UnConstPtr<_Src*>::_Type _UnConstSrc;
  328. typedef typename __type_traits<_UnConstSrc>::has_trivial_assignment_operator _Tr1;
  329. # endif
  330. typedef typename _AreCopyable<_Src, _Dst>::_Ret _Tr2;
  331. typedef typename _Land2<_Tr1, _Tr2>::_Ret _UserRet;
  332. typedef typename _Lor2<_NativeRet, _UserRet>::_Ret _Ret;
  333. static _Ret _Answer() { return _Ret(); }
  334. };
  335. template <class _Src, class _Dst>
  336. struct _TrivialUCopy {
  337. typedef typename _TrivialNativeTypeCopy<_Src, _Dst>::_Ret _NativeRet;
  338. # if !defined (__BORLANDC__) || (__BORLANDC__ != 0x560)
  339. typedef typename __type_traits<_Src>::has_trivial_copy_constructor _Tr1;
  340. # else
  341. typedef typename _UnConstPtr<_Src*>::_Type _UnConstSrc;
  342. typedef typename __type_traits<_UnConstSrc>::has_trivial_copy_constructor _Tr1;
  343. # endif
  344. typedef typename _AreCopyable<_Src, _Dst>::_Ret _Tr2;
  345. typedef typename _Land2<_Tr1, _Tr2>::_Ret _UserRet;
  346. typedef typename _Lor2<_NativeRet, _UserRet>::_Ret _Ret;
  347. static _Ret _Answer() { return _Ret(); }
  348. };
  349. template <class _Tp>
  350. struct _DefaultZeroValue {
  351. typedef typename _IsIntegral<_Tp>::_Ret _Tr1;
  352. typedef typename _IsRational<_Tp>::_Ret _Tr2;
  353. typedef typename _IsPtr<_Tp>::_Ret _Tr3;
  354. typedef typename _Lor3<_Tr1, _Tr2, _Tr3>::_Ret _Ret;
  355. };
  356. template <class _Tp>
  357. struct _TrivialInit {
  358. # if !defined (__BORLANDC__) || (__BORLANDC__ != 0x560)
  359. typedef typename __type_traits<_Tp>::has_trivial_default_constructor _Tr1;
  360. # else
  361. typedef typename _UnConstPtr<_Tp*>::_Type _Tp1;
  362. typedef typename __type_traits<_Tp1>::has_trivial_copy_constructor _Tr1;
  363. # endif
  364. typedef typename _DefaultZeroValue<_Tp>::_Ret _Tr2;
  365. typedef typename _Not<_Tr2>::_Ret _Tr3;
  366. typedef typename _Land2<_Tr1, _Tr3>::_Ret _Ret;
  367. static _Ret _Answer() { return _Ret(); }
  368. };
  369. #endif /* !_STLP_USE_BOOST_SUPPORT */
  370. template <class _Tp>
  371. struct _IsPtrType {
  372. typedef typename _IsPtr<_Tp>::_Ret _Type;
  373. static _Type _Ret() { return _Type(); }
  374. };
  375. template <class _Tp>
  376. struct _IsRefType {
  377. typedef typename _IsRef<_Tp>::_Ret _Type;
  378. static _Type _Ret() { return _Type();}
  379. };
  380. template <class _Tp>
  381. struct __call_traits {
  382. #if defined (_STLP_USE_BOOST_SUPPORT) && !defined (_STLP_NO_EXTENSIONS)
  383. typedef typename __select< ::boost::is_reference<_Tp>::value,
  384. typename ::boost::add_const<_Tp>::type,
  385. typename ::boost::add_reference< typename ::boost::add_const<_Tp>::type >::type>::_Ret const_param_type;
  386. typedef typename __select< ::boost::is_reference<_Tp>::value,
  387. typename ::boost::remove_const<_Tp>::type,
  388. typename ::boost::add_reference<_Tp>::type>::_Ret param_type;
  389. #else
  390. typedef const _Tp& const_param_type;
  391. typedef _Tp& param_type;
  392. #endif
  393. };
  394. #if !defined (_STLP_USE_BOOST_SUPPORT) && !defined (_STLP_NO_EXTENSIONS) && defined (_STLP_CLASS_PARTIAL_SPECIALIZATION)
  395. template <class _Tp>
  396. struct __call_traits<_Tp&> {
  397. typedef _Tp& param_type;
  398. typedef const _Tp& const_param_type;
  399. };
  400. template <class _Tp>
  401. struct __call_traits<const _Tp&> {
  402. typedef _Tp& param_type;
  403. typedef const _Tp& const_param_type;
  404. };
  405. #endif
  406. template <class _Tp1, class _Tp2>
  407. struct _BothPtrType {
  408. typedef typename _IsPtr<_Tp1>::_Ret _IsPtr1;
  409. typedef typename _IsPtr<_Tp2>::_Ret _IsPtr2;
  410. typedef typename _Land2<_IsPtr1, _IsPtr2>::_Ret _Ret;
  411. static _Ret _Answer() { return _Ret(); }
  412. };
  413. template <class _Tp1, class _Tp2, class _IsRef1, class _IsRef2>
  414. struct _OKToSwap {
  415. typedef typename _AreSameTypes<_Tp1, _Tp2>::_Ret _Same;
  416. typedef typename _Land3<_Same, _IsRef1, _IsRef2>::_Ret _Type;
  417. static _Type _Answer() { return _Type(); }
  418. };
  419. template <class _Tp1, class _Tp2, class _IsRef1, class _IsRef2>
  420. inline _OKToSwap<_Tp1, _Tp2, _IsRef1, _IsRef2>
  421. _IsOKToSwap(_Tp1*, _Tp2*, const _IsRef1&, const _IsRef2&)
  422. { return _OKToSwap<_Tp1, _Tp2, _IsRef1, _IsRef2>(); }
  423. template <class _Src, class _Dst>
  424. inline _TrivialCopy<_Src, _Dst> _UseTrivialCopy(_Src*, _Dst*)
  425. { return _TrivialCopy<_Src, _Dst>(); }
  426. template <class _Src, class _Dst>
  427. inline _TrivialUCopy<_Src, _Dst> _UseTrivialUCopy(_Src*, _Dst*)
  428. { return _TrivialUCopy<_Src, _Dst>(); }
  429. #if defined (_STLP_FUNCTION_TMPL_PARTIAL_ORDER) || defined (__BORLANDC__) || \
  430. defined (__DMC__)
  431. struct _NegativeAnswer {
  432. typedef __false_type _Ret;
  433. static _Ret _Answer() { return _Ret(); }
  434. };
  435. template <class _Src, class _Dst>
  436. inline _NegativeAnswer _UseTrivialCopy(_Src*, const _Dst*)
  437. { return _NegativeAnswer(); }
  438. template <class _Src, class _Dst>
  439. inline _NegativeAnswer _UseTrivialCopy(_Src*, volatile _Dst*)
  440. { return _NegativeAnswer(); }
  441. template <class _Src, class _Dst>
  442. inline _NegativeAnswer _UseTrivialCopy(_Src*, const volatile _Dst*)
  443. { return _NegativeAnswer(); }
  444. template <class _Src, class _Dst>
  445. inline _NegativeAnswer _UseTrivialUCopy(_Src*, const _Dst*)
  446. { return _NegativeAnswer(); }
  447. template <class _Src, class _Dst>
  448. inline _NegativeAnswer _UseTrivialUCopy(_Src*, volatile _Dst*)
  449. { return _NegativeAnswer(); }
  450. template <class _Src, class _Dst>
  451. inline _NegativeAnswer _UseTrivialUCopy(_Src*, const volatile _Dst*)
  452. { return _NegativeAnswer(); }
  453. #endif
  454. template <class _Tp>
  455. inline _TrivialInit<_Tp> _UseTrivialInit(_Tp*)
  456. { return _TrivialInit<_Tp>(); }
  457. template <class _Tp>
  458. struct _IsPOD {
  459. typedef typename __type_traits<_Tp>::is_POD_type _Type;
  460. static _Type _Answer() { return _Type(); }
  461. };
  462. template <class _Tp>
  463. inline _IsPOD<_Tp> _Is_POD(_Tp*)
  464. { return _IsPOD<_Tp>(); }
  465. template <class _Tp>
  466. struct _DefaultZeroValueQuestion {
  467. typedef typename _DefaultZeroValue<_Tp>::_Ret _Ret;
  468. static _Ret _Answer() { return _Ret(); }
  469. };
  470. template <class _Tp>
  471. inline _DefaultZeroValueQuestion<_Tp> _HasDefaultZeroValue(_Tp*)
  472. { return _DefaultZeroValueQuestion<_Tp>(); }
  473. /*
  474. * Base class used:
  475. * - to simulate partial template specialization
  476. * - to simulate partial function ordering
  477. * - to recognize STLport class from user specialized one
  478. */
  479. template <class _Tp>
  480. struct __stlport_class
  481. { typedef _Tp _Type; };
  482. template <class _Tp>
  483. struct _IsSTLportClass {
  484. typedef typename _IsConvertible<_Tp, __stlport_class<_Tp> >::_Ret _Ret;
  485. #if defined (__BORLANDC__)
  486. enum { _Is = _IsConvertible<_Tp, __stlport_class<_Tp> >::value };
  487. #endif
  488. };
  489. #if defined (_STLP_USE_PARTIAL_SPEC_WORKAROUND) && !defined (_STLP_FUNCTION_TMPL_PARTIAL_ORDER)
  490. template <class _Tp>
  491. struct _SwapImplemented {
  492. typedef typename _IsSTLportClass<_Tp>::_Ret _Ret;
  493. # if defined (__BORLANDC__)
  494. enum { _Is = _IsSTLportClass<_Tp>::_Is };
  495. # endif
  496. };
  497. #endif
  498. template <class _Tp>
  499. class _TpWithState : private _Tp {
  500. _TpWithState();
  501. int _state;
  502. };
  503. /* This is an internal helper struct used to guess if we are working
  504. * on a stateless class. It can only be instanciated with a class type. */
  505. template <class _Tp>
  506. struct _IsStateless {
  507. enum { _Is = sizeof(_TpWithState<_Tp>) == sizeof(int) };
  508. typedef typename __bool2type<_Is>::_Ret _Ret;
  509. };
  510. _STLP_END_NAMESPACE
  511. #ifdef _STLP_CLASS_PARTIAL_SPECIALIZATION
  512. # if defined (__BORLANDC__) || \
  513. defined (__SUNPRO_CC) || \
  514. (defined (__MWERKS__) && (__MWERKS__ <= 0x2303)) || \
  515. (defined (__sgi) && defined (_COMPILER_VERSION)) || \
  516. defined (__DMC__)
  517. # define _STLP_IS_POD_ITER(_It, _Tp) __type_traits< typename iterator_traits< _Tp >::value_type >::is_POD_type()
  518. # else
  519. # define _STLP_IS_POD_ITER(_It, _Tp) typename __type_traits< typename iterator_traits< _Tp >::value_type >::is_POD_type()
  520. # endif
  521. #else
  522. # define _STLP_IS_POD_ITER(_It, _Tp) _Is_POD( _STLP_VALUE_TYPE( _It, _Tp ) )._Answer()
  523. #endif
  524. #endif /* _STLP_TYPE_TRAITS_H */
  525. // Local Variables:
  526. // mode:C++
  527. // End: