zip.hpp 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /*!
  2. @file
  3. Forward declares `boost::hana::zip`.
  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_HPP
  9. #define BOOST_HANA_FWD_ZIP_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` produces a sequence whose
  17. //! `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` 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 sequences, which are all assumed to
  29. //! have the same length. Assuming the sequences to all have the same size
  30. //! allows the library to perform some optimizations. To zip sequences
  31. //! that may have different lengths, `zip_shortest` should be used
  32. //! instead. Also note that it is an error to provide no sequence at all,
  33. //! i.e. `zip` expects at least one sequence.
  34. //!
  35. //!
  36. //! Example
  37. //! -------
  38. //! @include example/zip.cpp
  39. #ifdef BOOST_HANA_DOXYGEN_INVOKED
  40. constexpr auto zip = [](auto&& x1, ..., auto&& xn) {
  41. return tag-dispatched;
  42. };
  43. #else
  44. template <typename S, typename = void>
  45. struct zip_impl : zip_impl<S, when<true>> { };
  46. struct zip_t {
  47. template <typename Xs, typename ...Ys>
  48. constexpr auto operator()(Xs&& xs, Ys&& ...ys) const;
  49. };
  50. constexpr zip_t zip{};
  51. #endif
  52. BOOST_HANA_NAMESPACE_END
  53. #endif // !BOOST_HANA_FWD_ZIP_HPP