From f9b5fa44f49d05a41a60caaeb36605a5c0e2044d Mon Sep 17 00:00:00 2001 From: Douglas Gregor Date: Wed, 16 Apr 2003 13:36:07 +0000 Subject: [PATCH] Pick the first type that has the right alignment. The types are roughly ordered based on size, so this prevents the alignment type from being much larger than it should be. [SVN r18258] --- .../boost/type_traits/type_with_alignment.hpp | 26 +++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/include/boost/type_traits/type_with_alignment.hpp b/include/boost/type_traits/type_with_alignment.hpp index 91d3aca..b7e90dc 100644 --- a/include/boost/type_traits/type_with_alignment.hpp +++ b/include/boost/type_traits/type_with_alignment.hpp @@ -1,8 +1,8 @@ // (C) Copyright John Maddock 2000. -// Permission to copy, use, modify, sell and distribute this software is -// granted provided this copyright notice appears in all copies. This -// software is provided "as is" without express or implied warranty, +// Permission to copy, use, modify, sell and distribute this software is +// granted provided this copyright notice appears in all copies. This +// software is provided "as is" without express or implied warranty, // and with no claim as to its suitability for any purpose. #ifndef BOOST_TT_TYPE_WITH_ALIGNMENT_INCLUDED @@ -43,15 +43,20 @@ typedef int (alignment_dummy::*member_function_ptr)(); char, short, int, long, float, double, long double \ , void*, function_ptr, member_ptr, member_function_ptr)) -#define BOOST_TT_CHOOSE_MIN_ALIGNMENT(R,P,I,T) \ - typename mpl::if_c< \ - alignment_of::value <= target, T, char>::type BOOST_PP_CAT(t,I); +#define BOOST_TT_CHOOSE_MIN_ALIGNMENT(R,P,I,T) \ + typename mpl::if_c< \ + (alignment_of::value == target && !BOOST_PP_CAT(found,I)), \ + T, char>::type BOOST_PP_CAT(t,I); \ + enum { BOOST_PP_CAT(found,BOOST_PP_INC(I)) = \ + alignment_of::value == target || BOOST_PP_CAT(found,I) } ; #define BOOST_TT_CHOOSE_T(R,P,I,T) T BOOST_PP_CAT(t,I); - + template union lower_alignment { + enum { found0 = false }; + BOOST_PP_LIST_FOR_EACH_I( BOOST_TT_CHOOSE_MIN_ALIGNMENT , ignored @@ -92,7 +97,7 @@ BOOST_TT_AUX_BOOL_TRAIT_IMPL_SPEC1(is_pod,::boost::detail::lower_alignment<32> , } // namespace detail // This alignment method originally due to Brian Parker, implemented by David -// Abrahams, and then ported here by Doug Gregor. +// Abrahams, and then ported here by Doug Gregor. template class type_with_alignment { @@ -105,13 +110,8 @@ class type_with_alignment BOOST_STATIC_CONSTANT(std::size_t, found = alignment_of::value); -#ifndef __BORLANDC__ BOOST_STATIC_ASSERT(found >= Align); BOOST_STATIC_ASSERT(found % Align == 0); -#else - BOOST_STATIC_ASSERT(::boost::type_with_alignment::found >= Align); - BOOST_STATIC_ASSERT(::boost::type_with_alignment::found % Align == 0); -#endif public: typedef align_t type;