unpack.cpp 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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/core/make.hpp>
  6. #include <boost/hana/core/tag_of.hpp>
  7. #include <boost/hana/equal.hpp>
  8. #include <boost/hana/integral_constant.hpp>
  9. #include <boost/hana/range.hpp>
  10. #include <boost/hana/unpack.hpp>
  11. #include <laws/base.hpp>
  12. #include <type_traits>
  13. namespace hana = boost::hana;
  14. int main() {
  15. hana::test::_injection<0> f{};
  16. BOOST_HANA_CONSTANT_CHECK(hana::equal(
  17. hana::unpack(hana::make_range(hana::int_c<0>, hana::int_c<0>), f),
  18. f()
  19. ));
  20. BOOST_HANA_CONSTANT_CHECK(hana::equal(
  21. hana::unpack(hana::make_range(hana::int_c<0>, hana::int_c<1>), f),
  22. f(hana::int_c<0>)
  23. ));
  24. BOOST_HANA_CONSTANT_CHECK(hana::equal(
  25. hana::unpack(hana::make_range(hana::int_c<0>, hana::int_c<2>), f),
  26. f(hana::int_c<0>, hana::int_c<1>)
  27. ));
  28. BOOST_HANA_CONSTANT_CHECK(hana::equal(
  29. hana::unpack(hana::make_range(hana::int_c<0>, hana::int_c<3>), f),
  30. f(hana::int_c<0>, hana::int_c<1>, hana::int_c<2>)
  31. ));
  32. // Previously, we would only unpack with `std::size_t`s. Make
  33. // sure this does not happen.
  34. hana::unpack(hana::make_range(hana::int_c<0>, hana::int_c<1>), [](auto x) {
  35. using T = hana::tag_of_t<decltype(x)>;
  36. static_assert(std::is_same<typename T::value_type, int>{}, "");
  37. });
  38. }