]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | /*! |
2 | @file | |
3 | Defines `boost::hana::zip_shortest_with`. | |
4 | ||
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) | |
8 | */ | |
9 | ||
10 | #ifndef BOOST_HANA_ZIP_SHORTEST_WITH_HPP | |
11 | #define BOOST_HANA_ZIP_SHORTEST_WITH_HPP | |
12 | ||
13 | #include <boost/hana/fwd/zip_shortest_with.hpp> | |
14 | ||
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> | |
24 | ||
25 | #include <cstddef> | |
26 | ||
27 | ||
28 | BOOST_HANA_NAMESPACE_BEGIN | |
29 | //! @cond | |
30 | template <typename F, typename Xs, typename ...Ys> | |
31 | constexpr auto | |
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... | |
36 | >::value, | |
37 | "hana::zip_shortest_with(f, xs, ys...) requires 'xs' and 'ys...' to be Sequences"); | |
38 | #endif | |
39 | ||
40 | return zip_shortest_with_impl<typename hana::tag_of<Xs>::type>::apply( | |
41 | static_cast<F&&>(f), | |
42 | static_cast<Xs&&>(xs), | |
43 | static_cast<Ys&&>(ys)... | |
44 | ); | |
45 | } | |
46 | //! @endcond | |
47 | ||
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... | |
54 | }; | |
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>)... | |
58 | ); | |
59 | } | |
60 | }; | |
61 | BOOST_HANA_NAMESPACE_END | |
62 | ||
63 | #endif // !BOOST_HANA_ZIP_SHORTEST_WITH_HPP |