]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | /*! |
2 | @file | |
3 | Forward declares `boost::hana::intersperse`. | |
4 | ||
5 | @copyright Louis Dionne 2013-2016 | |
6 | Distributed under the Boost Software License, Version 1.0. | |
7 | (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) | |
8 | */ | |
9 | ||
10 | #ifndef BOOST_HANA_FWD_INTERSPERSE_HPP | |
11 | #define BOOST_HANA_FWD_INTERSPERSE_HPP | |
12 | ||
13 | #include <boost/hana/config.hpp> | |
14 | #include <boost/hana/core/when.hpp> | |
15 | ||
16 | ||
17 | BOOST_HANA_NAMESPACE_BEGIN | |
18 | //! Insert a value between each pair of elements in a finite sequence. | |
19 | //! @ingroup group-Sequence | |
20 | //! | |
21 | //! Given a finite `Sequence` `xs` with a linearization of | |
22 | //! `[x1, x2, ..., xn]`, `intersperse(xs, z)` is a new sequence with a | |
23 | //! linearization of `[x1, z, x2, z, x3, ..., xn-1, z, xn]`. In other | |
24 | //! words, it inserts the `z` element between every pair of elements of | |
25 | //! the original sequence. If the sequence is empty or has a single | |
26 | //! element, `intersperse` returns the sequence as-is. In all cases, | |
27 | //! the sequence must be finite. | |
28 | //! | |
29 | //! | |
30 | //! @param xs | |
31 | //! The sequence in which a value is interspersed. | |
32 | //! | |
33 | //! @param z | |
34 | //! The value to be inserted between every pair of elements of the sequence. | |
35 | //! | |
36 | //! | |
37 | //! Example | |
38 | //! ------- | |
39 | //! @include example/intersperse.cpp | |
40 | #ifdef BOOST_HANA_DOXYGEN_INVOKED | |
41 | constexpr auto intersperse = [](auto&& xs, auto&& z) { | |
42 | return tag-dispatched; | |
43 | }; | |
44 | #else | |
45 | template <typename S, typename = void> | |
46 | struct intersperse_impl : intersperse_impl<S, when<true>> { }; | |
47 | ||
48 | struct intersperse_t { | |
49 | template <typename Xs, typename Z> | |
50 | constexpr auto operator()(Xs&& xs, Z&& z) const; | |
51 | }; | |
52 | ||
53 | constexpr intersperse_t intersperse{}; | |
54 | #endif | |
55 | BOOST_HANA_NAMESPACE_END | |
56 | ||
57 | #endif // !BOOST_HANA_FWD_INTERSPERSE_HPP |