diff --git a/include/boost/type_traits/alignment_of.hpp b/include/boost/type_traits/alignment_of.hpp index 45cf38f..9739f14 100644 --- a/include/boost/type_traits/alignment_of.hpp +++ b/include/boost/type_traits/alignment_of.hpp @@ -12,6 +12,7 @@ #include #include +#include // should be the last #include #include @@ -55,11 +56,21 @@ struct alignment_logic template< typename T > struct alignment_of_impl { +#ifndef BOOST_ALIGNMENT_OF BOOST_STATIC_CONSTANT(std::size_t, value = (::boost::detail::alignment_logic< sizeof(::boost::detail::alignment_of_hack) - sizeof(T), sizeof(T) >::value)); +#else + // + // We put this here, rather than in the definition of + // alignment_of below, because MSVC's __alignof doesn't + // always work in that context for some unexplained reason. + // (See type_with_alignment tests for test cases). + // + BOOST_STATIC_CONSTANT(std::size_t, value = BOOST_ALIGNMENT_OF(T)); +#endif }; } // namespace detail diff --git a/include/boost/type_traits/intrinsics.hpp b/include/boost/type_traits/intrinsics.hpp index 6c285bf..316a966 100644 --- a/include/boost/type_traits/intrinsics.hpp +++ b/include/boost/type_traits/intrinsics.hpp @@ -42,6 +42,7 @@ // BOOST_IS_CONVERTIBLE(T,U) true if T is convertible to U // BOOST_IS_ENUM(T) true is T is an enum // BOOST_IS_POLYMORPHIC(T) true if T is a polymorphic type +// BOOST_ALIGNMENT_OF(T) should evaluate to the alignment requirements of type T. #ifdef BOOST_HAS_SGI_TYPE_TRAITS // Hook into SGI's __type_traits class, this will pick up user supplied @@ -104,6 +105,7 @@ # define BOOST_IS_ENUM(T) __is_enum(T) // This one doesn't quite always do the right thing: // # define BOOST_IS_POLYMORPHIC(T) __is_polymorphic(T) +# define BOOST_ALIGNMENT_OF(T) __alignof(T) # define BOOST_HAS_TYPE_TRAITS_INTRINSICS #endif @@ -146,6 +148,7 @@ # define BOOST_IS_CLASS(T) __is_class(T) # define BOOST_IS_ENUM(T) __is_enum(T) # define BOOST_IS_POLYMORPHIC(T) __is_polymorphic(T) +# define BOOST_ALIGNMENT_OF(T) __alignof__(T) # define BOOST_HAS_TYPE_TRAITS_INTRINSICS #endif