3 Defines `boost::hana::zip_with`.
5 @copyright Louis Dionne 2013-2016
6 Distributed under the Boost Software License, Version 1.0.
7 (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
10 #ifndef BOOST_HANA_ZIP_WITH_HPP
11 #define BOOST_HANA_ZIP_WITH_HPP
13 #include <boost/hana/fwd/zip_with.hpp>
15 #include <boost/hana/at.hpp>
16 #include <boost/hana/concept/sequence.hpp>
17 #include <boost/hana/config.hpp>
18 #include <boost/hana/core/dispatch.hpp>
19 #include <boost/hana/core/make.hpp>
20 #include <boost/hana/detail/fast_and.hpp>
21 #include <boost/hana/length.hpp>
27 BOOST_HANA_NAMESPACE_BEGIN
29 template <typename F, typename Xs, typename ...Ys>
30 constexpr auto zip_with_t::operator()(F&& f, Xs&& xs, Ys&& ...ys) const {
31 #ifndef BOOST_HANA_CONFIG_DISABLE_CONCEPT_CHECKS
32 static_assert(detail::fast_and<
33 hana::Sequence<Xs>::value, hana::Sequence<Ys>::value...
35 "hana::zip_with(f, xs, ys...) requires 'xs' and 'ys...' to be Sequences");
38 return zip_with_impl<typename hana::tag_of<Xs>::type>::apply(
40 static_cast<Xs&&>(xs),
41 static_cast<Ys&&>(ys)...
47 struct zip_with_impl<S, when<Sequence<S>::value>> {
48 template <std::size_t N, typename F, typename ...Xs>
49 static constexpr decltype(auto) transverse(F&& f, Xs&& ...xs) {
50 return static_cast<F&&>(f)(hana::at_c<N>(static_cast<Xs&&>(xs))...);
53 template <std::size_t ...N, typename F, typename ...Xs>
55 zip_helper(std::index_sequence<N...>, F&& f, Xs&& ...xs) {
56 return hana::make<S>(transverse<N>(f, xs...)...);
59 template <typename F, typename X, typename ...Xs>
61 apply(F&& f, X&& x, Xs&& ...xs) {
62 constexpr std::size_t N = decltype(hana::length(x))::value;
63 return zip_helper(std::make_index_sequence<N>{},
65 static_cast<X&&>(x), static_cast<Xs&&>(xs)...);
68 BOOST_HANA_NAMESPACE_END
70 #endif // !BOOST_HANA_ZIP_WITH_HPP