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