filter.cpp 982 B

12345678910111213141516171819202122232425
  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/equal.hpp>
  6. #include <boost/hana/ext/std/integral_constant.hpp>
  7. #include <boost/hana/filter.hpp>
  8. #include <boost/hana/functional/compose.hpp>
  9. #include <boost/hana/optional.hpp>
  10. #include <boost/hana/tuple.hpp>
  11. #include <boost/hana/type.hpp>
  12. #include <type_traits>
  13. namespace hana = boost::hana;
  14. // First take the type of an object, and then tell whether it's integral
  15. constexpr auto is_integral = hana::compose(hana::trait<std::is_integral>, hana::typeid_);
  16. static_assert(hana::filter(hana::make_tuple(1, 2.0, 3, 4.0), is_integral) == hana::make_tuple(1, 3), "");
  17. static_assert(hana::filter(hana::just(3), is_integral) == hana::just(3), "");
  18. BOOST_HANA_CONSTANT_CHECK(hana::filter(hana::just(3.0), is_integral) == hana::nothing);
  19. int main() { }