test_assignment.cpp 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. // Copyright (c) 2017 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. // test construction assignments
  7. #include <iostream>
  8. #include <boost/safe_numerics/safe_integer.hpp>
  9. template <class T>
  10. using safe_t = boost::safe_numerics::safe<
  11. T,
  12. boost::safe_numerics::native
  13. >;
  14. #include <boost/mp11/list.hpp>
  15. #include <boost/mp11/algorithm.hpp>
  16. #include "test_values.hpp"
  17. // note: same test matrix as used in test_checked. Here we test all combinations
  18. // safe and unsafe integers. in test_checked we test all combinations of
  19. // integer primitives
  20. const char *test_assignment_result[boost::mp11::mp_size<test_values>::value] = {
  21. // 0 0 0 0
  22. // 012345670123456701234567012345670
  23. // 012345678901234567890123456789012
  24. /* 0*/ ".....xx..xx..xx...xx.xxx.xxx.xxx.",
  25. /* 1*/ ".....xx..xx..xx...xx.xxx.xxx.xxx.",
  26. /* 2*/ ".....xx..xx..xx...xx.xxx.xxx.xxx.",
  27. /* 3*/ ".....xx..xx..xx...xx.xxx.xxx.xxx.",
  28. /* 4*/ ".........xx..xx.......xx.xxx.xxx.",
  29. /* 5*/ ".........xx..xx.......xx.xxx.xxx.",
  30. /* 6*/ ".........xx..xx.......xx.xxx.xxx.",
  31. /* 7*/ ".........xx..xx.......xx.xxx.xxx.",
  32. /* 8*/ ".............xx...........xx.xxx.",
  33. /* 9*/ ".............xx...........xx.xxx.",
  34. /*10*/ ".............xx...........xx.xxx.",
  35. /*11*/ ".............xx...........xx.xxx.",
  36. /*12*/ "..............................xx.",
  37. /*13*/ "..............................xx.",
  38. /*14*/ "..............................xx.",
  39. /*15*/ "..............................xx.",
  40. // 0 0 0 0
  41. // 012345670123456701234567012345670
  42. // 012345678901234567890123456789012
  43. /*16*/ "..xx.xxx.xxx.xxx.....xxx.xxx.xxx.",
  44. /*17*/ "..xx.xxx.xxx.xxx.....xxx.xxx.xxx.",
  45. /*18*/ "..xx.xxx.xxx.xxx.....xxx.xxx.xxx.",
  46. /*19*/ "..xx.xxx.xxx.xxx.....xxx.xxx.xxx.",
  47. /*20*/ "..xx..xx.xxx.xxx.........xxx.xxx.",
  48. /*21*/ "..xx..xx.xxx.xxx.........xxx.xxx.",
  49. /*22*/ "..xx..xx.xxx.xxx.........xxx.xxx.",
  50. /*23*/ "..xx..xx.xxx.xxx.........xxx.xxx.",
  51. /*24*/ "..xx..xx..xx.xxx.............xxx.",
  52. /*25*/ "..xx..xx..xx.xxx.............xxx.",
  53. /*26*/ "..xx..xx..xx.xxx.............xxx.",
  54. /*27*/ "..xx..xx..xx.xxx.............xxx.",
  55. /*28*/ "..xx..xx..xx..xx.................",
  56. /*29*/ "..xx..xx..xx..xx.................",
  57. /*30*/ "..xx..xx..xx..xx.................",
  58. /*31*/ "..xx..xx..xx..xx.................",
  59. // 012345678901234567890123456789012
  60. /*32*/ ".....xx..xx..xx...xx.xxx.xxx.xxx."
  61. };
  62. #include <boost/mp11/algorithm.hpp>
  63. #include <boost/core/demangle.hpp>
  64. template <class T>
  65. using safe_t = boost::safe_numerics::safe<
  66. T,
  67. boost::safe_numerics::native
  68. >;
  69. #include "test_assignment.hpp"
  70. using namespace boost::mp11;
  71. template<typename L>
  72. struct test {
  73. static_assert(mp_is_list<L>(), "must be a list of integral constants");
  74. bool m_error;
  75. test(bool b = true) : m_error(b) {}
  76. operator bool(){
  77. return m_error;
  78. }
  79. template<typename T>
  80. void operator()(const T &){
  81. static_assert(mp_is_list<T>(), "must be a list of two integral constants");
  82. constexpr size_t i1 = mp_first<T>(); // index of first argument
  83. constexpr size_t i2 = mp_second<T>();// index of second argument
  84. std::cout << i1 << ',' << i2 << ',';
  85. using T1 = typename boost::mp11::mp_at_c<L, i1>::value_type;
  86. using T2 = typename boost::mp11::mp_at_c<L, i2>::value_type;
  87. m_error &= test_assignment<T1, T2>(
  88. boost::mp11::mp_at_c<L, i1>(), // value of first argument
  89. boost::mp11::mp_at_c<L, i2>(), // value of second argument
  90. boost::core::demangle(typeid(T1).name()).c_str(),
  91. boost::core::demangle(typeid(T2).name()).c_str(),
  92. test_assignment_result[i1][i2]
  93. );
  94. }
  95. };
  96. int main(int, char *[]){
  97. // TEST_EACH_VALUE_PAIR
  98. test<test_values> rval(true);
  99. using value_indices = mp_iota_c<mp_size<test_values>::value>;
  100. mp_for_each<
  101. mp_product<mp_list, value_indices, value_indices>
  102. >(rval);
  103. std::cout << (rval ? "success!" : "failure") << std::endl;
  104. return ! rval ;
  105. }