File indexing completed on 2025-01-30 09:43:41
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010 #ifndef BOOST_HANA_ZIP_SHORTEST_WITH_HPP
0011 #define BOOST_HANA_ZIP_SHORTEST_WITH_HPP
0012
0013 #include <boost/hana/fwd/zip_shortest_with.hpp>
0014
0015 #include <boost/hana/concept/sequence.hpp>
0016 #include <boost/hana/core/dispatch.hpp>
0017 #include <boost/hana/config.hpp>
0018 #include <boost/hana/detail/algorithm.hpp>
0019 #include <boost/hana/detail/fast_and.hpp>
0020 #include <boost/hana/integral_constant.hpp>
0021 #include <boost/hana/length.hpp>
0022 #include <boost/hana/take_front.hpp>
0023 #include <boost/hana/zip_with.hpp>
0024
0025 #include <cstddef>
0026
0027
0028 namespace boost { namespace hana {
0029
0030 template <typename F, typename Xs, typename ...Ys>
0031 constexpr auto
0032 zip_shortest_with_t::operator()(F&& f, Xs&& xs, Ys&& ...ys) const {
0033 #ifndef BOOST_HANA_CONFIG_DISABLE_CONCEPT_CHECKS
0034 static_assert(detail::fast_and<
0035 hana::Sequence<Xs>::value, hana::Sequence<Ys>::value...
0036 >::value,
0037 "hana::zip_shortest_with(f, xs, ys...) requires 'xs' and 'ys...' to be Sequences");
0038 #endif
0039
0040 return zip_shortest_with_impl<typename hana::tag_of<Xs>::type>::apply(
0041 static_cast<F&&>(f),
0042 static_cast<Xs&&>(xs),
0043 static_cast<Ys&&>(ys)...
0044 );
0045 }
0046
0047
0048 template <typename S, bool condition>
0049 struct zip_shortest_with_impl<S, when<condition>> : default_ {
0050 template <typename F, typename ...Xs>
0051 static constexpr decltype(auto) apply(F&& f, Xs&& ...xs) {
0052 constexpr std::size_t lengths[] = {
0053 decltype(hana::length(xs))::value...
0054 };
0055 constexpr std::size_t min_len =
0056 *detail::min_element(lengths, lengths + sizeof...(xs));
0057 return hana::zip_with(static_cast<F&&>(f),
0058 hana::take_front(static_cast<Xs&&>(xs), hana::size_c<min_len>)...
0059 );
0060 }
0061 };
0062 }}
0063
0064 #endif