test_subtract_native.cpp 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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_subtract_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_subtract.hpp"
  16. using namespace boost::mp11;
  17. #include <boost/mp11/list.hpp>
  18. #include <boost/mp11/algorithm.hpp>
  19. #include <boost/core/demangle.hpp>
  20. using namespace boost::mp11;
  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_subtract(
  38. boost::mp11::mp_at_c<L, i1>()(), // value of first argument
  39. boost::mp11::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_subtraction_native_result[i1][i2]
  43. );
  44. }
  45. };
  46. int main(){
  47. //TEST_EACH_VALUE_PAIR
  48. test<test_values> rval(true);
  49. using value_indices = mp_iota_c<mp_size<test_values>::value>;
  50. mp_for_each<
  51. mp_product<mp_list, value_indices, value_indices>
  52. >(rval);
  53. std::cout << (rval ? "success!" : "failure") << std::endl;
  54. return ! rval ;
  55. }