]> git.lyx.org Git - lyx.git/blob - boost/boost/type_traits/alignment_traits.hpp
update from boost cvs
[lyx.git] / boost / boost / type_traits / alignment_traits.hpp
1
2 //  (C) Copyright John Maddock 2000.
3 //  Permission to copy, use, modify, sell and
4 //  distribute this software is granted provided this copyright notice appears
5 //  in all copies. This software is provided "as is" without express or implied
6 //  warranty, and with no claim as to its suitability for any purpose.
7
8 //
9 // defines alignment_of:
10
11 #ifndef ALIGNMENT_TYPE_TRAITS_HPP
12 #define ALIGNMENT_TYPE_TRAITS_HPP
13
14 #include <cstdlib>
15 #include <cstddef>
16 #ifndef BOOST_ICE_TYPE_TRAITS_HPP
17 #include <boost/type_traits/ice.hpp>
18 #endif
19
20 namespace boost{
21 //
22 // get the alignment of some arbitrary type:
23 namespace detail{
24
25 template <class T>
26 struct alignment_of_hack
27 {
28    char c;
29    T t;
30    alignment_of_hack();
31 };
32
33 template <unsigned A, unsigned S>
34 struct alignment_logic
35 {
36    BOOST_STATIC_CONSTANT(std::size_t, value = A < S ? A : S);
37 };
38
39 } // namespace detail
40
41 template <class T>
42 struct alignment_of
43 {
44    BOOST_STATIC_CONSTANT(std::size_t, value =
45       (::boost::detail::alignment_logic<
46          sizeof(detail::alignment_of_hack<T>) - sizeof(T),
47          sizeof(T)
48       >::value));
49 };
50
51 //
52 // references have to be treated specially, assume
53 // that a reference is just a special pointer:
54 #ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
55 template <class T>
56 struct alignment_of<T&>
57 {
58 public:
59    BOOST_STATIC_CONSTANT(std::size_t, value = alignment_of<T*>::value);
60 };
61 #endif
62 //
63 // void has to be treated specially:
64 template <>
65 struct alignment_of<void>
66 { BOOST_STATIC_CONSTANT(std::size_t, value = 0); };
67 #ifndef BOOST_NO_CV_VOID_SPECIALIZATIONS
68 template <>
69 struct alignment_of<const void>
70 { BOOST_STATIC_CONSTANT(std::size_t, value = 0); };
71 template <>
72 struct alignment_of<volatile void>
73 { BOOST_STATIC_CONSTANT(std::size_t, value = 0); };
74 template <>
75 struct alignment_of<const volatile void>
76 { BOOST_STATIC_CONSTANT(std::size_t, value = 0); };
77 #endif
78
79 } // namespace boost
80
81 #endif // ALIGNMENT_TYPE_TRAITS_HPP
82
83  
84