3 Forward declares `boost::hana::prepend`.
5 @copyright Louis Dionne 2013-2016
6 Distributed under the Boost Software License, Version 1.0.
7 (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
10 #ifndef BOOST_HANA_FWD_PREPEND_HPP
11 #define BOOST_HANA_FWD_PREPEND_HPP
13 #include <boost/hana/config.hpp>
14 #include <boost/hana/core/when.hpp>
17 BOOST_HANA_NAMESPACE_BEGIN
18 //! Prepend an element to a monadic structure.
19 //! @ingroup group-MonadPlus
21 //! Given a monadic structure `xs` and an element `x`, `prepend` returns
22 //! a new monadic structure which is the result of lifting `x` into the
23 //! monadic structure and then combining that (to the left) with `xs`.
26 //! prepend(xs, x) == concat(lift<Xs>(x), xs)
29 //! For sequences, this has the intuitive behavior of simply prepending
30 //! an element to the beginning of the sequence, hence the name.
32 //! > #### Rationale for not calling this `push_front`
33 //! > While `push_front` is the de-facto name used in the standard library,
34 //! > it also strongly suggests mutation of the underlying sequence, which
35 //! > is not the case here. The author also finds that `push_front`
36 //! > suggests too strongly the sole interpretation of putting an
37 //! > element to the front of a sequence, whereas `prepend` is slightly
38 //! > more nuanced and bears its name better for e.g. `hana::optional`.
43 //! Given a MonadPlus `M`, the signature is
44 //! @f$ \mathtt{prepend} : M(T) \times T \to M(T) @f$.
47 //! A monadic structure that will be combined to the right of the element.
50 //! An element to combine to the left of the monadic structure.
55 //! @include example/prepend.cpp
56 #ifdef BOOST_HANA_DOXYGEN_INVOKED
57 constexpr auto prepend = [](auto&& xs, auto&& x) {
58 return tag-dispatched;
61 template <typename M, typename = void>
62 struct prepend_impl : prepend_impl<M, when<true>> { };
65 template <typename Xs, typename X>
66 constexpr auto operator()(Xs&& xs, X&& x) const;
69 constexpr prepend_t prepend{};
71 BOOST_HANA_NAMESPACE_END
73 #endif // !BOOST_HANA_FWD_PREPEND_HPP