source: NonGTP/Boost/boost/type_traits/alignment_of.hpp @ 857

Revision 857, 2.6 KB checked in by igarcia, 18 years ago (diff)
Line 
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// should be the last #include
16#include "boost/type_traits/detail/size_t_trait_def.hpp"
17
18#ifdef BOOST_MSVC
19#   pragma warning(push)
20#   pragma warning(disable: 4121) // alignment is sensitive to packing
21#endif
22#if defined(__BORLANDC__) && (__BORLANDC__ < 0x600)
23#pragma option push -Vx- -Ve-
24#endif
25
26namespace boost {
27
28template <typename T> struct alignment_of;
29
30// get the alignment of some arbitrary type:
31namespace detail {
32
33template <typename T>
34struct alignment_of_hack
35{
36    char c;
37    T t;
38    alignment_of_hack();
39};
40
41
42template <unsigned A, unsigned S>
43struct alignment_logic
44{
45    BOOST_STATIC_CONSTANT(std::size_t, value = A < S ? A : S);
46};
47
48
49template< typename T >
50struct alignment_of_impl
51{
52    BOOST_STATIC_CONSTANT(std::size_t, value =
53        (::boost::detail::alignment_logic<
54            sizeof(detail::alignment_of_hack<T>) - sizeof(T),
55            sizeof(T)
56        >::value));
57};
58
59} // namespace detail
60
61BOOST_TT_AUX_SIZE_T_TRAIT_DEF1(alignment_of,T,::boost::detail::alignment_of_impl<T>::value)
62
63// references have to be treated specially, assume
64// that a reference is just a special pointer:
65#ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
66template <typename T>
67struct alignment_of<T&>
68    : alignment_of<T*>
69{
70};
71#endif
72#ifdef __BORLANDC__
73// long double gives an incorrect value of 10 (!)
74// unless we do this...
75struct long_double_wrapper{ long double ld; };
76template<> struct alignment_of<long double>
77   : public alignment_of<long_double_wrapper>{};
78#endif
79
80// void has to be treated specially:
81BOOST_TT_AUX_SIZE_T_TRAIT_SPEC1(alignment_of,void,0)
82#ifndef BOOST_NO_CV_VOID_SPECIALIZATIONS
83BOOST_TT_AUX_SIZE_T_TRAIT_SPEC1(alignment_of,void const,0)
84BOOST_TT_AUX_SIZE_T_TRAIT_SPEC1(alignment_of,void volatile,0)
85BOOST_TT_AUX_SIZE_T_TRAIT_SPEC1(alignment_of,void const volatile,0)
86#endif
87
88} // namespace boost
89
90#if defined(__BORLANDC__) && (__BORLANDC__ < 0x600)
91#pragma option pop
92#endif
93#ifdef BOOST_MSVC
94#   pragma warning(pop)
95#endif
96
97#include "boost/type_traits/detail/size_t_trait_undef.hpp"
98
99#endif // BOOST_TT_ALIGNMENT_OF_HPP_INCLUDED
100
Note: See TracBrowser for help on using the repository browser.