Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:38:07

0001 /*!
0002 @file
0003 Defines `boost::hana::zip_with`.
0004 
0005 Copyright Louis Dionne 2013-2022
0006 Distributed under the Boost Software License, Version 1.0.
0007 (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
0008  */
0009 
0010 #ifndef BOOST_HANA_ZIP_WITH_HPP
0011 #define BOOST_HANA_ZIP_WITH_HPP
0012 
0013 #include <boost/hana/fwd/zip_with.hpp>
0014 
0015 #include <boost/hana/at.hpp>
0016 #include <boost/hana/concept/sequence.hpp>
0017 #include <boost/hana/config.hpp>
0018 #include <boost/hana/core/dispatch.hpp>
0019 #include <boost/hana/core/make.hpp>
0020 #include <boost/hana/detail/fast_and.hpp>
0021 #include <boost/hana/length.hpp>
0022 
0023 #include <cstddef>
0024 #include <utility>
0025 
0026 
0027 namespace boost { namespace hana {
0028     //! @cond
0029     template <typename F, typename Xs, typename ...Ys>
0030     constexpr auto zip_with_t::operator()(F&& f, Xs&& xs, Ys&& ...ys) const {
0031     #ifndef BOOST_HANA_CONFIG_DISABLE_CONCEPT_CHECKS
0032         static_assert(detail::fast_and<
0033             hana::Sequence<Xs>::value, hana::Sequence<Ys>::value...
0034         >::value,
0035         "hana::zip_with(f, xs, ys...) requires 'xs' and 'ys...' to be Sequences");
0036     #endif
0037 
0038         return zip_with_impl<typename hana::tag_of<Xs>::type>::apply(
0039             static_cast<F&&>(f),
0040             static_cast<Xs&&>(xs),
0041             static_cast<Ys&&>(ys)...
0042         );
0043     }
0044     //! @endcond
0045 
0046     template <typename S>
0047     struct zip_with_impl<S, when<Sequence<S>::value>> {
0048         template <std::size_t N, typename F, typename ...Xs>
0049         static constexpr decltype(auto) transverse(F&& f, Xs&& ...xs) {
0050             return static_cast<F&&>(f)(hana::at_c<N>(static_cast<Xs&&>(xs))...);
0051         }
0052 
0053         template <std::size_t ...N, typename F, typename ...Xs>
0054         static constexpr auto
0055         zip_helper(std::index_sequence<N...>, F&& f, Xs&& ...xs) {
0056             return hana::make<S>(transverse<N>(f, xs...)...);
0057         }
0058 
0059         template <typename F, typename X, typename ...Xs>
0060         static constexpr auto
0061         apply(F&& f, X&& x, Xs&& ...xs) {
0062             constexpr std::size_t N = decltype(hana::length(x))::value;
0063             return zip_helper(std::make_index_sequence<N>{},
0064                               static_cast<F&&>(f),
0065                               static_cast<X&&>(x), static_cast<Xs&&>(xs)...);
0066         }
0067     };
0068 }} // end namespace boost::hana
0069 
0070 #endif // !BOOST_HANA_ZIP_WITH_HPP