9
3

unpack.cpp 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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/types.hpp>
  7. #include <boost/hana/type.hpp>
  8. #include <boost/hana/unpack.hpp>
  9. #include <laws/base.hpp>
  10. namespace hana = boost::hana;
  11. template <typename ...>
  12. struct mf { struct type; };
  13. template <int> struct x;
  14. int main() {
  15. // with a Metafunction
  16. {
  17. BOOST_HANA_CONSTANT_CHECK(hana::equal(
  18. hana::unpack(hana::experimental::types<>{}, hana::metafunction<mf>),
  19. hana::type_c<mf<>::type>
  20. ));
  21. BOOST_HANA_CONSTANT_CHECK(hana::equal(
  22. hana::unpack(hana::experimental::types<x<0>>{}, hana::metafunction<mf>),
  23. hana::type_c<mf<x<0>>::type>
  24. ));
  25. BOOST_HANA_CONSTANT_CHECK(hana::equal(
  26. hana::unpack(hana::experimental::types<x<0>, x<1>>{}, hana::metafunction<mf>),
  27. hana::type_c<mf<x<0>, x<1>>::type>
  28. ));
  29. BOOST_HANA_CONSTANT_CHECK(hana::equal(
  30. hana::unpack(hana::experimental::types<x<0>, x<1>, x<2>>{}, hana::metafunction<mf>),
  31. hana::type_c<mf<x<0>, x<1>, x<2>>::type>
  32. ));
  33. BOOST_HANA_CONSTANT_CHECK(hana::equal(
  34. hana::unpack(hana::experimental::types<x<0>, x<1>, x<2>, x<3>>{}, hana::metafunction<mf>),
  35. hana::type_c<mf<x<0>, x<1>, x<2>, x<3>>::type>
  36. ));
  37. BOOST_HANA_CONSTANT_CHECK(hana::equal(
  38. hana::unpack(hana::experimental::types<x<0>, x<1>, x<2>, x<3>, x<4>>{}, hana::metafunction<mf>),
  39. hana::type_c<mf<x<0>, x<1>, x<2>, x<3>, x<4>>::type>
  40. ));
  41. }
  42. // with a non-Metafunction
  43. {
  44. auto f = hana::test::_injection<0>{};
  45. BOOST_HANA_CONSTANT_CHECK(hana::equal(
  46. hana::unpack(hana::experimental::types<>{}, f),
  47. f()
  48. ));
  49. BOOST_HANA_CONSTANT_CHECK(hana::equal(
  50. hana::unpack(hana::experimental::types<x<0>>{}, f),
  51. f(hana::type_c<x<0>>)
  52. ));
  53. BOOST_HANA_CONSTANT_CHECK(hana::equal(
  54. hana::unpack(hana::experimental::types<x<0>, x<1>>{}, f),
  55. f(hana::type_c<x<0>>, hana::type_c<x<1>>)
  56. ));
  57. BOOST_HANA_CONSTANT_CHECK(hana::equal(
  58. hana::unpack(hana::experimental::types<x<0>, x<1>, x<2>>{}, f),
  59. f(hana::type_c<x<0>>, hana::type_c<x<1>>, hana::type_c<x<2>>)
  60. ));
  61. BOOST_HANA_CONSTANT_CHECK(hana::equal(
  62. hana::unpack(hana::experimental::types<x<0>, x<1>, x<2>, x<3>>{}, f),
  63. f(hana::type_c<x<0>>, hana::type_c<x<1>>, hana::type_c<x<2>>, hana::type_c<x<3>>)
  64. ));
  65. }
  66. }