zip_with.hpp 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /*!
  2. @file
  3. Forward declares `boost::hana::zip_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_WITH_HPP
  9. #define BOOST_HANA_FWD_ZIP_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_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_with` produces a sequence
  20. //! 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 sequences, which are all assumed to
  30. //! have the same length. Assuming the sequences to all have the same size
  31. //! allows the library to perform some optimizations. To zip sequences
  32. //! that may have different lengths, `zip_shortest_with` should be used
  33. //! instead. Also note that it is an error to provide no sequence at all,
  34. //! i.e. `zip_with` expects at least one sequence.
  35. //!
  36. //!
  37. //! Example
  38. //! -------
  39. //! @include example/zip_with.cpp
  40. #ifdef BOOST_HANA_DOXYGEN_INVOKED
  41. constexpr auto zip_with = [](auto&& f, auto&& x1, ..., auto&& xn) {
  42. return tag-dispatched;
  43. };
  44. #else
  45. template <typename S, typename = void>
  46. struct zip_with_impl : zip_with_impl<S, when<true>> { };
  47. struct zip_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_with_t zip_with{};
  52. #endif
  53. BOOST_HANA_NAMESPACE_END
  54. #endif // !BOOST_HANA_FWD_ZIP_WITH_HPP