2 // (C) Copyright John Maddock 2000.
3 // Use, modification and distribution are subject to the Boost Software License,
4 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
5 // http://www.boost.org/LICENSE_1_0.txt).
7 // See http://www.boost.org/libs/type_traits for most recent version including documentation.
9 #ifndef BOOST_TT_ALIGNMENT_OF_HPP_INCLUDED
10 #define BOOST_TT_ALIGNMENT_OF_HPP_INCLUDED
12 #include <boost/config.hpp>
15 #include <boost/type_traits/intrinsics.hpp>
16 // should be the last #include
17 #include <boost/type_traits/detail/size_t_trait_def.hpp>
20 # pragma warning(push)
21 # pragma warning(disable: 4121 4512) // alignment is sensitive to packing
23 #if defined(__BORLANDC__) && (__BORLANDC__ < 0x600)
24 #pragma option push -Vx- -Ve-
29 template <typename T> struct alignment_of;
31 // get the alignment of some arbitrary type:
36 #pragma warning(disable:4324) // structure was padded due to __declspec(align())
39 struct alignment_of_hack
49 template <unsigned A, unsigned S>
50 struct alignment_logic
52 BOOST_STATIC_CONSTANT(std::size_t, value = A < S ? A : S);
56 template< typename T >
57 struct alignment_of_impl
59 #ifndef BOOST_ALIGNMENT_OF
60 BOOST_STATIC_CONSTANT(std::size_t, value =
61 (::boost::detail::alignment_logic<
62 sizeof(::boost::detail::alignment_of_hack<T>) - sizeof(T),
67 // We put this here, rather than in the definition of
68 // alignment_of below, because MSVC's __alignof doesn't
69 // always work in that context for some unexplained reason.
70 // (See type_with_alignment tests for test cases).
72 BOOST_STATIC_CONSTANT(std::size_t, value = BOOST_ALIGNMENT_OF(T));
78 BOOST_TT_AUX_SIZE_T_TRAIT_DEF1(alignment_of,T,::boost::detail::alignment_of_impl<T>::value)
80 // references have to be treated specially, assume
81 // that a reference is just a special pointer:
82 #ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
84 struct alignment_of<T&>
90 // long double gives an incorrect value of 10 (!)
91 // unless we do this...
92 struct long_double_wrapper{ long double ld; };
93 template<> struct alignment_of<long double>
94 : public alignment_of<long_double_wrapper>{};
97 // void has to be treated specially:
98 BOOST_TT_AUX_SIZE_T_TRAIT_SPEC1(alignment_of,void,0)
99 #ifndef BOOST_NO_CV_VOID_SPECIALIZATIONS
100 BOOST_TT_AUX_SIZE_T_TRAIT_SPEC1(alignment_of,void const,0)
101 BOOST_TT_AUX_SIZE_T_TRAIT_SPEC1(alignment_of,void volatile,0)
102 BOOST_TT_AUX_SIZE_T_TRAIT_SPEC1(alignment_of,void const volatile,0)
107 #if defined(__BORLANDC__) && (__BORLANDC__ < 0x600)
111 # pragma warning(pop)
114 #include <boost/type_traits/detail/size_t_trait_undef.hpp>
116 #endif // BOOST_TT_ALIGNMENT_OF_HPP_INCLUDED