any_of.cpp 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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/any_of.hpp>
  5. #include <boost/hana/assert.hpp>
  6. #include <boost/hana/equal.hpp>
  7. #include <boost/hana/map.hpp>
  8. #include <boost/hana/not.hpp>
  9. #include <laws/base.hpp>
  10. #include <support/minimal_product.hpp>
  11. namespace hana = boost::hana;
  12. template <int i>
  13. auto key() { return hana::test::ct_eq<i>{}; }
  14. template <int i>
  15. auto val() { return hana::test::ct_eq<-i>{}; }
  16. template <int i, int j>
  17. auto p() { return ::minimal_product(key<i>(), val<j>()); }
  18. int main() {
  19. BOOST_HANA_CONSTANT_CHECK(hana::not_(hana::any_of(
  20. hana::make_map(),
  21. hana::equal.to(key<1>()
  22. ))));
  23. BOOST_HANA_CONSTANT_CHECK(hana::any_of(
  24. hana::make_map(p<1, 1>()),
  25. hana::equal.to(key<1>())
  26. ));
  27. BOOST_HANA_CONSTANT_CHECK(hana::not_(hana::any_of(
  28. hana::make_map(p<1, 1>()),
  29. hana::equal.to(key<2>())
  30. )));
  31. BOOST_HANA_CONSTANT_CHECK(hana::any_of(
  32. hana::make_map(p<1, 1>(), p<2, 2>()),
  33. hana::equal.to(key<1>())
  34. ));
  35. BOOST_HANA_CONSTANT_CHECK(hana::any_of(
  36. hana::make_map(p<1, 1>(), p<2, 2>()),
  37. hana::equal.to(key<2>())
  38. ));
  39. BOOST_HANA_CONSTANT_CHECK(hana::not_(hana::any_of(
  40. hana::make_map(p<1, 1>(), p<2, 2>()),
  41. hana::equal.to(key<3>())
  42. )));
  43. }