Back to home page

EIC code displayed by LXR

 
 

    


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

0001 /*!
0002 @file
0003 Forward declares `boost::hana::prepend`.
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_PREPEND_HPP
0011 #define BOOST_HANA_FWD_PREPEND_HPP
0012 
0013 #include <boost/hana/config.hpp>
0014 #include <boost/hana/core/when.hpp>
0015 
0016 
0017 namespace boost { namespace hana {
0018     //! Prepend an element to a monadic structure.
0019     //! @ingroup group-MonadPlus
0020     //!
0021     //! Given a monadic structure `xs` and an element `x`, `prepend` returns
0022     //! a new monadic structure which is the result of lifting `x` into the
0023     //! monadic structure and then combining that (to the left) with `xs`.
0024     //! In other words,
0025     //! @code
0026     //!     prepend(xs, x) == concat(lift<Xs>(x), xs)
0027     //! @endcode
0028     //!
0029     //! For sequences, this has the intuitive behavior of simply prepending
0030     //! an element to the beginning of the sequence, hence the name.
0031     //!
0032     //! > #### Rationale for not calling this `push_front`
0033     //! > While `push_front` is the de-facto name used in the standard library,
0034     //! > it also strongly suggests mutation of the underlying sequence, which
0035     //! > is not the case here. The author also finds that `push_front`
0036     //! > suggests too strongly the sole interpretation of putting an
0037     //! > element to the front of a sequence, whereas `prepend` is slightly
0038     //! > more nuanced and bears its name better for e.g. `hana::optional`.
0039     //!
0040     //!
0041     //! Signature
0042     //! ---------
0043     //! Given a MonadPlus `M`, the signature is
0044     //! @f$ \mathtt{prepend} : M(T) \times T \to M(T) @f$.
0045     //!
0046     //! @param xs
0047     //! A monadic structure that will be combined to the right of the element.
0048     //!
0049     //! @param x
0050     //! An element to combine to the left of the monadic structure.
0051     //!
0052     //!
0053     //! Example
0054     //! -------
0055     //! @include example/prepend.cpp
0056 #ifdef BOOST_HANA_DOXYGEN_INVOKED
0057     constexpr auto prepend = [](auto&& xs, auto&& x) {
0058         return tag-dispatched;
0059     };
0060 #else
0061     template <typename M, typename = void>
0062     struct prepend_impl : prepend_impl<M, when<true>> { };
0063 
0064     struct prepend_t {
0065         template <typename Xs, typename X>
0066         constexpr auto operator()(Xs&& xs, X&& x) const;
0067     };
0068 
0069     BOOST_HANA_INLINE_VARIABLE constexpr prepend_t prepend{};
0070 #endif
0071 }} // end namespace boost::hana
0072 
0073 #endif // !BOOST_HANA_FWD_PREPEND_HPP