unpack.cpp 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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/tuple.hpp>
  7. #include <boost/hana/type.hpp>
  8. #include <boost/hana/unpack.hpp>
  9. #include <laws/base.hpp>
  10. namespace hana = boost::hana;
  11. using hana::test::ct_eq;
  12. template <typename ...>
  13. struct F { struct type; };
  14. struct x0;
  15. struct x1;
  16. struct x2;
  17. struct x3;
  18. int main() {
  19. hana::test::_injection<0> f{};
  20. // tuple
  21. BOOST_HANA_CONSTANT_CHECK(hana::equal(
  22. hana::unpack(hana::make_tuple(), f),
  23. f()
  24. ));
  25. BOOST_HANA_CONSTANT_CHECK(hana::equal(
  26. hana::unpack(hana::make_tuple(ct_eq<0>{}), f),
  27. f(ct_eq<0>{})
  28. ));
  29. BOOST_HANA_CONSTANT_CHECK(hana::equal(
  30. hana::unpack(hana::make_tuple(ct_eq<0>{}, ct_eq<1>{}), f),
  31. f(ct_eq<0>{}, ct_eq<1>{})
  32. ));
  33. BOOST_HANA_CONSTANT_CHECK(hana::equal(
  34. hana::unpack(hana::make_tuple(ct_eq<0>{}, ct_eq<1>{}, ct_eq<2>{}), f),
  35. f(ct_eq<0>{}, ct_eq<1>{}, ct_eq<2>{})
  36. ));
  37. // tuple_t
  38. BOOST_HANA_CONSTANT_CHECK(hana::equal(
  39. hana::unpack(hana::tuple_t<>, f),
  40. f()
  41. ));
  42. BOOST_HANA_CONSTANT_CHECK(hana::equal(
  43. hana::unpack(hana::tuple_t<x0>, f),
  44. f(hana::type_c<x0>)
  45. ));
  46. BOOST_HANA_CONSTANT_CHECK(hana::equal(
  47. hana::unpack(hana::tuple_t<x0, x1>, f),
  48. f(hana::type_c<x0>, hana::type_c<x1>)
  49. ));
  50. BOOST_HANA_CONSTANT_CHECK(hana::equal(
  51. hana::unpack(hana::tuple_t<x0, x1, x2>, f),
  52. f(hana::type_c<x0>, hana::type_c<x1>, hana::type_c<x2>)
  53. ));
  54. BOOST_HANA_CONSTANT_CHECK(hana::equal(
  55. hana::unpack(hana::tuple_t<x0, x1, x2, x3>, f),
  56. f(hana::type_c<x0>, hana::type_c<x1>, hana::type_c<x2>, hana::type_c<x3>)
  57. ));
  58. // tuple_t with metafunction
  59. auto g = hana::metafunction<F>;
  60. BOOST_HANA_CONSTANT_CHECK(hana::equal(
  61. hana::unpack(hana::tuple_t<>, g),
  62. g()
  63. ));
  64. BOOST_HANA_CONSTANT_CHECK(hana::equal(
  65. hana::unpack(hana::tuple_t<x0>, g),
  66. g(hana::type_c<x0>)
  67. ));
  68. BOOST_HANA_CONSTANT_CHECK(hana::equal(
  69. hana::unpack(hana::tuple_t<x0, x1>, g),
  70. g(hana::type_c<x0>, hana::type_c<x1>)
  71. ));
  72. BOOST_HANA_CONSTANT_CHECK(hana::equal(
  73. hana::unpack(hana::tuple_t<x0, x1, x2>, g),
  74. g(hana::type_c<x0>, hana::type_c<x1>, hana::type_c<x2>)
  75. ));
  76. BOOST_HANA_CONSTANT_CHECK(hana::equal(
  77. hana::unpack(hana::tuple_t<x0, x1, x2, x3>, g),
  78. g(hana::type_c<x0>, hana::type_c<x1>, hana::type_c<x2>, hana::type_c<x3>)
  79. ));
  80. }