3 Defines `boost::hana::zip_shortest_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_SHORTEST_WITH_HPP
11 #define BOOST_HANA_ZIP_SHORTEST_WITH_HPP
13 #include <boost/hana/fwd/zip_shortest_with.hpp>
15 #include <boost/hana/concept/sequence.hpp>
16 #include <boost/hana/core/dispatch.hpp>
17 #include <boost/hana/config.hpp>
18 #include <boost/hana/detail/algorithm.hpp>
19 #include <boost/hana/detail/fast_and.hpp>
20 #include <boost/hana/integral_constant.hpp>
21 #include <boost/hana/length.hpp>
22 #include <boost/hana/take_front.hpp>
23 #include <boost/hana/zip_with.hpp>
28 BOOST_HANA_NAMESPACE_BEGIN
30 template <typename F, typename Xs, typename ...Ys>
32 zip_shortest_with_t::operator()(F&& f, Xs&& xs, Ys&& ...ys) const {
33 #ifndef BOOST_HANA_CONFIG_DISABLE_CONCEPT_CHECKS
34 static_assert(detail::fast_and<
35 hana::Sequence<Xs>::value, hana::Sequence<Ys>::value...
37 "hana::zip_shortest_with(f, xs, ys...) requires 'xs' and 'ys...' to be Sequences");
40 return zip_shortest_with_impl<typename hana::tag_of<Xs>::type>::apply(
42 static_cast<Xs&&>(xs),
43 static_cast<Ys&&>(ys)...
48 template <typename S, bool condition>
49 struct zip_shortest_with_impl<S, when<condition>> : default_ {
50 template <typename F, typename ...Xs>
51 static constexpr decltype(auto) apply(F&& f, Xs&& ...xs) {
52 constexpr std::size_t lengths[] = {
53 decltype(hana::length(xs))::value...
55 constexpr std::size_t min = *detail::min_element(lengths, lengths + sizeof...(xs));
56 return hana::zip_with(static_cast<F&&>(f),
57 hana::take_front(static_cast<Xs&&>(xs), hana::size_c<min>)...
61 BOOST_HANA_NAMESPACE_END
63 #endif // !BOOST_HANA_ZIP_SHORTEST_WITH_HPP