test_xor_native.cpp 1.8 KB

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