| 1 | /*! |
| 2 | @file |
| 3 | Defines `boost::hana::zip_shortest`. |
| 4 | |
| 5 | Copyright Louis Dionne 2013-2022 |
| 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) |
| 8 | */ |
| 9 | |
| 10 | #ifndef BOOST_HANA_ZIP_SHORTEST_HPP |
| 11 | #define BOOST_HANA_ZIP_SHORTEST_HPP |
| 12 | |
| 13 | #include <boost/hana/fwd/zip_shortest.hpp> |
| 14 | |
| 15 | #include <boost/hana/concept/sequence.hpp> |
| 16 | #include <boost/hana/config.hpp> |
| 17 | #include <boost/hana/core/dispatch.hpp> |
| 18 | #include <boost/hana/detail/fast_and.hpp> |
| 19 | #include <boost/hana/tuple.hpp> |
| 20 | #include <boost/hana/zip_shortest_with.hpp> |
| 21 | |
| 22 | |
| 23 | namespace boost { namespace hana { |
| 24 | //! @cond |
| 25 | template <typename Xs, typename ...Ys> |
| 26 | constexpr auto zip_shortest_t::operator()(Xs&& xs, Ys&& ...ys) const { |
| 27 | #ifndef BOOST_HANA_CONFIG_DISABLE_CONCEPT_CHECKS |
| 28 | static_assert(detail::fast_and< |
| 29 | hana::Sequence<Xs>::value, hana::Sequence<Ys>::value... |
| 30 | >::value, |
| 31 | "hana::zip_shortest(xs, ys...) requires 'xs' and 'ys...' to be Sequences" ); |
| 32 | #endif |
| 33 | |
| 34 | return zip_shortest_impl<typename hana::tag_of<Xs>::type>::apply( |
| 35 | static_cast<Xs&&>(xs), |
| 36 | static_cast<Ys&&>(ys)... |
| 37 | ); |
| 38 | } |
| 39 | //! @endcond |
| 40 | |
| 41 | template <typename S, bool condition> |
| 42 | struct zip_shortest_impl<S, when<condition>> : default_ { |
| 43 | template <typename ...Xs> |
| 44 | static constexpr decltype(auto) apply(Xs&& ...xs) { |
| 45 | return hana::zip_shortest_with(hana::make_tuple, |
| 46 | static_cast<Xs&&>(xs)...); |
| 47 | } |
| 48 | }; |
| 49 | }} // end namespace boost::hana |
| 50 | |
| 51 | #endif // !BOOST_HANA_ZIP_SHORTEST_HPP |
| 52 | |