test_multiply_native.cpp 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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_multiply_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_multiply.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_multiply<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_multiplication_native_result[i1][i2]
  41. );
  42. }
  43. };
  44. #include "check_symmetry.hpp"
  45. int main(){
  46. // sanity check on test matrix - should be symetrical
  47. check_symmetry(test_multiplication_native_result);
  48. //TEST_EACH_VALUE_PAIR
  49. test<test_values> rval(true);
  50. using value_indices = mp_iota_c<mp_size<test_values>::value>;
  51. mp_for_each<
  52. mp_product<mp_list, value_indices, value_indices>
  53. >(rval);
  54. std::cout << (rval ? "success!" : "failure") << std::endl;
  55. return ! rval ;
  56. }