test_subtract_constexpr.hpp 855 B

123456789101112131415161718192021222324252627282930
  1. #ifndef BOOST_TEST_SUBTRACT_CONSTEXPR_HPP
  2. #define BOOST_TEST_SUBTRACT_CONSTEXPR_HPP
  3. // Copyright (c) 2019 Robert Ramey
  4. //
  5. // Distributed under the Boost Software License, Version 1.0. (See
  6. // accompanying file LICENSE_1_0.txt or copy at
  7. // http://www.boost.org/LICENSE_1_0.txt)
  8. #include <boost/safe_numerics/safe_integer.hpp>
  9. template<class T1, class T2>
  10. constexpr bool test_subtract_constexpr(
  11. T1 v1,
  12. T2 v2,
  13. char expected_result
  14. ){
  15. using namespace boost::safe_numerics;
  16. // if we don't expect the operation to pass, we can't
  17. // check the constexpr version of the calculation so
  18. // just return success.
  19. if(expected_result == 'x')
  20. return true;
  21. safe_t<T1>(v1) - v2;
  22. v1 - safe_t<T2>(v2);
  23. safe_t<T1>(v1) - safe_t<T2>(v2);
  24. return true; // correct result
  25. }
  26. #endif // BOOST_TEST_SUBTRACT_CONSTEXPR_HPP