]> git.lyx.org Git - lyx.git/blob - boost/boost/type_traits/alignment_of.hpp
complie fix
[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
22 namespace boost {
23
24 template <typename T> struct alignment_of;
25
26 // get the alignment of some arbitrary type:
27 namespace detail {
28
29 template <typename T>
30 struct alignment_of_hack
31 {
32     char c;
33     T t;
34     alignment_of_hack();
35 };
36
37
38 template <unsigned A, unsigned S>
39 struct alignment_logic
40 {
41     BOOST_STATIC_CONSTANT(std::size_t, value = A < S ? A : S);
42 };
43
44
45 template< typename T >
46 struct alignment_of_impl
47 {
48     BOOST_STATIC_CONSTANT(std::size_t, value =
49         (::boost::detail::alignment_logic<
50             sizeof(detail::alignment_of_hack<T>) - sizeof(T),
51             sizeof(T)
52         >::value));
53 };
54
55 } // namespace detail
56
57 BOOST_TT_AUX_SIZE_T_TRAIT_DEF1(alignment_of,T,::boost::detail::alignment_of_impl<T>::value)
58
59 // references have to be treated specially, assume
60 // that a reference is just a special pointer:
61 #ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
62 template <typename T>
63 struct alignment_of<T&>
64     : alignment_of<T*>
65 {
66 };
67 #endif
68
69 // void has to be treated specially:
70 BOOST_TT_AUX_SIZE_T_TRAIT_SPEC1(alignment_of,void,0)
71 #ifndef BOOST_NO_CV_VOID_SPECIALIZATIONS
72 BOOST_TT_AUX_SIZE_T_TRAIT_SPEC1(alignment_of,void const,0)
73 BOOST_TT_AUX_SIZE_T_TRAIT_SPEC1(alignment_of,void volatile,0)
74 BOOST_TT_AUX_SIZE_T_TRAIT_SPEC1(alignment_of,void const volatile,0)
75 #endif
76
77 } // namespace boost
78
79 #ifdef BOOST_MSVC
80 #   pragma warning(pop)
81 #endif
82
83 #include "boost/type_traits/detail/size_t_trait_undef.hpp"
84
85 #endif // BOOST_TT_ALIGNMENT_OF_HPP_INCLUDED