00001
00002
00003
00004
00005
00006
00007
00008
00009 #ifndef BOOST_TT_ALIGNMENT_OF_HPP_INCLUDED
00010 #define BOOST_TT_ALIGNMENT_OF_HPP_INCLUDED
00011
00012 #include <boost/config.hpp>
00013 #include <cstddef>
00014
00015 #include <boost/type_traits/intrinsics.hpp>
00016
00017 #include <boost/type_traits/detail/size_t_trait_def.hpp>
00018
00019 #ifdef BOOST_MSVC
00020 # pragma warning(push)
00021 # pragma warning(disable: 4121 4512) // alignment is sensitive to packing
00022 #endif
00023 #if defined(__BORLANDC__) && (__BORLANDC__ < 0x600)
00024 #pragma option push -Vx- -Ve-
00025 #endif
00026
00027 namespace boost {
00028
00029 template <typename T> struct alignment_of;
00030
00031
00032 namespace detail {
00033
00034 #ifdef BOOST_MSVC
00035 #pragma warning(push)
00036 #pragma warning(disable:4324) // structure was padded due to __declspec(align())
00037 #endif
00038 template <typename T>
00039 struct alignment_of_hack
00040 {
00041 char c;
00042 T t;
00043 alignment_of_hack();
00044 };
00045 #ifdef BOOST_MSVC
00046 #pragma warning(pop)
00047 #endif
00048
00049 template <unsigned A, unsigned S>
00050 struct alignment_logic
00051 {
00052 BOOST_STATIC_CONSTANT(std::size_t, value = A < S ? A : S);
00053 };
00054
00055
00056 template< typename T >
00057 struct alignment_of_impl
00058 {
00059 #if defined(BOOST_MSVC) && (BOOST_MSVC >= 1400)
00060
00061
00062
00063
00064
00065 BOOST_STATIC_CONSTANT(std::size_t, value =
00066 (::boost::detail::alignment_logic<
00067 sizeof(::boost::detail::alignment_of_hack<T>) - sizeof(T),
00068 __alignof(T)
00069 >::value));
00070 #elif !defined(BOOST_ALIGNMENT_OF)
00071 BOOST_STATIC_CONSTANT(std::size_t, value =
00072 (::boost::detail::alignment_logic<
00073 sizeof(::boost::detail::alignment_of_hack<T>) - sizeof(T),
00074 sizeof(T)
00075 >::value));
00076 #else
00077
00078
00079
00080
00081
00082
00083 BOOST_STATIC_CONSTANT(std::size_t, value = BOOST_ALIGNMENT_OF(T));
00084 #endif
00085 };
00086
00087 }
00088
00089 BOOST_TT_AUX_SIZE_T_TRAIT_DEF1(alignment_of,T,::boost::detail::alignment_of_impl<T>::value)
00090
00091
00092
00093 #ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
00094 template <typename T>
00095 struct alignment_of<T&>
00096 : alignment_of<T*>
00097 {
00098 };
00099 #endif
00100 #ifdef __BORLANDC__
00101
00102
00103 struct long_double_wrapper{ long double ld; };
00104 template<> struct alignment_of<long double>
00105 : public alignment_of<long_double_wrapper>{};
00106 #endif
00107
00108
00109 BOOST_TT_AUX_SIZE_T_TRAIT_SPEC1(alignment_of,void,0)
00110 #ifndef BOOST_NO_CV_VOID_SPECIALIZATIONS
00111 BOOST_TT_AUX_SIZE_T_TRAIT_SPEC1(alignment_of,void const,0)
00112 BOOST_TT_AUX_SIZE_T_TRAIT_SPEC1(alignment_of,void volatile,0)
00113 BOOST_TT_AUX_SIZE_T_TRAIT_SPEC1(alignment_of,void const volatile,0)
00114 #endif
00115
00116 }
00117
00118 #if defined(__BORLANDC__) && (__BORLANDC__ < 0x600)
00119 #pragma option pop
00120 #endif
00121 #ifdef BOOST_MSVC
00122 # pragma warning(pop)
00123 #endif
00124
00125 #include <boost/type_traits/detail/size_t_trait_undef.hpp>
00126
00127 #endif // BOOST_TT_ALIGNMENT_OF_HPP_INCLUDED
00128