partition.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/assert.hpp>
  5. #include <boost/hana/equal.hpp>
  6. #include <boost/hana/ext/std/integral_constant.hpp>
  7. #include <boost/hana/integral_constant.hpp>
  8. #include <boost/hana/mod.hpp>
  9. #include <boost/hana/not_equal.hpp>
  10. #include <boost/hana/pair.hpp>
  11. #include <boost/hana/partition.hpp>
  12. #include <boost/hana/tuple.hpp>
  13. #include <boost/hana/type.hpp>
  14. #include <type_traits>
  15. namespace hana = boost::hana;
  16. BOOST_HANA_CONSTANT_CHECK(
  17. hana::partition(hana::tuple_c<int, 1, 2, 3, 4, 5, 6, 7>, [](auto x) {
  18. return x % hana::int_c<2> != hana::int_c<0>;
  19. })
  20. ==
  21. hana::make_pair(
  22. hana::tuple_c<int, 1, 3, 5, 7>,
  23. hana::tuple_c<int, 2, 4, 6>
  24. )
  25. );
  26. BOOST_HANA_CONSTANT_CHECK(
  27. hana::partition(hana::tuple_t<void, int, float, char, double>, hana::trait<std::is_floating_point>)
  28. ==
  29. hana::make_pair(
  30. hana::tuple_t<float, double>,
  31. hana::tuple_t<void, int, char>
  32. )
  33. );
  34. // partition.by is syntactic sugar
  35. BOOST_HANA_CONSTANT_CHECK(
  36. hana::partition.by(hana::trait<std::is_floating_point>,
  37. hana::tuple_t<void, int, float, char, double>)
  38. ==
  39. hana::make_pair(
  40. hana::tuple_t<float, double>,
  41. hana::tuple_t<void, int, char>
  42. )
  43. );
  44. int main() { }