intersperse.hpp 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /*!
  2. @file
  3. Forward declares `boost::hana::intersperse`.
  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_INTERSPERSE_HPP
  9. #define BOOST_HANA_FWD_INTERSPERSE_HPP
  10. #include <boost/hana/config.hpp>
  11. #include <boost/hana/core/when.hpp>
  12. BOOST_HANA_NAMESPACE_BEGIN
  13. //! Insert a value between each pair of elements in a finite sequence.
  14. //! @ingroup group-Sequence
  15. //!
  16. //! Given a finite `Sequence` `xs` with a linearization of
  17. //! `[x1, x2, ..., xn]`, `intersperse(xs, z)` is a new sequence with a
  18. //! linearization of `[x1, z, x2, z, x3, ..., xn-1, z, xn]`. In other
  19. //! words, it inserts the `z` element between every pair of elements of
  20. //! the original sequence. If the sequence is empty or has a single
  21. //! element, `intersperse` returns the sequence as-is. In all cases,
  22. //! the sequence must be finite.
  23. //!
  24. //!
  25. //! @param xs
  26. //! The sequence in which a value is interspersed.
  27. //!
  28. //! @param z
  29. //! The value to be inserted between every pair of elements of the sequence.
  30. //!
  31. //!
  32. //! Example
  33. //! -------
  34. //! @include example/intersperse.cpp
  35. #ifdef BOOST_HANA_DOXYGEN_INVOKED
  36. constexpr auto intersperse = [](auto&& xs, auto&& z) {
  37. return tag-dispatched;
  38. };
  39. #else
  40. template <typename S, typename = void>
  41. struct intersperse_impl : intersperse_impl<S, when<true>> { };
  42. struct intersperse_t {
  43. template <typename Xs, typename Z>
  44. constexpr auto operator()(Xs&& xs, Z&& z) const;
  45. };
  46. constexpr intersperse_t intersperse{};
  47. #endif
  48. BOOST_HANA_NAMESPACE_END
  49. #endif // !BOOST_HANA_FWD_INTERSPERSE_HPP