1 /*! 2 @file 3 Forward declares `boost::hana::replicate`. 4 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) 8 */ 9 10 #ifndef BOOST_HANA_FWD_REPLICATE_HPP 11 #define BOOST_HANA_FWD_REPLICATE_HPP 12 13 #include <boost/hana/config.hpp> 14 #include <boost/hana/core/when.hpp> 15 16 17 BOOST_HANA_NAMESPACE_BEGIN 18 //! Create a monadic structure by combining a lifted value with itself 19 //! `n` times. 20 //! @ingroup group-MonadPlus 21 //! 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: 27 //! @code 28 //! replicate<M>(x, n) == cycle(lift<M>(x), n) 29 //! @endcode 30 //! 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`. 34 //! 35 //! 36 //! Signature 37 //! --------- 38 //! Given an `IntegralConstant` `C` and MonadPlus `M`, the signature is 39 //! @f$ \mathtt{replicate}_M : T \times C \to M(T) @f$. 40 //! 41 //! @tparam M 42 //! The tag of the returned monadic structure. It must be a 43 //! model of the MonadPlus concept. 44 //! 45 //! @param x 46 //! The value to lift into a monadic structure and then combine with 47 //! itself. 48 //! 49 //! @param n 50 //! A non-negative `IntegralConstant` representing the number of times to 51 //! combine `lift<M>(x)` with itself. If `n == 0`, `replicate` returns 52 //! `empty<M>()`. 53 //! 54 //! 55 //! Example 56 //! ------- 57 //! @include example/replicate.cpp 58 #ifdef BOOST_HANA_DOXYGEN_INVOKED 59 template <typename M> __anonabbc4f740102(auto&& x, auto const& n) 60 constexpr auto replicate = [](auto&& x, auto const& n) { 61 return tag-dispatched; 62 }; 63 #else 64 template <typename M, typename = void> 65 struct replicate_impl : replicate_impl<M, when<true>> { }; 66 67 template <typename M> 68 struct replicate_t { 69 template <typename X, typename N> 70 constexpr auto operator()(X&& x, N const& n) const; 71 }; 72 73 template <typename M> 74 constexpr replicate_t<M> replicate{}; 75 #endif 76 BOOST_HANA_NAMESPACE_END 77 78 #endif // !BOOST_HANA_FWD_REPLICATE_HPP 79