Index: boost/type_traits/alignment_traits.hpp =================================================================== RCS file: /cvsroot/boost/boost/boost/type_traits/alignment_traits.hpp,v retrieving revision 1.4 diff -c -r1.4 alignment_traits.hpp *** boost/type_traits/alignment_traits.hpp 8 Oct 2001 11:33:02 -0000 1.4 --- boost/type_traits/alignment_traits.hpp 27 Mar 2002 04:39:00 -0000 *************** *** 16,23 **** --- 16,30 ---- #ifndef BOOST_ICE_TYPE_TRAITS_HPP #include #endif + #include + #include + #include + #include + #include namespace boost{ + template struct alignment_of; + // // get the alignment of some arbitrary type: namespace detail{ *************** *** 76,84 **** { BOOST_STATIC_CONSTANT(std::size_t, value = 0); }; #endif ! } // namespace boost ! #endif // ALIGNMENT_TYPE_TRAITS_HPP ! --- 83,193 ---- { BOOST_STATIC_CONSTANT(std::size_t, value = 0); }; #endif ! namespace detail { ! class alignment_dummy; ! typedef void (*function_ptr)(); ! typedef int (alignment_dummy::*member_ptr); ! typedef int (alignment_dummy::*member_function_ptr)(); ! ! /* ! * The ct_if implementation is temporary code. It will be replaced with MPL ! * in the future... ! */ ! struct select_then ! { ! template ! struct result ! { ! typedef Then type; ! }; ! }; ! ! struct select_else ! { ! template ! struct result ! { ! typedef Else type; ! }; ! }; ! ! template ! struct ct_if_selector ! { ! typedef select_then type; ! }; ! ! template<> ! struct ct_if_selector ! { ! typedef select_else type; ! }; ! ! template ! struct ct_if ! { ! typedef typename ct_if_selector::type select; ! typedef typename select::template result::type type; ! }; ! #define BOOST_TT_ALIGNMENT_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_CHOOSE_LOWER_ALIGNMENT(R,P,I,T) \ ! typename ct_if< \ ! alignment_of::value <= target, T, char>::type BOOST_PP_CAT(t,I); ! ! #define BOOST_TT_CHOOSE_T(R,P,I,T) T BOOST_PP_CAT(t,I); ! ! template ! union lower_alignment ! { ! BOOST_PP_LIST_FOR_EACH_I( ! BOOST_TT_CHOOSE_LOWER_ALIGNMENT ! , ignored, BOOST_TT_ALIGNMENT_TYPES) ! }; ! union max_align ! { ! BOOST_PP_LIST_FOR_EACH_I( ! BOOST_TT_CHOOSE_T ! , ignored, BOOST_TT_ALIGNMENT_TYPES) ! }; ! ! #undef BOOST_TT_ALIGNMENT_TYPES ! #undef BOOST_TT_CHOOSE_LOWER_ALIGNMENT ! #undef BOOST_TT_CHOOSE_T ! ! } ! ! // This alignment method originally due to Brian Parker, implemented by David ! // Abrahams, and then ported here by Doug Gregor. ! template ! class type_with_alignment ! { ! typedef detail::lower_alignment t1; ! ! BOOST_STATIC_CONSTANT(bool, t1_aligned = ! (alignment_of::value >= Align) ! & (alignment_of::value % Align == 0)); ! ! typedef typename detail::ct_if< ! t1_aligned ! , t1 ! , detail::max_align ! >::type align_t; ! ! BOOST_STATIC_CONSTANT(std::size_t, found = alignment_of::value); ! ! BOOST_STATIC_ASSERT(found >= Align); ! BOOST_STATIC_ASSERT(found % Align == 0); ! ! public: ! typedef align_t type; ! }; + } // namespace boost + + #endif // ALIGNMENT_TYPE_TRAITS_HPP Index: boost/type_traits/type_traits_test.hpp =================================================================== RCS file: /cvsroot/boost/boost/boost/type_traits/type_traits_test.hpp,v retrieving revision 1.21 diff -c -r1.21 type_traits_test.hpp *** boost/type_traits/type_traits_test.hpp 22 Mar 2002 11:25:32 -0000 1.21 --- boost/type_traits/type_traits_test.hpp 27 Mar 2002 04:39:01 -0000 *************** *** 197,202 **** --- 197,224 ---- #define align_test(T) test_align::do_it() + template + struct test_type_with_align + { + static void do_it() + { + typedef typename boost::type_with_alignment< + boost::alignment_of::value>::type + align_t; + int align = boost::alignment_of::value; + int new_align = boost::alignment_of::value; + ++test_count; + if (new_align % align != 0) { + ++failures; + std::cerr << "checking for an object with same alignment as " + << typeid(T).name() << "...failed" << std::endl; + std::cerr << "\tfound: " << typeid(align_t).name() << std::endl; + } + } + }; + + #define type_with_align_test(T) test_type_with_align::do_it() + // // the following code allows us to test that a particular // template functions correctly when instanciated inside another template Index: libs/type_traits/tests/alignment_test.cpp =================================================================== RCS file: /cvsroot/boost/boost/libs/type_traits/tests/alignment_test.cpp,v retrieving revision 1.5 diff -c -r1.5 alignment_test.cpp *** libs/type_traits/tests/alignment_test.cpp 24 Feb 2002 02:48:54 -0000 1.5 --- libs/type_traits/tests/alignment_test.cpp 27 Mar 2002 04:39:01 -0000 *************** *** 36,41 **** --- 36,46 ---- align_test(VD); value_test(0, ::boost::alignment_of::value); + type_with_align_test(int); + type_with_align_test(int(*)(int)); + type_with_align_test(VB); + type_with_align_test(VD); + type_with_align_test(char[13]); return check_result(argc, argv); } Index: libs/type_traits/index.htm =================================================================== RCS file: /cvsroot/boost/boost/libs/type_traits/index.htm,v retrieving revision 1.19 diff -c -r1.19 index.htm *** libs/type_traits/index.htm 22 Mar 2002 11:26:31 -0000 1.19 --- libs/type_traits/index.htm 27 Mar 2002 04:39:02 -0000 *************** *** 31,36 **** --- 31,37 ---- Type Properties Relationships Between Types Transformations Between Types + Synthesizing Types Compiler Support Information Type traits headers Example Code *************** *** 776,781 **** --- 777,815 ----

Note that the macro BOOST_BROKEN_COMPILER_TYPE_TRAITS_SPECIALIZATION evaluates to nothing on those compilers that do support partial specialization.

+ +

Synthesizing Types

+

The following template synthesizes a type with the desired properties. + + + + + + + + + + + + + + + + + + +
 

Expression

+

Description

+

Reference

+

Compiler requirements

+
 
 ::boost::type_with_alignment<Align>::typeAttempts to find a + built-in or POD type with an alignment that is a multiple of Align. +

+
 

Compiler Support Information