From 2ffc663dd5c778c5a2e847e91b32dc87c40143e3 Mon Sep 17 00:00:00 2001 From: Douglas Gregor Date: Tue, 2 Sep 2003 22:41:10 +0000 Subject: [PATCH] Also check structs with a single element of varying types when searching for a type with a particular alignment. [SVN r19908] --- .../boost/type_traits/type_with_alignment.hpp | 24 ++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/include/boost/type_traits/type_with_alignment.hpp b/include/boost/type_traits/type_with_alignment.hpp index 104169a..0ad3cdc 100644 --- a/include/boost/type_traits/type_with_alignment.hpp +++ b/include/boost/type_traits/type_with_alignment.hpp @@ -12,6 +12,8 @@ #include "boost/preprocessor/list/for_each_i.hpp" #include "boost/preprocessor/tuple/to_list.hpp" #include "boost/preprocessor/cat.hpp" +#include +#include #include "boost/type_traits/alignment_of.hpp" #include "boost/type_traits/is_pod.hpp" #include "boost/static_assert.hpp" @@ -38,11 +40,22 @@ typedef void (*function_ptr)(); typedef int (alignment_dummy::*member_ptr); typedef int (alignment_dummy::*member_function_ptr)(); -#define BOOST_TT_ALIGNMENT_TYPES BOOST_PP_TUPLE_TO_LIST( \ +#define BOOST_TT_ALIGNMENT_BASE_TYPES BOOST_PP_TUPLE_TO_LIST( \ 11, ( \ char, short, int, long, float, double, long double \ , void*, function_ptr, member_ptr, member_function_ptr)) +#define BOOST_TT_HAS_ONE_T(D,Data,T) boost::detail::has_one_T + +#define BOOST_TT_ALIGNMENT_STRUCT_TYPES \ + BOOST_PP_LIST_TRANSFORM(BOOST_TT_HAS_ONE_T, \ + X, \ + BOOST_TT_ALIGNMENT_BASE_TYPES) + +#define BOOST_TT_ALIGNMENT_TYPES \ + BOOST_PP_LIST_APPEND(BOOST_TT_ALIGNMENT_BASE_TYPES, \ + BOOST_TT_ALIGNMENT_STRUCT_TYPES) + #define BOOST_TT_CHOOSE_MIN_ALIGNMENT(R,P,I,T) \ typename mpl::if_c< \ (alignment_of::value == target && !BOOST_PP_CAT(found,I)), \ @@ -52,6 +65,12 @@ typedef int (alignment_dummy::*member_function_ptr)(); #define BOOST_TT_CHOOSE_T(R,P,I,T) T BOOST_PP_CAT(t,I); +template +struct has_one_T +{ + T data; +}; + template union lower_alignment { @@ -73,6 +92,9 @@ union max_align ) }; +#undef BOOST_TT_ALIGNMENT_BASE_TYPES +#undef BOOST_TT_HAS_ONE_T +#undef BOOST_TT_ALIGNMENT_STRUCT_TYPES #undef BOOST_TT_ALIGNMENT_TYPES #undef BOOST_TT_CHOOSE_MIN_ALIGNMENT #undef BOOST_TT_CHOOSE_T