zip_shortest.hpp 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /*!
  2. @file
  3. Forward declares `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_FWD_ZIP_SHORTEST_HPP
  9. #define BOOST_HANA_FWD_ZIP_SHORTEST_HPP
  10. #include <boost/hana/config.hpp>
  11. #include <boost/hana/core/when.hpp>
  12. BOOST_HANA_NAMESPACE_BEGIN
  13. //! Zip one sequence or more.
  14. //! @ingroup group-Sequence
  15. //!
  16. //! Given `n` sequences `s1, ..., sn`, `zip_shortest` produces a sequence
  17. //! whose `i`-th element is a tuple of `(s1[i], ..., sn[i])`, where `sk[i]`
  18. //! denotes the `i`-th element of the `k`-th sequence. In other words,
  19. //! `zip_shortest` produces a sequence of the form
  20. //! @code
  21. //! [
  22. //! make_tuple(s1[0], ..., sn[0]),
  23. //! make_tuple(s1[1], ..., sn[1]),
  24. //! ...
  25. //! make_tuple(s1[M], ..., sn[M])
  26. //! ]
  27. //! @endcode
  28. //! where `M` is the length of the shortest sequence. Hence, the returned
  29. //! sequence stops when the shortest input sequence is exhausted. If you
  30. //! know that all the sequences you are about to zip have the same length,
  31. //! you should use `zip` instead, since it can be more optimized. Also
  32. //! note that it is an error to provide no sequence at all, i.e.
  33. //! `zip_shortest` expects at least one sequence.
  34. //!
  35. //!
  36. //! Example
  37. //! -------
  38. //! @include example/zip_shortest.cpp
  39. #ifdef BOOST_HANA_DOXYGEN_INVOKED
  40. constexpr auto zip_shortest = [](auto&& x1, ..., auto&& xn) {
  41. return tag-dispatched;
  42. };
  43. #else
  44. template <typename S, typename = void>
  45. struct zip_shortest_impl : zip_shortest_impl<S, when<true>> { };
  46. struct zip_shortest_t {
  47. template <typename Xs, typename ...Ys>
  48. constexpr auto operator()(Xs&& xs, Ys&& ...ys) const;
  49. };
  50. constexpr zip_shortest_t zip_shortest{};
  51. #endif
  52. BOOST_HANA_NAMESPACE_END
  53. #endif // !BOOST_HANA_FWD_ZIP_SHORTEST_HPP