test_right_shift_native.cpp 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. // Copyright (c) 2012 Robert Ramey
  2. //
  3. // Distributed under the Boost Software License, Version 1.0. (See
  4. // accompanying file LICENSE_1_0.txt or copy at
  5. // http://www.boost.org/LICENSE_1_0.txt)
  6. #include <iostream>
  7. #include <boost/safe_numerics/safe_integer.hpp>
  8. #include "test_right_shift_native_results.hpp"
  9. template <class T>
  10. using safe_t = boost::safe_numerics::safe<
  11. T,
  12. boost::safe_numerics::native
  13. >;
  14. #include "test_right_shift.hpp"
  15. #include <boost/mp11/list.hpp>
  16. #include <boost/mp11/algorithm.hpp>
  17. #include <boost/core/demangle.hpp>
  18. using namespace boost::mp11;
  19. template<typename L>
  20. struct test {
  21. static_assert(mp_is_list<L>(), "must be a list of integral constants");
  22. bool m_error;
  23. test(bool b = true) : m_error(b) {}
  24. operator bool(){
  25. return m_error;
  26. }
  27. template<typename T>
  28. void operator()(const T &){
  29. static_assert(mp_is_list<T>(), "must be a list of two integral constants");
  30. constexpr size_t i1 = mp_first<T>(); // index of first argument
  31. constexpr size_t i2 = mp_second<T>();// index of second argument
  32. std::cout << i1 << ',' << i2 << ',';
  33. using T1 = typename mp_at_c<L, i1>::value_type;
  34. using T2 = typename mp_at_c<L, i2>::value_type;
  35. m_error &= test_right_shift<T1, T2>(
  36. mp_at_c<L, i1>(), // value of first argument
  37. mp_at_c<L, i2>(), // value of second argument
  38. boost::core::demangle(typeid(T1).name()).c_str(),
  39. boost::core::demangle(typeid(T2).name()).c_str(),
  40. test_right_shift_native_result[i1][i2]
  41. );
  42. }
  43. };
  44. int main(){
  45. //TEST_EACH_VALUE_PAIR
  46. test<test_values> rval(true);
  47. using value_indices = mp_iota_c<mp_size<test_values>::value>;
  48. mp_for_each<
  49. mp_product<mp_list, value_indices, value_indices>
  50. >(rval);
  51. std::cout << (rval ? "success!" : "failure") << std::endl;
  52. return ! rval ;
  53. }