zip_shortest.hpp 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. /*!
  2. @file
  3. Defines `boost::hana::zip_shortest`.
  4. @copyright Louis Dionne 2013-2017
  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_SHORTEST_HPP
  9. #define BOOST_HANA_ZIP_SHORTEST_HPP
  10. #include <boost/hana/fwd/zip_shortest.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_shortest_with.hpp>
  17. BOOST_HANA_NAMESPACE_BEGIN
  18. //! @cond
  19. template <typename Xs, typename ...Ys>
  20. constexpr auto zip_shortest_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_shortest(xs, ys...) requires 'xs' and 'ys...' to be Sequences");
  26. #endif
  27. return zip_shortest_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_shortest_impl<S, when<condition>> : default_ {
  35. template <typename ...Xs>
  36. static constexpr decltype(auto) apply(Xs&& ...xs) {
  37. return hana::zip_shortest_with(hana::make_tuple,
  38. static_cast<Xs&&>(xs)...);
  39. }
  40. };
  41. BOOST_HANA_NAMESPACE_END
  42. #endif // !BOOST_HANA_ZIP_SHORTEST_HPP