on.cpp 1.1 KB

123456789101112131415161718192021222324252627282930313233343536
  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/first.hpp>
  5. #include <boost/hana/functional/on.hpp>
  6. #include <boost/hana/integral_constant.hpp>
  7. #include <boost/hana/less.hpp>
  8. #include <boost/hana/pair.hpp>
  9. #include <boost/hana/plus.hpp>
  10. #include <boost/hana/sort.hpp>
  11. #include <boost/hana/tuple.hpp>
  12. #include <boost/hana/type.hpp>
  13. namespace hana = boost::hana;
  14. // infix application
  15. constexpr auto sorted = hana::sort.by(hana::less ^hana::on^ hana::first, hana::make_tuple(
  16. hana::make_pair(hana::int_c<3>, 'x'),
  17. hana::make_pair(hana::int_c<1>, hana::type_c<void>),
  18. hana::make_pair(hana::int_c<2>, 9876)
  19. ));
  20. static_assert(sorted == hana::make_tuple(
  21. hana::make_pair(hana::int_c<1>, hana::type_c<void>),
  22. hana::make_pair(hana::int_c<2>, 9876),
  23. hana::make_pair(hana::int_c<3>, 'x')
  24. ), "");
  25. // function call syntax
  26. constexpr auto x = hana::make_pair(1, 2);
  27. constexpr auto y = hana::make_pair(10, 20);
  28. static_assert(hana::on(hana::plus, hana::first)(x, y) == 1 + 10, "");
  29. int main() { }