keys.cpp 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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/keys.hpp>
  8. #include <boost/hana/map.hpp>
  9. #include <boost/hana/permutations.hpp>
  10. #include <laws/base.hpp>
  11. #include <support/seq.hpp>
  12. #include <support/minimal_product.hpp>
  13. namespace hana = boost::hana;
  14. template <int i>
  15. auto key() { return hana::test::ct_eq<i>{}; }
  16. template <int i>
  17. auto val() { return hana::test::ct_eq<-i>{}; }
  18. template <int i, int j>
  19. auto p() { return ::minimal_product(key<i>(), val<j>()); }
  20. int main() {
  21. constexpr auto list = ::seq;
  22. BOOST_HANA_CONSTANT_CHECK(hana::equal(
  23. hana::keys(hana::make_map()),
  24. list()
  25. ));
  26. BOOST_HANA_CONSTANT_CHECK(hana::equal(
  27. hana::keys(hana::make_map(p<1, 1>())),
  28. list(key<1>())
  29. ));
  30. BOOST_HANA_CONSTANT_CHECK(hana::contains(
  31. hana::permutations(list(key<1>(), key<2>())),
  32. hana::keys(hana::make_map(p<1, 1>(), p<2, 2>()))
  33. ));
  34. BOOST_HANA_CONSTANT_CHECK(hana::contains(
  35. hana::permutations(list(key<1>(), key<2>(), key<3>())),
  36. hana::keys(hana::make_map(p<1, 1>(), p<2, 2>(), p<3, 3>()))
  37. ));
  38. }