Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-30 10:01:38

0001 
0002 //  (C) Copyright John Maddock 2000.
0003 //  Use, modification and distribution are subject to the Boost Software License,
0004 //  Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
0005 //  http://www.boost.org/LICENSE_1_0.txt).
0006 //
0007 //  See http://www.boost.org/libs/type_traits for most recent version including documentation.
0008 
0009 #ifndef BOOST_TT_ALIGNMENT_OF_HPP_INCLUDED
0010 #define BOOST_TT_ALIGNMENT_OF_HPP_INCLUDED
0011 
0012 #include <boost/config.hpp>
0013 #include <cstddef>
0014 
0015 #include <boost/type_traits/intrinsics.hpp>
0016 #include <boost/type_traits/integral_constant.hpp>
0017 
0018 #ifdef BOOST_MSVC
0019 #   pragma warning(push)
0020 #   pragma warning(disable: 4121 4512) // alignment is sensitive to packing
0021 #endif
0022 #if defined(BOOST_BORLANDC) && (BOOST_BORLANDC < 0x600)
0023 #pragma option push -Vx- -Ve-
0024 #endif
0025 
0026 namespace boost {
0027 
0028 template <typename T> struct alignment_of;
0029 
0030 // get the alignment of some arbitrary type:
0031 namespace detail {
0032 
0033 #ifdef BOOST_MSVC
0034 #pragma warning(push)
0035 #pragma warning(disable:4324) // structure was padded due to __declspec(align())
0036 #endif
0037 template <typename T>
0038 struct alignment_of_hack
0039 {
0040     char c;
0041     T t;
0042     alignment_of_hack();
0043 };
0044 #ifdef BOOST_MSVC
0045 #pragma warning(pop)
0046 #endif
0047 
0048 template <unsigned A, unsigned S>
0049 struct alignment_logic
0050 {
0051     BOOST_STATIC_CONSTANT(std::size_t, value = A < S ? A : S);
0052 };
0053 
0054 
0055 template< typename T >
0056 struct alignment_of_impl
0057 {
0058 #if defined(BOOST_MSVC) && (BOOST_MSVC >= 1400)
0059     //
0060     // With MSVC both the native __alignof operator
0061     // and our own logic gets things wrong from time to time :-(
0062     // Using a combination of the two seems to make the most of a bad job:
0063     //
0064     BOOST_STATIC_CONSTANT(std::size_t, value =
0065         (::boost::detail::alignment_logic<
0066             sizeof(::boost::detail::alignment_of_hack<T>) - sizeof(T),
0067             __alignof(T)
0068         >::value));
0069 #elif !defined(BOOST_ALIGNMENT_OF)
0070     BOOST_STATIC_CONSTANT(std::size_t, value =
0071         (::boost::detail::alignment_logic<
0072             sizeof(::boost::detail::alignment_of_hack<T>) - sizeof(T),
0073             sizeof(T)
0074         >::value));
0075 #else
0076    //
0077    // We put this here, rather than in the definition of
0078    // alignment_of below, because MSVC's __alignof doesn't
0079    // always work in that context for some unexplained reason.
0080    // (See type_with_alignment tests for test cases).
0081    //
0082    BOOST_STATIC_CONSTANT(std::size_t, value = BOOST_ALIGNMENT_OF(T));
0083 #endif
0084 };
0085 
0086 } // namespace detail
0087 
0088 template <class T> struct alignment_of : public integral_constant<std::size_t, ::boost::detail::alignment_of_impl<T>::value>{};
0089 
0090 // references have to be treated specially, assume
0091 // that a reference is just a special pointer:
0092 template <typename T> struct alignment_of<T&> : public alignment_of<T*>{};
0093 
0094 #ifdef BOOST_BORLANDC
0095 // long double gives an incorrect value of 10 (!)
0096 // unless we do this...
0097 struct long_double_wrapper{ long double ld; };
0098 template<> struct alignment_of<long double> : public alignment_of<long_double_wrapper>{};
0099 #endif
0100 
0101 // void has to be treated specially:
0102 template<> struct alignment_of<void> : integral_constant<std::size_t, 0>{};
0103 #ifndef BOOST_NO_CV_VOID_SPECIALIZATIONS
0104 template<> struct alignment_of<void const> : integral_constant<std::size_t, 0>{};
0105 template<> struct alignment_of<void const volatile> : integral_constant<std::size_t, 0>{};
0106 template<> struct alignment_of<void volatile> : integral_constant<std::size_t, 0>{};
0107 #endif
0108 
0109 } // namespace boost
0110 
0111 #if defined(BOOST_BORLANDC) && (BOOST_BORLANDC < 0x600)
0112 #pragma option pop
0113 #endif
0114 #ifdef BOOST_MSVC
0115 #   pragma warning(pop)
0116 #endif
0117 
0118 #endif // BOOST_TT_ALIGNMENT_OF_HPP_INCLUDED
0119