boost_type_traits.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. /*
  2. *
  3. * Copyright (c) 2004
  4. * Francois Dumont
  5. *
  6. * This material is provided "as is", with absolutely no warranty expressed
  7. * or implied. Any use is at your own risk.
  8. *
  9. * Permission to use or copy this software for any purpose is hereby granted
  10. * without fee, provided the above notices are retained on all copies.
  11. * Permission to modify the code and to distribute modified code is granted,
  12. * provided the above notices are retained, and a notice that the code was
  13. * modified is included with the above copyright notice.
  14. *
  15. */
  16. #ifndef _STLP_BOOST_TYPE_TRAITS_H
  17. #define _STLP_BOOST_TYPE_TRAITS_H
  18. #ifndef BOOST_CONFIG_SUFFIX_HPP
  19. # ifdef BOOST_CONFIG_HPP
  20. # undef BOOST_CONFIG_HPP
  21. # endif
  22. # include <boost/config.hpp>
  23. #endif
  24. #include <boost/type_traits/is_integral.hpp>
  25. #include <boost/type_traits/is_float.hpp>
  26. #include <boost/type_traits/has_trivial_constructor.hpp>
  27. #include <boost/type_traits/has_trivial_copy.hpp>
  28. #include <boost/type_traits/has_trivial_assign.hpp>
  29. #include <boost/type_traits/has_trivial_destructor.hpp>
  30. #include <boost/type_traits/is_pod.hpp>
  31. #include <boost/type_traits/is_pointer.hpp>
  32. #include <boost/type_traits/is_reference.hpp>
  33. #include <boost/type_traits/remove_cv.hpp>
  34. #include <boost/type_traits/is_same.hpp>
  35. /*
  36. * This file mostly wraps boost type_traits in the STLport type_traits.
  37. * When checking a type traits like trivial assign operator for instance
  38. * both the boost value and STLport values has to be taken into account
  39. * as we don't know what the user might have prefer, specializing the boost
  40. * type traits or the STLport one.
  41. */
  42. _STLP_BEGIN_NAMESPACE
  43. template <class _Tp> struct _IsRef {
  44. enum { _Is = ::boost::is_reference<_Tp>::value };
  45. typedef typename __bool2type<_Is>::_Ret _Ret;
  46. };
  47. template <class _Tp> struct _IsPtr {
  48. enum { is_pointer = ::boost::is_pointer<_Tp>::value };
  49. typedef typename __bool2type<is_pointer>::_Ret _Ret;
  50. };
  51. template <class _Tp> struct _IsIntegral {
  52. enum { is_integral = ::boost::is_integral<_Tp>::value };
  53. typedef typename __bool2type<is_integral>::_Ret _Ret;
  54. };
  55. template <class _Tp> struct _IsRational {
  56. enum { is_float = ::boost::is_float<_Tp>::value };
  57. typedef typename __bool2type<is_float>::_Ret _Ret;
  58. };
  59. template <class _Tp>
  60. struct __type_traits {
  61. enum { trivial_constructor = ::boost::has_trivial_constructor<_Tp>::value };
  62. typedef typename __bool2type<trivial_constructor>::_Ret has_trivial_default_constructor;
  63. enum { trivial_copy = ::boost::has_trivial_copy<_Tp>::value };
  64. typedef typename __bool2type<trivial_copy>::_Ret has_trivial_copy_constructor;
  65. enum { trivial_assign = ::boost::has_trivial_assign<_Tp>::value };
  66. typedef typename __bool2type<trivial_assign>::_Ret has_trivial_assignment_operator;
  67. enum { trivial_destructor = ::boost::has_trivial_destructor<_Tp>::value };
  68. typedef typename __bool2type<trivial_destructor>::_Ret has_trivial_destructor;
  69. enum { pod = ::boost::is_pod<_Tp>::value };
  70. typedef typename __bool2type<pod>::_Ret is_POD_type;
  71. };
  72. template <class _Tp1, class _Tp2>
  73. struct _TrivialCopy {
  74. typedef typename ::boost::remove_cv<_Tp1>::type uncv1;
  75. typedef typename ::boost::remove_cv<_Tp2>::type uncv2;
  76. enum { same = ::boost::is_same<uncv1, uncv2>::value };
  77. typedef typename __bool2type<same>::_Ret _Same;
  78. enum { boost_trivial_assign = ::boost::has_trivial_assign<uncv1>::value };
  79. typedef typename __bool2type<boost_trivial_assign>::_Ret _BoostTrivialAssign;
  80. typedef typename __type_traits<uncv1>::has_trivial_assignment_operator _STLPTrivialAssign;
  81. typedef typename _Lor2<_BoostTrivialAssign, _STLPTrivialAssign>::_Ret _TrivialAssign;
  82. typedef typename _Land2<_Same, _TrivialAssign>::_Ret _Type;
  83. static _Type _Answer() { return _Type(); }
  84. };
  85. template <class _Tp1, class _Tp2>
  86. struct _TrivialUCopy {
  87. typedef typename ::boost::remove_cv<_Tp1>::type uncv1;
  88. typedef typename ::boost::remove_cv<_Tp2>::type uncv2;
  89. enum { same = ::boost::is_same<uncv1, uncv2>::value };
  90. typedef typename __bool2type<same>::_Ret _Same;
  91. enum { boost_trivial_copy = ::boost::has_trivial_copy<uncv1>::value };
  92. typedef typename __bool2type<boost_trivial_copy>::_Ret _BoostTrivialCopy;
  93. typedef typename __type_traits<uncv1>::has_trivial_copy_constructor _STLPTrivialCopy;
  94. typedef typename _Lor2<_BoostTrivialCopy, _STLPTrivialCopy>::_Ret _TrivialCopy;
  95. typedef typename _Land2<_Same, _TrivialCopy>::_Ret _Type;
  96. static _Type _Answer() { return _Type(); }
  97. };
  98. template <class _Tp>
  99. struct _DefaultZeroValue {
  100. enum { is_integral = ::boost::is_integral<_Tp>::value };
  101. typedef typename __bool2type<is_integral>::_Ret _IsIntegral;
  102. enum { is_float = ::boost::is_float<_Tp>::value };
  103. typedef typename __bool2type<is_float>::_Ret _IsFloat;
  104. enum { is_pointer = ::boost::is_pointer<_Tp>::value };
  105. typedef typename __bool2type<is_pointer>::_Ret _IsPointer;
  106. typedef typename _Lor3<_IsIntegral, _IsFloat, _IsPointer>::_Ret _Ret;
  107. };
  108. template <class _Tp>
  109. struct _TrivialInit {
  110. typedef typename ::boost::remove_cv<_Tp>::type uncv;
  111. enum { boost_trivial_constructor = ::boost::has_trivial_constructor<uncv>::value };
  112. typedef typename __bool2type<boost_trivial_constructor>::_Ret _BoostTrivialInit;
  113. typedef typename __type_traits<uncv>::has_trivial_default_constructor _STLPTrivialInit;
  114. typedef typename _Lor2<_BoostTrivialInit, _STLPTrivialInit>::_Ret _Tr1;
  115. typedef typename _DefaultZeroValue<_Tp>::_Ret _Tr2;
  116. typedef typename _Not<_Tr2>::_Ret _Tr3;
  117. typedef typename _Land2<_Tr1, _Tr3>::_Ret _Ret;
  118. static _Ret _Answer() { return _Ret(); }
  119. };
  120. _STLP_END_NAMESPACE
  121. #endif /* _STLP_BOOST_TYPE_TRAITS_H */