]> git.lyx.org Git - lyx.git/blob - boost/boost/type_traits/alignment_of.hpp
update boost to version 1.36
[lyx.git] / boost / 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 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 #include <boost/type_traits/intrinsics.hpp>
16 // should be the last #include
17 #include <boost/type_traits/detail/size_t_trait_def.hpp>
18
19 #ifdef 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 boost {
28
29 template <typename T> struct alignment_of;
30
31 // get the alignment of some arbitrary type:
32 namespace detail {
33
34 #ifdef BOOST_MSVC
35 #pragma warning(push)
36 #pragma warning(disable:4324) // structure was padded due to __declspec(align())
37 #endif
38 template <typename T>
39 struct alignment_of_hack
40 {
41     char c;
42     T t;
43     alignment_of_hack();
44 };
45 #ifdef BOOST_MSVC
46 #pragma warning(pop)
47 #endif
48
49 template <unsigned A, unsigned S>
50 struct alignment_logic
51 {
52     BOOST_STATIC_CONSTANT(std::size_t, value = A < S ? A : S);
53 };
54
55
56 template< typename T >
57 struct alignment_of_impl
58 {
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),
63             sizeof(T)
64         >::value));
65 #else
66    //
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).
71    //
72    BOOST_STATIC_CONSTANT(std::size_t, value = BOOST_ALIGNMENT_OF(T));
73 #endif
74 };
75
76 } // namespace detail
77
78 BOOST_TT_AUX_SIZE_T_TRAIT_DEF1(alignment_of,T,::boost::detail::alignment_of_impl<T>::value)
79
80 // references have to be treated specially, assume
81 // that a reference is just a special pointer:
82 #ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
83 template <typename T>
84 struct alignment_of<T&>
85     : alignment_of<T*>
86 {
87 };
88 #endif
89 #ifdef __BORLANDC__
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>{};
95 #endif
96
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)
103 #endif
104
105 } // namespace boost
106
107 #if defined(__BORLANDC__) && (__BORLANDC__ < 0x600)
108 #pragma option pop
109 #endif
110 #ifdef BOOST_MSVC
111 #   pragma warning(pop)
112 #endif
113
114 #include <boost/type_traits/detail/size_t_trait_undef.hpp>
115
116 #endif // BOOST_TT_ALIGNMENT_OF_HPP_INCLUDED
117