zip.hpp 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. /*!
  2. @file
  3. Defines `boost::hana::zip`.
  4. Copyright Louis Dionne 2013-2022
  5. Distributed under the Boost Software License, Version 1.0.
  6. (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
  7. */
  8. #ifndef BOOST_HANA_ZIP_HPP
  9. #define BOOST_HANA_ZIP_HPP
  10. #include <boost/hana/fwd/zip.hpp>
  11. #include <boost/hana/concept/sequence.hpp>
  12. #include <boost/hana/config.hpp>
  13. #include <boost/hana/core/dispatch.hpp>
  14. #include <boost/hana/detail/fast_and.hpp>
  15. #include <boost/hana/tuple.hpp>
  16. #include <boost/hana/zip_with.hpp>
  17. namespace boost { namespace hana {
  18. //! @cond
  19. template <typename Xs, typename ...Ys>
  20. constexpr auto zip_t::operator()(Xs&& xs, Ys&& ...ys) const {
  21. #ifndef BOOST_HANA_CONFIG_DISABLE_CONCEPT_CHECKS
  22. static_assert(detail::fast_and<
  23. hana::Sequence<Xs>::value, hana::Sequence<Ys>::value...
  24. >::value,
  25. "hana::zip(xs, ys...) requires 'xs' and 'ys...' to be Sequences");
  26. #endif
  27. return zip_impl<typename hana::tag_of<Xs>::type>::apply(
  28. static_cast<Xs&&>(xs),
  29. static_cast<Ys&&>(ys)...
  30. );
  31. }
  32. //! @endcond
  33. template <typename S, bool condition>
  34. struct zip_impl<S, when<condition>> : default_ {
  35. template <typename ...Xs>
  36. static constexpr decltype(auto) apply(Xs&& ...xs) {
  37. return hana::zip_with(hana::make_tuple, static_cast<Xs&&>(xs)...);
  38. }
  39. };
  40. }} // end namespace boost::hana
  41. #endif // !BOOST_HANA_ZIP_HPP