|
|
|||
File indexing completed on 2025-12-15 09:53:05
0001 /*! 0002 @file 0003 Forward declares `boost::hana::replicate`. 0004 0005 Copyright Louis Dionne 2013-2022 0006 Distributed under the Boost Software License, Version 1.0. 0007 (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) 0008 */ 0009 0010 #ifndef BOOST_HANA_FWD_REPLICATE_HPP 0011 #define BOOST_HANA_FWD_REPLICATE_HPP 0012 0013 #include <boost/hana/config.hpp> 0014 #include <boost/hana/core/when.hpp> 0015 0016 0017 namespace boost { namespace hana { 0018 //! Create a monadic structure by combining a lifted value with itself 0019 //! `n` times. 0020 //! @ingroup group-MonadPlus 0021 //! 0022 //! Given a value `x`, a non-negative `IntegralConstant` `n` and the tag 0023 //! of a monadic structure `M`, `replicate` creates a new monadic structure 0024 //! which is the result of combining `x` with itself `n` times inside the 0025 //! monadic structure. In other words, `replicate` simply `lift`s `x` into 0026 //! the monadic structure, and then combines that with itself `n` times: 0027 //! @code 0028 //! replicate<M>(x, n) == cycle(lift<M>(x), n) 0029 //! @endcode 0030 //! 0031 //! If `n` is zero, then the identity of the `concat` operation is returned. 0032 //! In the case of sequences, this corresponds to creating a new sequence 0033 //! holding `n` copies of `x`. 0034 //! 0035 //! 0036 //! Signature 0037 //! --------- 0038 //! Given an `IntegralConstant` `C` and MonadPlus `M`, the signature is 0039 //! @f$ \mathtt{replicate}_M : T \times C \to M(T) @f$. 0040 //! 0041 //! @tparam M 0042 //! The tag of the returned monadic structure. It must be a 0043 //! model of the MonadPlus concept. 0044 //! 0045 //! @param x 0046 //! The value to lift into a monadic structure and then combine with 0047 //! itself. 0048 //! 0049 //! @param n 0050 //! A non-negative `IntegralConstant` representing the number of times to 0051 //! combine `lift<M>(x)` with itself. If `n == 0`, `replicate` returns 0052 //! `empty<M>()`. 0053 //! 0054 //! 0055 //! Example 0056 //! ------- 0057 //! @include example/replicate.cpp 0058 #ifdef BOOST_HANA_DOXYGEN_INVOKED 0059 template <typename M> 0060 constexpr auto replicate = [](auto&& x, auto const& n) { 0061 return tag-dispatched; 0062 }; 0063 #else 0064 template <typename M, typename = void> 0065 struct replicate_impl : replicate_impl<M, when<true>> { }; 0066 0067 template <typename M> 0068 struct replicate_t { 0069 template <typename X, typename N> 0070 constexpr auto operator()(X&& x, N const& n) const; 0071 }; 0072 0073 template <typename M> 0074 BOOST_HANA_INLINE_VARIABLE constexpr replicate_t<M> replicate{}; 0075 #endif 0076 }} // end namespace boost::hana 0077 0078 #endif // !BOOST_HANA_FWD_REPLICATE_HPP
| [ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
|
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
|