ap.cpp 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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/ap.hpp>
  5. #include <boost/hana/assert.hpp>
  6. #include <boost/hana/config.hpp>
  7. #include <boost/hana/equal.hpp>
  8. #include <boost/hana/optional.hpp>
  9. #include <boost/hana/tuple.hpp>
  10. #include <functional>
  11. namespace hana = boost::hana;
  12. int main() {
  13. // with tuples
  14. static_assert(
  15. hana::ap(hana::make_tuple(std::plus<>{}), hana::make_tuple(1, 2),
  16. hana::make_tuple(3, 4, 5))
  17. ==
  18. hana::make_tuple(
  19. 1 + 3, 1 + 4, 1 + 5,
  20. 2 + 3, 2 + 4, 2 + 5
  21. )
  22. , "");
  23. // with optional values
  24. BOOST_HANA_CONSTEXPR_LAMBDA auto multiply = [](auto a, auto b, auto c) {
  25. return a * b * c;
  26. };
  27. BOOST_HANA_CONSTEXPR_CHECK(
  28. hana::ap(hana::just(multiply), hana::just(1),
  29. hana::just(2),
  30. hana::just(3))
  31. ==
  32. hana::just(1 * 2 * 3)
  33. );
  34. BOOST_HANA_CONSTANT_CHECK(
  35. hana::ap(hana::just(multiply), hana::just(1),
  36. hana::nothing,
  37. hana::just(3))
  38. ==
  39. hana::nothing
  40. );
  41. }