comparing.cpp 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  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/comparing.hpp>
  5. #include <boost/hana/equal.hpp>
  6. #include <boost/hana/group.hpp>
  7. #include <boost/hana/length.hpp>
  8. #include <boost/hana/range.hpp>
  9. #include <boost/hana/tuple.hpp>
  10. namespace hana = boost::hana;
  11. int main() {
  12. constexpr auto sequences = hana::make_tuple(
  13. hana::make_tuple(1, 2, 3),
  14. hana::make_tuple('x', 'y', 'z'),
  15. hana::range_c<long, 0, 1>,
  16. hana::tuple_t<char, int>,
  17. hana::range_c<int, 0, 2>,
  18. hana::make_tuple(123.4, nullptr)
  19. );
  20. constexpr auto grouped = hana::group.by(hana::comparing(hana::length), sequences);
  21. static_assert(grouped == hana::make_tuple(
  22. hana::make_tuple(
  23. hana::make_tuple(1, 2, 3),
  24. hana::make_tuple('x', 'y', 'z')
  25. ),
  26. hana::make_tuple(
  27. hana::range_c<long, 0, 1>
  28. ),
  29. hana::make_tuple(
  30. hana::tuple_t<char, int>,
  31. hana::range_c<int, 0, 2>,
  32. hana::make_tuple(123.4, nullptr)
  33. )
  34. ), "");
  35. }