3 Forward declares `boost::hana::prefix`.
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_PREFIX_HPP
11 #define BOOST_HANA_FWD_PREFIX_HPP
13 #include <boost/hana/config.hpp>
14 #include <boost/hana/core/when.hpp>
17 BOOST_HANA_NAMESPACE_BEGIN
18 //! Inserts a value before each element of a monadic structure.
19 //! @ingroup group-MonadPlus
21 //! Given a monadic structure `xs` and a value `z` called the prefix,
22 //! `prefix` returns a new monadic structure. `prefix` satisfies
24 //! prefix(xs, z) == flatten(transform(xs, [](auto x) {
25 //! return concat(lift<M>(z), lift<M>(x));
29 //! For sequences, this simply corresponds to inserting the prefix before
30 //! each element of the sequence. For example, given a sequence
31 //! `[x1, ..., xn]`, `prefix` will return
33 //! [z, x1, z, x2, ..., z, xn]
35 //! As explained above, this can be generalized to other MonadPlus models,
36 //! with various levels of interest.
41 //! Given a MonadPlus `M`, the signature is
42 //! @f$ \mathrm{prefix} : M(T) \times T \to M(T) @f$.
45 //! A monadic structure.
48 //! A value (the prefix) to insert before each element of a monadic
54 //! @include example/prefix.cpp
55 #ifdef BOOST_HANA_DOXYGEN_INVOKED
56 constexpr auto prefix = [](auto&& xs, auto&& pref) {
57 return tag-dispatched;
60 template <typename M, typename = void>
61 struct prefix_impl : prefix_impl<M, when<true>> { };
64 template <typename Xs, typename Pref>
65 constexpr auto operator()(Xs&& xs, Pref&& pref) const;
68 constexpr prefix_t prefix{};
70 BOOST_HANA_NAMESPACE_END
72 #endif // !BOOST_HANA_FWD_PREFIX_HPP