2 // (C) Copyright John Maddock 2000.
3 // Permission to copy, use, modify, sell and distribute this software is
4 // granted provided this copyright notice appears in all copies. This software
5 // is provided "as is" without express or implied warranty, and with no claim
6 // as to its suitability for any purpose.
8 #ifndef BOOST_TT_ALIGNMENT_OF_HPP_INCLUDED
9 #define BOOST_TT_ALIGNMENT_OF_HPP_INCLUDED
11 #include "boost/config.hpp"
14 // should be the last #include
15 #include "boost/type_traits/detail/size_t_trait_def.hpp"
18 # pragma warning(push)
19 # pragma warning(disable: 4121) // alignment is sensitive to packing
22 #pragma option push -Vx- -Ve-
27 template <typename T> struct alignment_of;
29 // get the alignment of some arbitrary type:
33 struct alignment_of_hack
41 template <unsigned A, unsigned S>
42 struct alignment_logic
44 BOOST_STATIC_CONSTANT(std::size_t, value = A < S ? A : S);
48 template< typename T >
49 struct alignment_of_impl
51 BOOST_STATIC_CONSTANT(std::size_t, value =
52 (::boost::detail::alignment_logic<
53 sizeof(detail::alignment_of_hack<T>) - sizeof(T),
60 BOOST_TT_AUX_SIZE_T_TRAIT_DEF1(alignment_of,T,::boost::detail::alignment_of_impl<T>::value)
62 // references have to be treated specially, assume
63 // that a reference is just a special pointer:
64 #ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
66 struct alignment_of<T&>
72 // long double gives an incorrect value of 10 (!)
73 // unless we do this...
74 struct long_double_wrapper{ long double ld; };
75 template<> struct alignment_of<long double>
76 : public alignment_of<long_double_wrapper>{};
79 // void has to be treated specially:
80 BOOST_TT_AUX_SIZE_T_TRAIT_SPEC1(alignment_of,void,0)
81 #ifndef BOOST_NO_CV_VOID_SPECIALIZATIONS
82 BOOST_TT_AUX_SIZE_T_TRAIT_SPEC1(alignment_of,void const,0)
83 BOOST_TT_AUX_SIZE_T_TRAIT_SPEC1(alignment_of,void volatile,0)
84 BOOST_TT_AUX_SIZE_T_TRAIT_SPEC1(alignment_of,void const volatile,0)
96 #include "boost/type_traits/detail/size_t_trait_undef.hpp"
98 #endif // BOOST_TT_ALIGNMENT_OF_HPP_INCLUDED