test_equal_constexpr.hpp 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. #ifndef BOOST_TEST_EQUAL_CONSTEXPR_HPP
  2. #define BOOST_TEST_EQUAL_CONSTEXPR_HPP
  3. // Copyright (c) 2015 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/config.hpp> // BOOST_CLANG
  9. #include <boost/safe_numerics/safe_integer.hpp>
  10. #if BOOST_CLANG == 1
  11. #pragma GCC diagnostic push
  12. #pragma GCC diagnostic ignored "-Wunused-comparison"
  13. #endif
  14. template<class T1, class T2>
  15. constexpr bool test_equal_constexpr(
  16. T1 v1,
  17. T2 v2,
  18. char expected_result
  19. ){
  20. using namespace boost::safe_numerics;
  21. // if we don't expect the operation to pass, we can't
  22. // check the constexpr version of the calculation so
  23. // just return success.
  24. if(expected_result == 'x')
  25. return true;
  26. safe_t<T1>(v1) == v2;
  27. v1 == safe_t<T2>(v2);
  28. safe_t<T1>(v1) == safe_t<T2>(v2);
  29. return true; // correct result
  30. }
  31. #if BOOST_CLANG == 1
  32. #pragma GCC diagnostic pop
  33. #endif
  34. #endif // BOOST_TEST_EQUAL_CONSTEXPR_HPP