Boost logo

Boost :

From: Douglas Gregor (gregod_at_[hidden])
Date: 2003-09-02 17:42:57


On Tuesday 02 September 2003 05:01 pm, David Abrahams wrote:
> "Peter Dimov" <pdimov_at_[hidden]> writes:
> > Maybe adding struct { double x; } would be enough?
>
> I think it would be safer to add struct { double T; } for each T in
> the list of types, just in case.

I agree. I've checked in the following patch, which implementations (a
corrected version of) the above. The preprocessor library rocks.

Mat, does this fix the problem for you?

        Doug

Index: type_with_alignment.hpp
===================================================================
RCS file: /cvsroot/boost/boost/boost/type_traits/type_with_alignment.hpp,v
retrieving revision 1.12
diff -u -r1.12 type_with_alignment.hpp
--- type_with_alignment.hpp 9 Jun 2003 22:16:19 -0000 1.12
+++ type_with_alignment.hpp 2 Sep 2003 22:39:51 -0000
@@ -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 <boost/preprocessor/list/transform.hpp>
+#include <boost/preprocessor/list/append.hpp>
 #include "boost/type_traits/alignment_of.hpp"
 #include "boost/type_traits/is_pod.hpp"
 #include "boost/static_assert.hpp"
@@ -38,11 +40,22 @@
 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<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<T>::value == target && !BOOST_PP_CAT(found,I)),
\
@@ -52,6 +65,12 @@

 #define BOOST_TT_CHOOSE_T(R,P,I,T) T BOOST_PP_CAT(t,I);

+template <typename T>
+struct has_one_T
+{
+ T data;
+};
+
 template <std::size_t target>
 union lower_alignment
 {
@@ -73,6 +92,9 @@
         )
 };

+#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


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk