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 17 #ifndef _STLP_BOOST_TYPE_TRAITS_H 18 #define _STLP_BOOST_TYPE_TRAITS_H 19 20 #include <boost/type_traits/is_integral.hpp> 21 #include <boost/type_traits/is_float.hpp> 22 #include <boost/type_traits/has_trivial_constructor.hpp> 23 #include <boost/type_traits/has_trivial_copy.hpp> 24 #include <boost/type_traits/has_trivial_assign.hpp> 25 #include <boost/type_traits/has_trivial_destructor.hpp> 26 #include <boost/type_traits/is_pod.hpp> 27 #include <boost/type_traits/is_pointer.hpp> 28 #include <boost/type_traits/is_reference.hpp> 29 #include <boost/type_traits/remove_cv.hpp> 30 #include <boost/type_traits/is_same.hpp> 31 32 /* 33 * This file mostly wraps boost type_traits in the STLport type_traits. 34 * When checking a type traits like trivial assign operator for instance 35 * both the boost value and STLport values has to be taken into account 36 * as we don't know what the user might have prefer, specializing the boost 37 * type traits or the STLport one. 38 */ 39 _STLP_BEGIN_NAMESPACE 40 41 template <class _Tp> struct _IsRef { 42 enum { _Is = ::boost::is_reference<_Tp>::value }; 43 typedef typename __bool2type<_Is>::_Ret _Ret; 44 }; 45 46 template <class _Tp> struct _IsPtr { 47 enum { is_pointer = ::boost::is_pointer<_Tp>::value }; 48 typedef typename __bool2type<is_pointer>::_Ret _Ret; 49 }; 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 56 template <class _Tp> struct _IsRational { 57 enum { is_float = ::boost::is_float<_Tp>::value }; 58 typedef typename __bool2type<is_float>::_Ret _Ret; 59 }; 60 61 template <class _Tp> 62 struct __type_traits { 63 enum { trivial_constructor = ::boost::has_trivial_constructor<_Tp>::value }; 64 typedef typename __bool2type<trivial_constructor>::_Ret has_trivial_default_constructor; 65 66 enum { trivial_copy = ::boost::has_trivial_copy<_Tp>::value }; 67 typedef typename __bool2type<trivial_copy>::_Ret has_trivial_copy_constructor; 68 69 enum { trivial_assign = ::boost::has_trivial_assign<_Tp>::value }; 70 typedef typename __bool2type<trivial_assign>::_Ret has_trivial_assignment_operator; 71 72 enum { trivial_destructor = ::boost::has_trivial_destructor<_Tp>::value }; 73 typedef typename __bool2type<trivial_destructor>::_Ret has_trivial_destructor; 74 75 enum { pod = ::boost::is_pod<_Tp>::value }; 76 typedef typename __bool2type<pod>::_Ret is_POD_type; 77 }; 78 79 template <class _Tp1, class _Tp2> 80 struct _TrivialCopy { 81 typedef typename ::boost::remove_cv<_Tp1>::type uncv1; 82 typedef typename ::boost::remove_cv<_Tp2>::type uncv2; 83 84 enum { same = ::boost::is_same<uncv1, uncv2>::value }; 85 typedef typename __bool2type<same>::_Ret _Same; 86 87 enum { boost_trivial_assign = ::boost::has_trivial_assign<uncv1>::value }; 88 typedef typename __bool2type<boost_trivial_assign>::_Ret _BoostTrivialAssign; 89 typedef typename __type_traits<uncv1>::has_trivial_assignment_operator _STLPTrivialAssign; 90 typedef typename _Lor2<_BoostTrivialAssign, _STLPTrivialAssign>::_Ret _TrivialAssign; 91 92 typedef typename _Land2<_Same, _TrivialAssign>::_Ret _Type; _Answer_TrivialCopy93 static _Type _Answer() { return _Type(); } 94 }; 95 96 template <class _Tp1, class _Tp2> 97 struct _TrivialUCopy { 98 typedef typename ::boost::remove_cv<_Tp1>::type uncv1; 99 typedef typename ::boost::remove_cv<_Tp2>::type uncv2; 100 101 enum { same = ::boost::is_same<uncv1, uncv2>::value }; 102 typedef typename __bool2type<same>::_Ret _Same; 103 104 enum { boost_trivial_copy = ::boost::has_trivial_copy<uncv1>::value }; 105 typedef typename __bool2type<boost_trivial_copy>::_Ret _BoostTrivialCopy; 106 typedef typename __type_traits<uncv1>::has_trivial_copy_constructor _STLPTrivialCopy; 107 typedef typename _Lor2<_BoostTrivialCopy, _STLPTrivialCopy>::_Ret _TrivialCopy; 108 109 typedef typename _Land2<_Same, _TrivialCopy>::_Ret _Type; _Answer_TrivialUCopy110 static _Type _Answer() { return _Type(); } 111 }; 112 113 template <class _Tp> 114 struct _DefaultZeroValue { 115 enum { is_integral = ::boost::is_integral<_Tp>::value }; 116 typedef typename __bool2type<is_integral>::_Ret _IsIntegral; 117 enum { is_float = ::boost::is_float<_Tp>::value }; 118 typedef typename __bool2type<is_float>::_Ret _IsFloat; 119 enum { is_pointer = ::boost::is_pointer<_Tp>::value }; 120 typedef typename __bool2type<is_pointer>::_Ret _IsPointer; 121 122 typedef typename _Lor3<_IsIntegral, _IsFloat, _IsPointer>::_Ret _Ret; 123 }; 124 125 template <class _Tp> 126 struct _TrivialInit { 127 typedef typename ::boost::remove_cv<_Tp>::type uncv; 128 129 enum { boost_trivial_constructor = ::boost::has_trivial_constructor<uncv>::value }; 130 typedef typename __bool2type<boost_trivial_constructor>::_Ret _BoostTrivialInit; 131 typedef typename __type_traits<uncv>::has_trivial_default_constructor _STLPTrivialInit; 132 typedef typename _Lor2<_BoostTrivialInit, _STLPTrivialInit>::_Ret _Tr1; 133 134 typedef typename _DefaultZeroValue<_Tp>::_Ret _Tr2; 135 typedef typename _Not<_Tr2>::_Ret _Tr3; 136 137 typedef typename _Land2<_Tr1, _Tr3>::_Ret _Ret; _Answer_TrivialInit138 static _Ret _Answer() { return _Ret(); } 139 }; 140 141 _STLP_END_NAMESPACE 142 143 #endif /* _STLP_BOOST_TYPE_TRAITS_H */ 144