3 Forward declares `boost::hana::replicate`.
5 @copyright Louis Dionne 2013-2017
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)
10 #ifndef BOOST_HANA_FWD_REPLICATE_HPP
11 #define BOOST_HANA_FWD_REPLICATE_HPP
13 #include <boost/hana/config.hpp>
14 #include <boost/hana/core/when.hpp>
17 BOOST_HANA_NAMESPACE_BEGIN
18 //! Create a monadic structure by combining a lifted value with itself
20 //! @ingroup group-MonadPlus
22 //! Given a value `x`, a non-negative `IntegralConstant` `n` and the tag
23 //! of a monadic structure `M`, `replicate` creates a new monadic structure
24 //! which is the result of combining `x` with itself `n` times inside the
25 //! monadic structure. In other words, `replicate` simply `lift`s `x` into
26 //! the monadic structure, and then combines that with itself `n` times:
28 //! replicate<M>(x, n) == cycle(lift<M>(x), n)
31 //! If `n` is zero, then the identity of the `concat` operation is returned.
32 //! In the case of sequences, this corresponds to creating a new sequence
33 //! holding `n` copies of `x`.
38 //! Given an `IntegralConstant` `C` and MonadPlus `M`, the signature is
39 //! @f$ \mathtt{replicate}_M : T \times C \to M(T) @f$.
42 //! The tag of the returned monadic structure. It must be a
43 //! model of the MonadPlus concept.
46 //! The value to lift into a monadic structure and then combine with
50 //! A non-negative `IntegralConstant` representing the number of times to
51 //! combine `lift<M>(x)` with itself. If `n == 0`, `replicate` returns
57 //! @include example/replicate.cpp
58 #ifdef BOOST_HANA_DOXYGEN_INVOKED
60 constexpr auto replicate = [](auto&& x, auto const& n) {
61 return tag-dispatched;
64 template <typename M, typename = void>
65 struct replicate_impl : replicate_impl<M, when<true>> { };
71 constexpr replicate_t<M> replicate{};
73 BOOST_HANA_NAMESPACE_END
75 #endif // !BOOST_HANA_FWD_REPLICATE_HPP