2 // (C) Copyright John Maddock 2000.
3 // Permission to copy, use, modify, sell and distribute this software is
4 // granted provided this copyright notice appears in all copies. This
5 // software is provided "as is" without express or implied warranty,
6 // and with no claim as to its suitability for any purpose.
8 #ifndef BOOST_TT_TYPE_WITH_ALIGNMENT_INCLUDED
9 #define BOOST_TT_TYPE_WITH_ALIGNMENT_INCLUDED
11 #include "boost/mpl/if.hpp"
12 #include "boost/preprocessor/list/for_each_i.hpp"
13 #include "boost/preprocessor/tuple/to_list.hpp"
14 #include "boost/preprocessor/cat.hpp"
15 #include "boost/type_traits/alignment_of.hpp"
16 #include "boost/static_assert.hpp"
17 #include "boost/config.hpp"
22 # pragma warning(push)
23 # pragma warning(disable: 4121) // alignment is sensitive to packing
30 class alignment_dummy;
31 typedef void (*function_ptr)();
32 typedef int (alignment_dummy::*member_ptr);
33 typedef int (alignment_dummy::*member_function_ptr)();
35 #define BOOST_TT_ALIGNMENT_TYPES BOOST_PP_TUPLE_TO_LIST( \
37 char, short, int, long, float, double, long double \
38 , void*, function_ptr, member_ptr, member_function_ptr))
40 #define BOOST_TT_CHOOSE_MIN_ALIGNMENT(R,P,I,T) \
42 alignment_of<T>::value <= target, T, char>::type BOOST_PP_CAT(t,I);
44 #define BOOST_TT_CHOOSE_T(R,P,I,T) T BOOST_PP_CAT(t,I);
46 template <std::size_t target>
49 BOOST_PP_LIST_FOR_EACH_I(
50 BOOST_TT_CHOOSE_MIN_ALIGNMENT
52 , BOOST_TT_ALIGNMENT_TYPES
58 BOOST_PP_LIST_FOR_EACH_I(
61 , BOOST_TT_ALIGNMENT_TYPES
65 #undef BOOST_TT_ALIGNMENT_TYPES
66 #undef BOOST_TT_CHOOSE_MIN_ALIGNMENT
67 #undef BOOST_TT_CHOOSE_T
69 template<int TAlign, int Align>
72 BOOST_STATIC_CONSTANT(bool,
73 value = (TAlign >= Align) & (TAlign % Align == 0)
79 // This alignment method originally due to Brian Parker, implemented by David
80 // Abrahams, and then ported here by Doug Gregor.
82 class type_with_alignment
84 typedef detail::lower_alignment<Align> t1;
85 typedef typename mpl::if_c<
86 ::boost::detail::is_aligned< ::boost::alignment_of<t1>::value,Align >::value
91 BOOST_STATIC_CONSTANT(std::size_t, found = alignment_of<align_t>::value);
93 BOOST_STATIC_ASSERT(found >= Align);
94 BOOST_STATIC_ASSERT(found % Align == 0);
103 # pragma warning(pop)
106 #endif // BOOST_TT_TYPE_WITH_ALIGNMENT_INCLUDED