From 2fd0675a21a35ee0d1f6aa7c2f7fa6873aa45a5c Mon Sep 17 00:00:00 2001 From: Daryle Walker Date: Mon, 28 Jul 2008 14:41:00 +0000 Subject: [PATCH] Hopefully made compile-time constants suitable for more compilers [SVN r47852] --- test/integer_test.cpp | 37 ++++++++++++++++++++++++++----------- 1 file changed, 26 insertions(+), 11 deletions(-) diff --git a/test/integer_test.cpp b/test/integer_test.cpp index 4b34d40..8f5c834 100644 --- a/test/integer_test.cpp +++ b/test/integer_test.cpp @@ -44,6 +44,7 @@ #include // for boost::mpl::push_back #include // for boost::mpl::push_front #include // for boost::mpl::range_c +#include // for boost::mpl::shift_right #include // for boost::mpl::sort #include // for boost::mpl::transform #include // for boost::mpl::transform_view @@ -290,6 +291,19 @@ print_out_template( T const &, ValueT setting, char const *template_pre_name, #error "These tests cannot work without Substitution-Failure-Is-Not-An-Error" #endif +// Get the extreme values for each integral type +template < typename T > +struct minimum_of + : boost::mpl::integral_c< T, boost::integer_traits::const_min > +{ +}; + +template < typename T > +struct maximum_of + : boost::mpl::integral_c< T, boost::integer_traits::const_max > +{ +}; + } // unnamed namespace @@ -617,13 +631,14 @@ BOOST_AUTO_TEST_CASE_TEMPLATE( fit_for_shifted_unsigned_values_test, T, // 64) elements, so we have to take selected values. using boost::uintmax_t; - static uintmax_t const maxi = boost::integer_traits::const_max - >> T::value; + typedef boost::mpl::shift_right, T> maxi_type; + + uintmax_t const maxi = maxi_type::value; BOOST_CHECK_EQUAL( static_cast::least>(maxi), maxi ); + boost::uint_value_t::least>(maxi), maxi ); BOOST_CHECK_EQUAL( static_cast::fast>(maxi), maxi ); + boost::uint_value_t::fast>(maxi), maxi ); } // Check if large value can fit its minimum required size, by value, signed @@ -646,20 +661,20 @@ BOOST_AUTO_TEST_CASE_TEMPLATE( fit_for_shifted_signed_values_test, T, // 64) elements, so we have to take selected values. using boost::intmax_t; - typedef boost::integer_traits intmax_traits; + typedef boost::mpl::shift_right, T> mini_type; + typedef boost::mpl::shift_right, T> maxi_type; - static intmax_t const maxi = intmax_traits::const_max >> T::value, - mini = intmax_traits::const_min >> T::value; + intmax_t const maxi = maxi_type::value, mini = mini_type::value; BOOST_CHECK_EQUAL( static_cast::least>(maxi), maxi ); + boost::int_max_value_t::least>(maxi), maxi ); BOOST_CHECK_EQUAL( static_cast::fast>(maxi), maxi ); + boost::int_max_value_t::fast>(maxi), maxi ); BOOST_CHECK_EQUAL( static_cast::least>(mini), mini ); + boost::int_min_value_t::least>(mini), mini ); BOOST_CHECK_EQUAL( static_cast::fast>(mini), mini ); + boost::int_min_value_t::fast>(mini), mini ); } BOOST_AUTO_TEST_SUITE_END()