test_right_shift_constexpr.hpp 870 B

123456789101112131415161718192021222324252627282930
  1. #ifndef BOOST_TEST_RIGHT_SHIFT_CONSTEXPR_HPP
  2. #define BOOST_TEST_RIGHT_SHIFT_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/safe_numerics/safe_integer.hpp>
  9. template<class T1, class T2>
  10. constexpr bool test_right_shift_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_RIGHT_SHIFT_CONSTEXPR_HPP