namespace boost { template struct STATIC_ASSERTION_FAILURE_BASE; template <> struct STATIC_ASSERTION_FAILURE_BASE { enum { value = 1 }; }; namespace static_assert { class not_used {}; } // in order we need to 'dump' constants template< int i> class const_value {}; template< bool x, class type1 = static_assert::not_used , class type2 = static_assert::not_used, class type3 = static_assert::not_used, class type4 = static_assert::not_used, class type5 = static_assert::not_used, class type6 = static_assert::not_used, class type7 = static_assert::not_used > struct STATIC_ASSERTION_FAILURE : public STATIC_ASSERTION_FAILURE_BASE< x> { }; template struct static_assert_test{}; } // namespace boost #define INT_(x) ::boost::const_value<(x)> // for MSVC #define BOOST_STATIC_ASSERT1( B, val1 ) \ typedef ::boost::static_assert_test<\ sizeof(::boost::STATIC_ASSERTION_FAILURE< (bool)( B ), val1 >)\ > boost_static_assert_typedef_ #define BOOST_STATIC_ASSERT2( B, val1, val2 ) \ typedef ::boost::static_assert_test<\ sizeof(::boost::STATIC_ASSERTION_FAILURE< (bool)( B ), val1, val2 >)\ > boost_static_assert_typedef_ #define BOOST_STATIC_ASSERT4( B, val1, val2, val3, val4 ) \ typedef ::boost::static_assert_test<\ sizeof(::boost::STATIC_ASSERTION_FAILURE< (bool)( B ), val1, val2, val3, val4 >)\ > boost_static_assert_typedef_ //...etc /////////////////////////////////////////////// // Example template< class type1, class type2> struct type1_bigger { type1_bigger() { BOOST_STATIC_ASSERT4( sizeof(type1) > sizeof(type2), type1, type2, INT_(sizeof(type1)), INT_(sizeof(type2)) ); } }; int main(int argc, char* argv[]) { type1_bigger< int, char> i; // generated assertion failed type1_bigger< char, int> i2; return 0; }