1 
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).
6 //
7 //  See http://www.boost.org/libs/type_traits for most recent version including documentation.
8 
9 #ifndef BOOST_TT_ALIGNMENT_OF_HPP_INCLUDED
10 #define BOOST_TT_ALIGNMENT_OF_HPP_INCLUDED
11 
12 #include "boost/config.hpp"
13 #include <cstddef>
14 
15 // should be the last #include
16 #include "boost/type_traits/detail/size_t_trait_def.hpp"
17 
18 #ifdef BOOST_MSVC
19 #   pragma warning(push)
20 #   pragma warning(disable: 4121) // alignment is sensitive to packing
21 #endif
22 #if defined(__BORLANDC__) && (__BORLANDC__ < 0x600)
23 #pragma option push -Vx- -Ve-
24 #endif
25 
26 namespace boost {
27 
28 template <typename T> struct alignment_of;
29 
30 // get the alignment of some arbitrary type:
31 namespace detail {
32 
33 template <typename T>
34 struct alignment_of_hack
35 {
36     char c;
37     T t;
38     alignment_of_hack();
39 };
40 
41 
42 template <unsigned A, unsigned S>
43 struct alignment_logic
44 {
45     BOOST_STATIC_CONSTANT(std::size_t, value = A < S ? A : S);
46 };
47 
48 
49 template< typename T >
50 struct alignment_of_impl
51 {
52     BOOST_STATIC_CONSTANT(std::size_t, value =
53         (::boost::detail::alignment_logic<
54             sizeof(detail::alignment_of_hack<T>) - sizeof(T),
55             sizeof(T)
56         >::value));
57 };
58 
59 } // namespace detail
60 
61 BOOST_TT_AUX_SIZE_T_TRAIT_DEF1(alignment_of,T,::boost::detail::alignment_of_impl<T>::value)
62 
63 // references have to be treated specially, assume
64 // that a reference is just a special pointer:
65 #ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
66 template <typename T>
67 struct alignment_of<T&>
68     : alignment_of<T*>
69 {
70 };
71 #endif
72 #ifdef __BORLANDC__
73 // long double gives an incorrect value of 10 (!)
74 // unless we do this...
75 struct long_double_wrapper{ long double ld; };
76 template<> struct alignment_of<long double>
77    : public alignment_of<long_double_wrapper>{};
78 #endif
79 
80 // void has to be treated specially:
81 BOOST_TT_AUX_SIZE_T_TRAIT_SPEC1(alignment_of,void,0)
82 #ifndef BOOST_NO_CV_VOID_SPECIALIZATIONS
83 BOOST_TT_AUX_SIZE_T_TRAIT_SPEC1(alignment_of,void const,0)
84 BOOST_TT_AUX_SIZE_T_TRAIT_SPEC1(alignment_of,void volatile,0)
85 BOOST_TT_AUX_SIZE_T_TRAIT_SPEC1(alignment_of,void const volatile,0)
86 #endif
87 
88 } // namespace boost
89 
90 #if defined(__BORLANDC__) && (__BORLANDC__ < 0x600)
91 #pragma option pop
92 #endif
93 #ifdef BOOST_MSVC
94 #   pragma warning(pop)
95 #endif
96 
97 #include "boost/type_traits/detail/size_t_trait_undef.hpp"
98 
99 #endif // BOOST_TT_ALIGNMENT_OF_HPP_INCLUDED
100 
101