|
|
|||
File indexing completed on 2025-12-15 09:53:04
0001 /*! 0002 @file 0003 Forward declares `boost::hana::prefix`. 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_PREFIX_HPP 0011 #define BOOST_HANA_FWD_PREFIX_HPP 0012 0013 #include <boost/hana/config.hpp> 0014 #include <boost/hana/core/when.hpp> 0015 0016 0017 namespace boost { namespace hana { 0018 //! Inserts a value before each element of a monadic structure. 0019 //! @ingroup group-MonadPlus 0020 //! 0021 //! Given a monadic structure `xs` and a value `z` called the prefix, 0022 //! `prefix` returns a new monadic structure. `prefix` satisfies 0023 //! @code 0024 //! prefix(xs, z) == flatten(transform(xs, [](auto x) { 0025 //! return concat(lift<M>(z), lift<M>(x)); 0026 //! })) 0027 //! @endcode 0028 //! 0029 //! For sequences, this simply corresponds to inserting the prefix before 0030 //! each element of the sequence. For example, given a sequence 0031 //! `[x1, ..., xn]`, `prefix` will return 0032 //! @code 0033 //! [z, x1, z, x2, ..., z, xn] 0034 //! @endcode 0035 //! As explained above, this can be generalized to other MonadPlus models, 0036 //! with various levels of interest. 0037 //! 0038 //! 0039 //! Signature 0040 //! --------- 0041 //! Given a MonadPlus `M`, the signature is 0042 //! @f$ \mathrm{prefix} : M(T) \times T \to M(T) @f$. 0043 //! 0044 //! @param xs 0045 //! A monadic structure. 0046 //! 0047 //! @param pref 0048 //! A value (the prefix) to insert before each element of a monadic 0049 //! structure. 0050 //! 0051 //! 0052 //! Example 0053 //! ------- 0054 //! @include example/prefix.cpp 0055 #ifdef BOOST_HANA_DOXYGEN_INVOKED 0056 constexpr auto prefix = [](auto&& xs, auto&& pref) { 0057 return tag-dispatched; 0058 }; 0059 #else 0060 template <typename M, typename = void> 0061 struct prefix_impl : prefix_impl<M, when<true>> { }; 0062 0063 struct prefix_t { 0064 template <typename Xs, typename Pref> 0065 constexpr auto operator()(Xs&& xs, Pref&& pref) const; 0066 }; 0067 0068 BOOST_HANA_INLINE_VARIABLE constexpr prefix_t prefix{}; 0069 #endif 0070 }} // end namespace boost::hana 0071 0072 #endif // !BOOST_HANA_FWD_PREFIX_HPP
| [ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
|
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
|