zip_shortest_with.hpp 2.1 KB

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