any_of.cpp 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839
  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/config.hpp>
  7. #include <boost/hana/ext/std/integral_constant.hpp>
  8. #include <boost/hana/integral_constant.hpp>
  9. #include <boost/hana/mod.hpp>
  10. #include <boost/hana/not.hpp>
  11. #include <boost/hana/not_equal.hpp>
  12. #include <boost/hana/traits.hpp>
  13. #include <boost/hana/tuple.hpp>
  14. #include <boost/hana/type.hpp>
  15. #include <type_traits>
  16. namespace hana = boost::hana;
  17. using namespace hana::literals;
  18. BOOST_HANA_CONSTEXPR_LAMBDA auto is_odd = [](auto x) {
  19. return x % 2_c != 0_c;
  20. };
  21. int main() {
  22. BOOST_HANA_CONSTEXPR_CHECK(hana::any_of(hana::make_tuple(1, 2), is_odd));
  23. BOOST_HANA_CONSTANT_CHECK(!hana::any_of(hana::make_tuple(2_c, 4_c), is_odd));
  24. BOOST_HANA_CONSTANT_CHECK(
  25. hana::any_of(hana::make_tuple(hana::type<void>{}, hana::type<char&>{}),
  26. hana::traits::is_void)
  27. );
  28. BOOST_HANA_CONSTANT_CHECK(
  29. !hana::any_of(hana::make_tuple(hana::type<void>{}, hana::type<char&>{}),
  30. hana::traits::is_integral)
  31. );
  32. }