searchable.cpp 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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/ext/std/integral_constant.hpp>
  6. #include <boost/hana/find.hpp>
  7. #include <boost/hana/find_if.hpp>
  8. #include <boost/hana/functional/compose.hpp>
  9. #include <boost/hana/integral_constant.hpp>
  10. #include <boost/hana/optional.hpp>
  11. #include <boost/hana/tuple.hpp>
  12. #include <boost/hana/type.hpp>
  13. #include <type_traits>
  14. namespace hana = boost::hana;
  15. // First get the type of the object, and then call the trait on it.
  16. constexpr auto is_integral = hana::compose(hana::trait<std::is_integral>, hana::typeid_);
  17. constexpr auto is_class = hana::compose(hana::trait<std::is_class>, hana::typeid_);
  18. static_assert(
  19. hana::find_if(hana::make_tuple(1.0, 2, '3'), is_integral)
  20. ==
  21. hana::just(2)
  22. , "");
  23. BOOST_HANA_CONSTANT_CHECK(
  24. hana::find_if(hana::make_tuple(1.0, 2, '3'), is_class)
  25. ==
  26. hana::nothing
  27. );
  28. BOOST_HANA_CONSTANT_CHECK(
  29. hana::find(hana::make_tuple(hana::int_c<1>, hana::char_c<'c'>, hana::type_c<void>), hana::type_c<void>)
  30. ==
  31. hana::just(hana::type_c<void>)
  32. );
  33. BOOST_HANA_CONSTANT_CHECK(
  34. hana::find(hana::make_tuple(hana::int_c<1>, hana::char_c<'c'>, hana::type_c<void>), hana::type_c<int>)
  35. ==
  36. hana::nothing
  37. );
  38. int main() { }