|
|
|||
File indexing completed on 2025-12-16 09:52:53
0001 /*! 0002 @file 0003 Forward declares `boost::hana::cycle`. 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_CYCLE_HPP 0011 #define BOOST_HANA_FWD_CYCLE_HPP 0012 0013 #include <boost/hana/config.hpp> 0014 #include <boost/hana/core/when.hpp> 0015 0016 0017 namespace boost { namespace hana { 0018 //! Combine a monadic structure with itself `n` times. 0019 //! @ingroup group-MonadPlus 0020 //! 0021 //! Given a monadic structure `xs` and a non-negative number `n`, 0022 //! `cycle` returns a new monadic structure which is the result of 0023 //! combining `xs` with itself `n` times using the `concat` operation. 0024 //! In other words, 0025 //! @code 0026 //! cycle(xs, n) == concat(xs, concat(xs, ... concat(xs, xs))) 0027 //! // ^^^^^ n times total 0028 //! @endcode 0029 //! 0030 //! Also note that since `concat` is required to be associative, we 0031 //! could also have written 0032 //! @code 0033 //! cycle(xs, n) == concat(concat(... concat(xs, xs), xs), xs) 0034 //! // ^^^^^ n times total 0035 //! @endcode 0036 //! 0037 //! If `n` is zero, then the identity of `concat`, `empty`, is returned. 0038 //! In the case of sequences, this boils down to returning a sequence 0039 //! containing `n` copies of itself; for other models it might differ. 0040 //! 0041 //! 0042 //! Signature 0043 //! --------- 0044 //! Given an `IntegralConstant` `C` and a `MonadPlus` `M`, the signature is 0045 //! @f$ \mathrm{cycle} : M(T) \times C \to M(T) @f$. 0046 //! 0047 //! @param xs 0048 //! A monadic structure to combine with itself a certain number of times. 0049 //! 0050 //! @param n 0051 //! A non-negative `IntegralConstant` representing the number of times to 0052 //! combine the monadic structure with itself. If `n` is zero, `cycle` 0053 //! returns `empty`. 0054 //! 0055 //! 0056 //! Example 0057 //! ------- 0058 //! @include example/cycle.cpp 0059 #ifdef BOOST_HANA_DOXYGEN_INVOKED 0060 constexpr auto cycle = [](auto&& xs, auto const& n) { 0061 return tag-dispatched; 0062 }; 0063 #else 0064 template <typename M, typename = void> 0065 struct cycle_impl : cycle_impl<M, when<true>> { }; 0066 0067 struct cycle_t { 0068 template <typename Xs, typename N> 0069 constexpr auto operator()(Xs&& xs, N const& n) const; 0070 }; 0071 0072 BOOST_HANA_INLINE_VARIABLE constexpr cycle_t cycle{}; 0073 #endif 0074 }} // end namespace boost::hana 0075 0076 #endif // !BOOST_HANA_FWD_CYCLE_HPP
| [ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
|
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
|