test_constexpr.cpp 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. ///////////////////////////////////////////////////////////////////////////////
  2. // Copyright 2012 John Maddock. Distributed under the Boost
  3. // Software License, Version 1.0. (See accompanying file
  4. // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  5. #include <boost/multiprecision/cpp_int.hpp>
  6. #if defined(HAVE_FLOAT128)
  7. #include <boost/multiprecision/float128.hpp>
  8. #endif
  9. #ifndef BOOST_NO_CXX11_CONSTEXPR
  10. template <class T>
  11. void silence_unused(const T&) {}
  12. template <class T>
  13. void test1()
  14. {
  15. constexpr T i1 = 2u;
  16. constexpr T i2;
  17. constexpr T i3 = -3;
  18. constexpr T i4(i1);
  19. silence_unused(i1);
  20. silence_unused(i2);
  21. silence_unused(i3);
  22. silence_unused(i4);
  23. }
  24. template <class T>
  25. void test2()
  26. {
  27. constexpr T i1 = 2u;
  28. constexpr T i2;
  29. constexpr T i3 = -3;
  30. silence_unused(i1);
  31. silence_unused(i2);
  32. silence_unused(i3);
  33. }
  34. template <class T>
  35. void test3()
  36. {
  37. constexpr T i1 = 2u;
  38. constexpr T i2;
  39. silence_unused(i1);
  40. silence_unused(i2);
  41. }
  42. using namespace boost::multiprecision;
  43. template void test1<number<cpp_int_backend<64, 64, unsigned_magnitude, unchecked, void>, et_off> >();
  44. template void test1<number<cpp_int_backend<64, 64, signed_magnitude, unchecked, void>, et_off> >();
  45. template void test3<number<cpp_int_backend<2048, 2048, unsigned_magnitude, unchecked, void>, et_off> >();
  46. template void test2<number<cpp_int_backend<2048, 2048, signed_magnitude, unchecked, void>, et_off> >();
  47. #if defined(HAVE_FLOAT128)
  48. template void test1<float128>();
  49. #endif
  50. #endif