unpack.cpp 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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/contains.hpp>
  6. #include <boost/hana/equal.hpp>
  7. #include <boost/hana/unpack.hpp>
  8. #include <boost/hana/map.hpp>
  9. #include <boost/hana/permutations.hpp>
  10. #include <boost/hana/transform.hpp>
  11. #include <laws/base.hpp>
  12. #include <support/minimal_product.hpp>
  13. #include <support/seq.hpp>
  14. namespace hana = boost::hana;
  15. template <int i>
  16. auto key() { return hana::test::ct_eq<i>{}; }
  17. template <int i>
  18. auto val() { return hana::test::ct_eq<-i>{}; }
  19. template <int i, int j>
  20. auto p() { return ::minimal_product(key<i>(), val<j>()); }
  21. struct undefined { };
  22. int main() {
  23. auto sequence = ::seq;
  24. hana::test::_injection<0> f{};
  25. auto check = [=](auto ...pairs) {
  26. auto possible_results = hana::transform(hana::permutations(sequence(pairs...)),
  27. [=](auto xs) { return hana::unpack(xs, f); }
  28. );
  29. BOOST_HANA_CONSTANT_CHECK(hana::contains(
  30. possible_results,
  31. hana::unpack(hana::make_map(pairs...), f)
  32. ));
  33. };
  34. check();
  35. check(p<1, 1>());
  36. check(p<1, 1>(), p<2, 2>());
  37. check(p<1, 1>(), p<2, 2>(), p<3, 3>());
  38. check(p<1, 1>(), p<2, 2>(), p<3, 3>(), p<4, 4>());
  39. }