Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-12-15 09:53:05

0001 /*!
0002 @file
0003 Forward declares `boost::hana::suffix`.
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_SUFFIX_HPP
0011 #define BOOST_HANA_FWD_SUFFIX_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 after each element of a monadic structure.
0019     //! @ingroup group-MonadPlus
0020     //!
0021     //! Given a monadic structure `xs` and a value `z` (called the suffix),
0022     //! `suffix` returns a new monadic structure such that
0023     //! @code
0024     //!     suffix(xs, z) == flatten(transform(xs, [](auto x) {
0025     //!         return concat(lift<M>(x), lift<M>(z));
0026     //!     }))
0027     //! @endcode
0028     //!
0029     //! For sequences, this simply corresponds to inserting the suffix after
0030     //! each element of the sequence. For example, given a sequence
0031     //! `[x1, ..., xn]`, `suffix` will return
0032     //! @code
0033     //!     [x1, z, x2, z, ..., xn, z]
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$ \mathtt{suffix} : M(T) \times T \to M(T) @f$.
0043     //!
0044     //! @param xs
0045     //! A monadic structure.
0046     //!
0047     //! @param sfx
0048     //! A value (the suffix) to insert after each element of a monadic
0049     //! structure.
0050     //!
0051     //!
0052     //! Example
0053     //! -------
0054     //! @include example/suffix.cpp
0055 #ifdef BOOST_HANA_DOXYGEN_INVOKED
0056     constexpr auto suffix = [](auto&& xs, auto&& sfx) {
0057         return tag-dispatched;
0058     };
0059 #else
0060     template <typename M, typename = void>
0061     struct suffix_impl : suffix_impl<M, when<true>> { };
0062 
0063     struct suffix_t {
0064         template <typename Xs, typename Sfx>
0065         constexpr auto operator()(Xs&& xs, Sfx&& sfx) const;
0066     };
0067 
0068     BOOST_HANA_INLINE_VARIABLE constexpr suffix_t suffix{};
0069 #endif
0070 }} // end namespace boost::hana
0071 
0072 #endif // !BOOST_HANA_FWD_SUFFIX_HPP