test_divide_native.cpp 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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/native.hpp>
  9. #include "test_divide_native_results.hpp"
  10. template <class T>
  11. using safe_t = boost::safe_numerics::safe<
  12. T,
  13. boost::safe_numerics::native
  14. >;
  15. #include "test_divide.hpp"
  16. using namespace boost::mp11;
  17. #include <boost/mp11/list.hpp>
  18. #include <boost/mp11/algorithm.hpp>
  19. #include <boost/mp11/algorithm.hpp>
  20. #include <boost/core/demangle.hpp>
  21. template<typename L>
  22. struct test {
  23. static_assert(mp_is_list<L>(), "must be a list of integral constants");
  24. bool m_error;
  25. test(bool b = true) : m_error(b) {}
  26. operator bool(){
  27. return m_error;
  28. }
  29. template<typename T>
  30. void operator()(const T &){
  31. static_assert(mp_is_list<T>(), "must be a list of two integral constants");
  32. constexpr size_t i1 = mp_first<T>(); // index of first argument
  33. constexpr size_t i2 = mp_second<T>();// index of second argument
  34. std::cout << i1 << ',' << i2 << ',';
  35. using T1 = typename mp_at_c<L, i1>::value_type;
  36. using T2 = typename mp_at_c<L, i2>::value_type;
  37. m_error &= test_divide(
  38. mp_at_c<L, i1>()(), // value of first argument
  39. mp_at_c<L, i2>()(), // value of second argument
  40. boost::core::demangle(typeid(T1).name()).c_str(),
  41. boost::core::demangle(typeid(T2).name()).c_str(),
  42. test_division_native_result[i1][i2]
  43. );
  44. }
  45. };
  46. int main(){
  47. test<test_values> rval(true);
  48. using value_indices = mp_iota_c<mp_size<test_values>::value>;
  49. mp_for_each<
  50. mp_product<mp_list, value_indices, value_indices>
  51. >(rval);
  52. std::cout << (rval ? "success!" : "failure") << std::endl;
  53. return ! rval ;
  54. }