]> git.lyx.org Git - lyx.git/blob - boost/boost/type_traits/alignment_of.hpp
update to boost 1.30.1
[lyx.git] / boost / boost / type_traits / alignment_of.hpp
1
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.
7
8 #ifndef BOOST_TT_ALIGNMENT_OF_HPP_INCLUDED
9 #define BOOST_TT_ALIGNMENT_OF_HPP_INCLUDED
10
11 #include "boost/config.hpp"
12 #include <cstddef>
13
14 // should be the last #include
15 #include "boost/type_traits/detail/size_t_trait_def.hpp"
16
17 #ifdef BOOST_MSVC
18 #   pragma warning(push)
19 #   pragma warning(disable: 4121) // alignment is sensitive to packing
20 #endif
21 #ifdef __BORLANDC__
22 #pragma option push -Vx- -Ve-
23 #endif
24
25 namespace boost {
26
27 template <typename T> struct alignment_of;
28
29 // get the alignment of some arbitrary type:
30 namespace detail {
31
32 template <typename T>
33 struct alignment_of_hack
34 {
35     char c;
36     T t;
37     alignment_of_hack();
38 };
39
40
41 template <unsigned A, unsigned S>
42 struct alignment_logic
43 {
44     BOOST_STATIC_CONSTANT(std::size_t, value = A < S ? A : S);
45 };
46
47
48 template< typename T >
49 struct alignment_of_impl
50 {
51     BOOST_STATIC_CONSTANT(std::size_t, value =
52         (::boost::detail::alignment_logic<
53             sizeof(detail::alignment_of_hack<T>) - sizeof(T),
54             sizeof(T)
55         >::value));
56 };
57
58 } // namespace detail
59
60 BOOST_TT_AUX_SIZE_T_TRAIT_DEF1(alignment_of,T,::boost::detail::alignment_of_impl<T>::value)
61
62 // references have to be treated specially, assume
63 // that a reference is just a special pointer:
64 #ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
65 template <typename T>
66 struct alignment_of<T&>
67     : alignment_of<T*>
68 {
69 };
70 #endif
71 #ifdef __BORLANDC__
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>{};
77 #endif
78
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)
85 #endif
86
87 } // namespace boost
88
89 #ifdef __BORLANDC__
90 #pragma option pop
91 #endif
92 #ifdef BOOST_MSVC
93 #   pragma warning(pop)
94 #endif
95
96 #include "boost/type_traits/detail/size_t_trait_undef.hpp"
97
98 #endif // BOOST_TT_ALIGNMENT_OF_HPP_INCLUDED
99