fixing stuff
[dyninst.git] / dynutil / h / dyn_detail / boost / type_traits / alignment_of.hpp
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 DYN_DETAIL_BOOST_TT_ALIGNMENT_OF_HPP_INCLUDED
10 #define DYN_DETAIL_BOOST_TT_ALIGNMENT_OF_HPP_INCLUDED
11
12 #include <dyn_detail/boost/config.hpp>
13 #include <cstddef>
14
15 #include <dyn_detail/boost/type_traits/intrinsics.hpp>
16 // should be the last #include
17 #include <dyn_detail/boost/type_traits/detail/size_t_trait_def.hpp>
18
19 #ifdef DYN_DETAIL_BOOST_MSVC
20 #   pragma warning(push)
21 #   pragma warning(disable: 4121 4512) // alignment is sensitive to packing
22 #endif
23 #if defined(__BORLANDC__) && (__BORLANDC__ < 0x600)
24 #pragma option push -Vx- -Ve-
25 #endif
26
27 namespace dyn_detail {
28 namespace boost {
29
30 template <typename T> struct alignment_of;
31
32 // get the alignment of some arbitrary type:
33 namespace detail {
34
35 #ifdef DYN_DETAIL_BOOST_MSVC
36 #pragma warning(push)
37 #pragma warning(disable:4324) // structure was padded due to __declspec(align())
38 #endif
39 template <typename T>
40 struct alignment_of_hack
41 {
42     char c;
43     T t;
44     alignment_of_hack();
45 };
46 #ifdef DYN_DETAIL_BOOST_MSVC
47 #pragma warning(pop)
48 #endif
49
50 template <unsigned A, unsigned S>
51 struct alignment_logic
52 {
53     DYN_DETAIL_BOOST_STATIC_CONSTANT(std::size_t, value = A < S ? A : S);
54 };
55
56
57 template< typename T >
58 struct alignment_of_impl
59 {
60 #ifndef DYN_DETAIL_BOOST_ALIGNMENT_OF
61     DYN_DETAIL_BOOST_STATIC_CONSTANT(std::size_t, value =
62         (::dyn_detail::boost::detail::alignment_logic<
63             sizeof(::dyn_detail::boost::detail::alignment_of_hack<T>) - sizeof(T),
64             sizeof(T)
65         >::value));
66 #else
67    //
68    // We put this here, rather than in the definition of
69    // alignment_of below, because MSVC's __alignof doesn't
70    // always work in that context for some unexplained reason.
71    // (See type_with_alignment tests for test cases).
72    //
73    DYN_DETAIL_BOOST_STATIC_CONSTANT(std::size_t, value = DYN_DETAIL_BOOST_ALIGNMENT_OF(T));
74 #endif
75 };
76
77 } // namespace detail
78
79 DYN_DETAIL_BOOST_TT_AUX_SIZE_T_TRAIT_DEF1(alignment_of,T,::dyn_detail::boost::detail::alignment_of_impl<T>::value)
80
81 // references have to be treated specially, assume
82 // that a reference is just a special pointer:
83 #ifndef DYN_DETAIL_BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
84 template <typename T>
85 struct alignment_of<T&>
86     : alignment_of<T*>
87 {
88 };
89 #endif
90 #ifdef __BORLANDC__
91 // long double gives an incorrect value of 10 (!)
92 // unless we do this...
93 struct long_double_wrapper{ long double ld; };
94 template<> struct alignment_of<long double>
95    : public alignment_of<long_double_wrapper>{};
96 #endif
97
98 // void has to be treated specially:
99 DYN_DETAIL_BOOST_TT_AUX_SIZE_T_TRAIT_SPEC1(alignment_of,void,0)
100 #ifndef DYN_DETAIL_BOOST_NO_CV_VOID_SPECIALIZATIONS
101 DYN_DETAIL_BOOST_TT_AUX_SIZE_T_TRAIT_SPEC1(alignment_of,void const,0)
102 DYN_DETAIL_BOOST_TT_AUX_SIZE_T_TRAIT_SPEC1(alignment_of,void volatile,0)
103 DYN_DETAIL_BOOST_TT_AUX_SIZE_T_TRAIT_SPEC1(alignment_of,void const volatile,0)
104 #endif
105
106 } // namespace boost
107 } // namespace dyn_detail
108
109 #if defined(__BORLANDC__) && (__BORLANDC__ < 0x600)
110 #pragma option pop
111 #endif
112 #ifdef DYN_DETAIL_BOOST_MSVC
113 #   pragma warning(pop)
114 #endif
115
116 #include <dyn_detail/boost/type_traits/detail/size_t_trait_undef.hpp>
117
118 #endif // DYN_DETAIL_BOOST_TT_ALIGNMENT_OF_HPP_INCLUDED
119