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