unpack.cpp 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. // Copyright Louis Dionne 2013-2017
  2. // Distributed under the Boost Software License, Version 1.0.
  3. // (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
  4. #include <boost/hana/assert.hpp>
  5. #include <boost/hana/equal.hpp>
  6. #include <boost/hana/experimental/view.hpp>
  7. #include <boost/hana/tuple.hpp>
  8. #include <boost/hana/unpack.hpp>
  9. #include <laws/base.hpp>
  10. #include <support/seq.hpp>
  11. namespace hana = boost::hana;
  12. using hana::test::ct_eq;
  13. int main() {
  14. auto container = ::seq;
  15. auto f = hana::test::_injection<0>{};
  16. {
  17. auto storage = container();
  18. auto sliced = hana::experimental::sliced(storage, hana::tuple_c<int>);
  19. BOOST_HANA_CONSTANT_CHECK(hana::equal(
  20. hana::unpack(sliced, f),
  21. f()
  22. ));
  23. }
  24. {
  25. auto storage = container(ct_eq<0>{});
  26. auto sliced = hana::experimental::sliced(storage, hana::tuple_c<int>);
  27. BOOST_HANA_CONSTANT_CHECK(hana::equal(
  28. hana::unpack(sliced, f),
  29. f()
  30. ));
  31. }{
  32. auto storage = container(ct_eq<0>{});
  33. auto sliced = hana::experimental::sliced(storage, hana::tuple_c<int, 0>);
  34. BOOST_HANA_CONSTANT_CHECK(hana::equal(
  35. hana::unpack(sliced, f),
  36. f(ct_eq<0>{})
  37. ));
  38. }
  39. {
  40. auto storage = container(ct_eq<0>{}, ct_eq<1>{});
  41. auto sliced = hana::experimental::sliced(storage, hana::tuple_c<int>);
  42. BOOST_HANA_CONSTANT_CHECK(hana::equal(
  43. hana::unpack(sliced, f),
  44. f()
  45. ));
  46. }{
  47. auto storage = container(ct_eq<0>{}, ct_eq<1>{});
  48. auto sliced = hana::experimental::sliced(storage, hana::tuple_c<int, 0>);
  49. BOOST_HANA_CONSTANT_CHECK(hana::equal(
  50. hana::unpack(sliced, f),
  51. f(ct_eq<0>{})
  52. ));
  53. }{
  54. auto storage = container(ct_eq<0>{}, ct_eq<1>{});
  55. auto sliced = hana::experimental::sliced(storage, hana::tuple_c<int, 0, 1>);
  56. BOOST_HANA_CONSTANT_CHECK(hana::equal(
  57. hana::unpack(sliced, f),
  58. f(ct_eq<0>{}, ct_eq<1>{})
  59. ));
  60. }{
  61. auto storage = container(ct_eq<0>{}, ct_eq<1>{});
  62. auto sliced = hana::experimental::sliced(storage, hana::tuple_c<int, 1>);
  63. BOOST_HANA_CONSTANT_CHECK(hana::equal(
  64. hana::unpack(sliced, f),
  65. f(ct_eq<1>{})
  66. ));
  67. }{
  68. auto storage = container(ct_eq<0>{}, ct_eq<1>{});
  69. auto sliced = hana::experimental::sliced(storage, hana::tuple_c<int, 1, 0>);
  70. BOOST_HANA_CONSTANT_CHECK(hana::equal(
  71. hana::unpack(sliced, f),
  72. f(ct_eq<1>{}, ct_eq<0>{})
  73. ));
  74. }
  75. {
  76. auto storage = container(ct_eq<0>{}, ct_eq<1>{}, ct_eq<2>{});
  77. auto sliced = hana::experimental::sliced(storage, hana::tuple_c<int>);
  78. BOOST_HANA_CONSTANT_CHECK(hana::equal(
  79. hana::unpack(sliced, f),
  80. f()
  81. ));
  82. }{
  83. auto storage = container(ct_eq<0>{}, ct_eq<1>{}, ct_eq<2>{});
  84. auto sliced = hana::experimental::sliced(storage, hana::tuple_c<int, 0>);
  85. BOOST_HANA_CONSTANT_CHECK(hana::equal(
  86. hana::unpack(sliced, f),
  87. f(ct_eq<0>{})
  88. ));
  89. }{
  90. auto storage = container(ct_eq<0>{}, ct_eq<1>{}, ct_eq<2>{});
  91. auto sliced = hana::experimental::sliced(storage, hana::tuple_c<int, 1>);
  92. BOOST_HANA_CONSTANT_CHECK(hana::equal(
  93. hana::unpack(sliced, f),
  94. f(ct_eq<1>{})
  95. ));
  96. }{
  97. auto storage = container(ct_eq<0>{}, ct_eq<1>{}, ct_eq<2>{});
  98. auto sliced = hana::experimental::sliced(storage, hana::tuple_c<int, 2>);
  99. BOOST_HANA_CONSTANT_CHECK(hana::equal(
  100. hana::unpack(sliced, f),
  101. f(ct_eq<2>{})
  102. ));
  103. }{
  104. auto storage = container(ct_eq<0>{}, ct_eq<1>{}, ct_eq<2>{});
  105. auto sliced = hana::experimental::sliced(storage, hana::tuple_c<int, 0, 2>);
  106. BOOST_HANA_CONSTANT_CHECK(hana::equal(
  107. hana::unpack(sliced, f),
  108. f(ct_eq<0>{}, ct_eq<2>{})
  109. ));
  110. }{
  111. auto storage = container(ct_eq<0>{}, ct_eq<1>{}, ct_eq<2>{});
  112. auto sliced = hana::experimental::sliced(storage, hana::tuple_c<int, 1, 1>);
  113. BOOST_HANA_CONSTANT_CHECK(hana::equal(
  114. hana::unpack(sliced, f),
  115. f(ct_eq<1>{}, ct_eq<1>{})
  116. ));
  117. }
  118. {
  119. auto storage = container(ct_eq<0>{}, ct_eq<1>{}, ct_eq<2>{}, ct_eq<3>{});
  120. auto sliced = hana::experimental::sliced(storage, hana::tuple_c<int, 3, 1, 0, 2, 2>);
  121. BOOST_HANA_CONSTANT_CHECK(hana::equal(
  122. hana::unpack(sliced, f),
  123. f(ct_eq<3>{}, ct_eq<1>{}, ct_eq<0>{}, ct_eq<2>{}, ct_eq<2>{})
  124. ));
  125. }
  126. }