6 * This material is provided "as is", with absolutely no warranty expressed
7 * or implied. Any use is at your own risk.
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.
17 #ifndef _STLP_BOOST_TYPE_TRAITS_H
18 #define _STLP_BOOST_TYPE_TRAITS_H
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>
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.
41 template <class _Tp> struct _IsRef {
42 enum { _Is = ::boost::is_reference<_Tp>::value };
43 typedef typename __bool2type<_Is>::_Ret _Ret;
46 template <class _Tp> struct _IsPtr {
47 enum { is_pointer = ::boost::is_pointer<_Tp>::value };
48 typedef typename __bool2type<is_pointer>::_Ret _Ret;
51 template <class _Tp> struct _IsIntegral {
52 enum { is_integral = ::boost::is_integral<_Tp>::value };
53 typedef typename __bool2type<is_integral>::_Ret _Ret;
56 template <class _Tp> struct _IsRational {
57 enum { is_float = ::boost::is_float<_Tp>::value };
58 typedef typename __bool2type<is_float>::_Ret _Ret;
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;
66 enum { trivial_copy = ::boost::has_trivial_copy<_Tp>::value };
67 typedef typename __bool2type<trivial_copy>::_Ret has_trivial_copy_constructor;
69 enum { trivial_assign = ::boost::has_trivial_assign<_Tp>::value };
70 typedef typename __bool2type<trivial_assign>::_Ret has_trivial_assignment_operator;
72 enum { trivial_destructor = ::boost::has_trivial_destructor<_Tp>::value };
73 typedef typename __bool2type<trivial_destructor>::_Ret has_trivial_destructor;
75 enum { pod = ::boost::is_pod<_Tp>::value };
76 typedef typename __bool2type<pod>::_Ret is_POD_type;
79 template <class _Tp1, class _Tp2>
81 typedef typename ::boost::remove_cv<_Tp1>::type uncv1;
82 typedef typename ::boost::remove_cv<_Tp2>::type uncv2;
84 enum { same = ::boost::is_same<uncv1, uncv2>::value };
85 typedef typename __bool2type<same>::_Ret _Same;
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;
92 typedef typename _Land2<_Same, _TrivialAssign>::_Ret _Type;
93 static _Type _Answer() { return _Type(); }
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;
101 enum { same = ::boost::is_same<uncv1, uncv2>::value };
102 typedef typename __bool2type<same>::_Ret _Same;
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;
109 typedef typename _Land2<_Same, _TrivialCopy>::_Ret _Type;
110 static _Type _Answer() { return _Type(); }
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;
122 typedef typename _Lor3<_IsIntegral, _IsFloat, _IsPointer>::_Ret _Ret;
126 struct _TrivialInit {
127 typedef typename ::boost::remove_cv<_Tp>::type uncv;
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;
134 typedef typename _DefaultZeroValue<_Tp>::_Ret _Tr2;
135 typedef typename _Not<_Tr2>::_Ret _Tr3;
137 typedef typename _Land2<_Tr1, _Tr3>::_Ret _Ret;
138 static _Ret _Answer() { return _Ret(); }
143 #endif /* _STLP_BOOST_TYPE_TRAITS_H */