test_policy_9.cpp 4.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. #define BOOST_TEST_MAIN
  2. // Copyright John Maddock 2007.
  3. // Use, modification and distribution are subject to the
  4. // Boost Software License, Version 1.0.
  5. // (See accompanying file LICENSE_1_0.txt
  6. // or copy at http://www.boost.org/LICENSE_1_0.txt)
  7. #include <boost/math/policies/policy.hpp>
  8. #include <boost/math/policies/error_handling.hpp>
  9. #include <boost/math/tools/precision.hpp>
  10. template <class T>
  11. BOOST_CONSTEXPR int consume_constexpr(const T&)
  12. { return 0; }
  13. void test()
  14. {
  15. using namespace boost::math::policies;
  16. using namespace boost;
  17. #if !defined(BOOST_NO_CXX11_CONSTEXPR) && !defined(BOOST_NO_CXX11_AUTO_DECLARATIONS) && !defined(BOOST_MATH_DISABLE_CONSTEXPR)
  18. constexpr auto p1 = make_policy();
  19. constexpr auto p2 = make_policy(promote_double<false>());
  20. constexpr auto p3 = make_policy(domain_error<user_error>(), pole_error<user_error>(), overflow_error<user_error>(), underflow_error<user_error>(),
  21. denorm_error<user_error>(), evaluation_error<user_error>(), rounding_error<user_error>(), indeterminate_result_error<user_error>());
  22. constexpr auto p4 = make_policy(promote_float<false>(), promote_double<false>(), assert_undefined<true>(), discrete_quantile<real>(),
  23. digits10<10>(), max_series_iterations<100>(), max_root_iterations<20>());
  24. constexpr auto p5 = make_policy(digits2<20>());
  25. constexpr int d = digits<double, policy<> >() + digits_base10<double, policy<> >();
  26. constexpr unsigned long s = get_max_series_iterations<policy<> >();
  27. constexpr unsigned long r = get_max_root_iterations<policy<> >();
  28. constexpr double ep = get_epsilon<double, policy<> >();
  29. constexpr double ep2 = get_epsilon<double, policy<digits10<7> > >();
  30. constexpr auto p6 = make_policy(domain_error<ignore_error>(), pole_error<ignore_error>(), overflow_error<ignore_error>(), underflow_error<ignore_error>(),
  31. denorm_error<ignore_error>(), evaluation_error<ignore_error>(), rounding_error<ignore_error>(), indeterminate_result_error<ignore_error>());
  32. constexpr double r1 = raise_domain_error<double>("foo", "Out of range", 0.0, p6);
  33. constexpr double r2 = raise_pole_error<double>("func", "msg", 0.0, p6);
  34. constexpr double r3 = raise_overflow_error<double>("func", "msg", p6);
  35. constexpr double r4 = raise_overflow_error("func", "msg", 0.0, p6);
  36. constexpr double r5 = raise_underflow_error<double>("func", "msg", p6);
  37. constexpr double r6 = raise_denorm_error("func", "msg", 0.0, p6);
  38. constexpr double r7 = raise_evaluation_error("func", "msg", 0.0, p6);
  39. constexpr float r8 = raise_rounding_error("func", "msg", 0.0, 0.0f, p6);
  40. constexpr float r9 = raise_indeterminate_result_error("func", "msg", 0.0, 0.0f, p6);
  41. consume_constexpr(p1);
  42. consume_constexpr(p2);
  43. consume_constexpr(p3);
  44. consume_constexpr(p4);
  45. consume_constexpr(p5);
  46. consume_constexpr(p6);
  47. consume_constexpr(d);
  48. consume_constexpr(s);
  49. consume_constexpr(r);
  50. consume_constexpr(ep);
  51. consume_constexpr(ep2);
  52. consume_constexpr(r1);
  53. consume_constexpr(r2);
  54. consume_constexpr(r3);
  55. consume_constexpr(r4);
  56. consume_constexpr(r5);
  57. consume_constexpr(r6);
  58. consume_constexpr(r7);
  59. consume_constexpr(r8);
  60. consume_constexpr(r9);
  61. #endif
  62. #ifndef BOOST_NO_CXX11_NOEXCEPT
  63. static_assert(noexcept(make_policy()), "This expression should be noexcept");
  64. static_assert(noexcept(make_policy(promote_double<false>())), "This expression should be noexcept");
  65. static_assert(noexcept(make_policy(domain_error<user_error>(), pole_error<user_error>(), overflow_error<user_error>(), underflow_error<user_error>(),
  66. denorm_error<user_error>(), evaluation_error<user_error>(), rounding_error<user_error>(), indeterminate_result_error<user_error>())), "This expression should be noexcept");
  67. static_assert(noexcept(make_policy(promote_float<false>(), promote_double<false>(), assert_undefined<true>(), discrete_quantile<boost::math::policies::real>(),
  68. digits10<10>(), max_series_iterations<100>(), max_root_iterations<20>())), "This expression should be noexcept");
  69. static_assert(noexcept(digits<double, policy<> >() + digits_base10<double, policy<> >()), "This expression should be noexcept");
  70. static_assert(noexcept(get_max_series_iterations<policy<> >()), "This expression should be noexcept");
  71. static_assert(noexcept(get_max_root_iterations<policy<> >()), "This expression should be noexcept");
  72. static_assert(noexcept(get_epsilon<double, policy<> >()), "This expression should be noexcept");
  73. #endif
  74. } // BOOST_AUTO_TEST_CASE( test_main )