/home/ntakagi/work/STLport-5.1.5/stlport/stl/boost_type_traits.h

Go to the documentation of this file.
00001 /*
00002  *
00003  * Copyright (c) 2004
00004  * Francois Dumont
00005  *
00006  * This material is provided "as is", with absolutely no warranty expressed
00007  * or implied. Any use is at your own risk.
00008  *
00009  * Permission to use or copy this software for any purpose is hereby granted
00010  * without fee, provided the above notices are retained on all copies.
00011  * Permission to modify the code and to distribute modified code is granted,
00012  * provided the above notices are retained, and a notice that the code was
00013  * modified is included with the above copyright notice.
00014  *
00015  */
00016 
00017 #ifndef _STLP_BOOST_TYPE_TRAITS_H
00018 #define _STLP_BOOST_TYPE_TRAITS_H
00019 
00020 #include <boost/type_traits/is_integral.hpp>
00021 #include <boost/type_traits/is_float.hpp>
00022 #include <boost/type_traits/has_trivial_constructor.hpp>
00023 #include <boost/type_traits/has_trivial_copy.hpp>
00024 #include <boost/type_traits/has_trivial_assign.hpp>
00025 #include <boost/type_traits/has_trivial_destructor.hpp>
00026 #include <boost/type_traits/is_pod.hpp>
00027 #include <boost/type_traits/is_pointer.hpp>
00028 #include <boost/type_traits/is_reference.hpp>
00029 #include <boost/type_traits/remove_cv.hpp>
00030 #include <boost/type_traits/is_same.hpp>
00031 
00032 /*
00033  * This file mostly wraps boost type_traits in the STLport type_traits.
00034  * When checking a type traits like trivial assign operator for instance
00035  * both the boost value and STLport values has to be taken into account
00036  * as we don't know what the user might have prefer, specializing the boost
00037  * type traits or the STLport one.
00038  */
00039 _STLP_BEGIN_NAMESPACE
00040 
00041 template <class _Tp> struct _IsRef {
00042   enum { _Is = ::boost::is_reference<_Tp>::value };
00043   typedef typename __bool2type<_Is>::_Ret _Ret;
00044 };
00045 
00046 template <class _Tp> struct _IsPtr {
00047   enum { is_pointer = ::boost::is_pointer<_Tp>::value };
00048   typedef typename __bool2type<is_pointer>::_Ret _Ret;
00049 };
00050 
00051 template <class _Tp> struct _IsIntegral {
00052   enum { is_integral = ::boost::is_integral<_Tp>::value };
00053   typedef typename __bool2type<is_integral>::_Ret _Ret;
00054 };
00055 
00056 template <class _Tp> struct _IsRational {
00057   enum { is_float = ::boost::is_float<_Tp>::value };
00058   typedef typename __bool2type<is_float>::_Ret _Ret;
00059 };
00060 
00061 template <class _Tp>
00062 struct __type_traits {
00063   enum { trivial_constructor = ::boost::has_trivial_constructor<_Tp>::value };
00064   typedef typename __bool2type<trivial_constructor>::_Ret has_trivial_default_constructor;
00065 
00066   enum { trivial_copy = ::boost::has_trivial_copy<_Tp>::value };
00067   typedef typename __bool2type<trivial_copy>::_Ret has_trivial_copy_constructor;
00068 
00069   enum { trivial_assign = ::boost::has_trivial_assign<_Tp>::value };
00070   typedef typename __bool2type<trivial_assign>::_Ret has_trivial_assignment_operator;
00071 
00072   enum { trivial_destructor = ::boost::has_trivial_destructor<_Tp>::value };
00073   typedef typename __bool2type<trivial_destructor>::_Ret has_trivial_destructor;
00074 
00075   enum { pod = ::boost::is_pod<_Tp>::value };
00076   typedef typename __bool2type<pod>::_Ret is_POD_type;
00077 };
00078 
00079 template <class _Tp1, class _Tp2>
00080 struct _TrivialCopy {
00081   typedef typename ::boost::remove_cv<_Tp1>::type uncv1;
00082   typedef typename ::boost::remove_cv<_Tp2>::type uncv2;
00083 
00084   enum { same = ::boost::is_same<uncv1, uncv2>::value };
00085   typedef typename __bool2type<same>::_Ret _Same;
00086 
00087   enum { boost_trivial_assign = ::boost::has_trivial_assign<uncv1>::value };
00088   typedef typename __bool2type<boost_trivial_assign>::_Ret _BoostTrivialAssign;
00089   typedef typename __type_traits<uncv1>::has_trivial_assignment_operator _STLPTrivialAssign;
00090   typedef typename _Lor2<_BoostTrivialAssign, _STLPTrivialAssign>::_Ret _TrivialAssign;
00091 
00092   typedef typename _Land2<_Same, _TrivialAssign>::_Ret _Type;
00093   static _Type _Answer() { return _Type(); }
00094 };
00095 
00096 template <class _Tp1, class _Tp2>
00097 struct _TrivialUCopy {
00098   typedef typename ::boost::remove_cv<_Tp1>::type uncv1;
00099   typedef typename ::boost::remove_cv<_Tp2>::type uncv2;
00100 
00101   enum { same = ::boost::is_same<uncv1, uncv2>::value };
00102   typedef typename __bool2type<same>::_Ret _Same;
00103 
00104   enum { boost_trivial_copy = ::boost::has_trivial_copy<uncv1>::value };
00105   typedef typename __bool2type<boost_trivial_copy>::_Ret _BoostTrivialCopy;
00106   typedef typename __type_traits<uncv1>::has_trivial_copy_constructor _STLPTrivialCopy;
00107   typedef typename _Lor2<_BoostTrivialCopy, _STLPTrivialCopy>::_Ret _TrivialCopy;
00108 
00109   typedef typename _Land2<_Same, _TrivialCopy>::_Ret _Type;
00110   static _Type _Answer() { return _Type(); }
00111 };
00112 
00113 template <class _Tp>
00114 struct _DefaultZeroValue {
00115   enum { is_integral = ::boost::is_integral<_Tp>::value };
00116   typedef typename __bool2type<is_integral>::_Ret _IsIntegral;
00117   enum { is_float = ::boost::is_float<_Tp>::value };
00118   typedef typename __bool2type<is_float>::_Ret _IsFloat;
00119   enum { is_pointer = ::boost::is_pointer<_Tp>::value };
00120   typedef typename __bool2type<is_pointer>::_Ret _IsPointer;
00121 
00122   typedef typename _Lor3<_IsIntegral, _IsFloat, _IsPointer>::_Ret _Ret;
00123 };
00124 
00125 template <class _Tp>
00126 struct _TrivialInit {
00127   typedef typename ::boost::remove_cv<_Tp>::type uncv;
00128 
00129   enum { boost_trivial_constructor = ::boost::has_trivial_constructor<uncv>::value };
00130   typedef typename __bool2type<boost_trivial_constructor>::_Ret _BoostTrivialInit;
00131   typedef typename __type_traits<uncv>::has_trivial_default_constructor _STLPTrivialInit;
00132   typedef typename _Lor2<_BoostTrivialInit, _STLPTrivialInit>::_Ret _Tr1;
00133 
00134   typedef typename _DefaultZeroValue<_Tp>::_Ret _Tr2;
00135   typedef typename _Not<_Tr2>::_Ret _Tr3;
00136 
00137   typedef typename _Land2<_Tr1, _Tr3>::_Ret _Ret;
00138   static _Ret _Answer() { return _Ret(); }
00139 };
00140 
00141 _STLP_END_NAMESPACE
00142 
00143 #endif /* _STLP_BOOST_TYPE_TRAITS_H */



Generated on Mon Mar 10 15:32:46 2008 by  doxygen 1.5.1