test_modulus_automatic.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 <boost/safe_numerics/automatic.hpp>
  9. #include "test_modulus_automatic_results.hpp"
  10. template <class T>
  11. using safe_t = boost::safe_numerics::safe<
  12. T,
  13. boost::safe_numerics::automatic
  14. >;
  15. #include "test_modulus.hpp"
  16. #include <boost/mp11/list.hpp>
  17. #include <boost/mp11/algorithm.hpp>
  18. #include <boost/core/demangle.hpp>
  19. using namespace boost::mp11;
  20. template<typename L>
  21. struct test {
  22. static_assert(mp_is_list<L>(), "must be a list of integral constants");
  23. bool m_error;
  24. test(bool b = true) : m_error(b) {}
  25. operator bool(){
  26. return m_error;
  27. }
  28. template<typename T>
  29. void operator()(const T &){
  30. static_assert(mp_is_list<T>(), "must be a list of two integral constants");
  31. constexpr size_t i1 = mp_first<T>(); // index of first argument
  32. constexpr size_t i2 = mp_second<T>();// index of second argument
  33. std::cout << i1 << ',' << i2 << ',';
  34. using T1 = typename mp_at_c<L, i1>::value_type;
  35. using T2 = typename mp_at_c<L, i2>::value_type;
  36. m_error &= test_modulus<T1, T2>(
  37. mp_at_c<L, i1>()(), // value of first argument
  38. mp_at_c<L, i2>()(), // value of second argument
  39. boost::core::demangle(typeid(T1).name()).c_str(),
  40. boost::core::demangle(typeid(T2).name()).c_str(),
  41. test_modulus_automatic_result[i1][i2]
  42. );
  43. }
  44. };
  45. int main(){
  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. }