zip_with.cpp 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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/equal.hpp>
  5. #include <boost/hana/ext/std/tuple.hpp>
  6. #include <boost/hana/mult.hpp>
  7. #include <boost/hana/transform.hpp>
  8. #include <boost/hana/tuple.hpp>
  9. #include <boost/hana/type.hpp>
  10. #include <boost/hana/unpack.hpp>
  11. #include <boost/hana/zip_with.hpp>
  12. #include <tuple>
  13. #include <type_traits>
  14. #include <utility>
  15. namespace hana = boost::hana;
  16. // Basic usage:
  17. static_assert(
  18. hana::zip_with(hana::mult, hana::make_tuple(1, 2, 3, 4), hana::make_tuple(5, 6, 7, 8))
  19. ==
  20. hana::make_tuple(5, 12, 21, 32)
  21. , "");
  22. // Example of computing a tuple of all the common types of several tuples:
  23. template<typename... Ts>
  24. using common_tuple_t = typename decltype(
  25. hana::unpack(
  26. hana::zip_with(
  27. hana::metafunction<std::common_type>,
  28. hana::transform(std::declval<Ts>(), hana::decltype_)...
  29. ),
  30. hana::template_<std::tuple>
  31. )
  32. )::type;
  33. static_assert(std::is_same<
  34. common_tuple_t<
  35. std::tuple<bool, int, unsigned>,
  36. std::tuple<char, long, long>,
  37. std::tuple<int, long long, double>
  38. >,
  39. std::tuple<int, long long, double>
  40. >::value, "");
  41. int main() { }