]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/libs/hana/include/boost/hana/fwd/prefix.hpp
bump version to 12.2.2-pve1
[ceph.git] / ceph / src / boost / libs / hana / include / boost / hana / fwd / prefix.hpp
CommitLineData
7c673cae
FG
1/*!
2@file
3Forward declares `boost::hana::prefix`.
4
5@copyright Louis Dionne 2013-2016
6Distributed under the Boost Software License, Version 1.0.
7(See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
8 */
9
10#ifndef BOOST_HANA_FWD_PREFIX_HPP
11#define BOOST_HANA_FWD_PREFIX_HPP
12
13#include <boost/hana/config.hpp>
14#include <boost/hana/core/when.hpp>
15
16
17BOOST_HANA_NAMESPACE_BEGIN
18 //! Inserts a value before each element of a monadic structure.
19 //! @ingroup group-MonadPlus
20 //!
21 //! Given a monadic structure `xs` and a value `z` called the prefix,
22 //! `prefix` returns a new monadic structure. `prefix` satisfies
23 //! @code
24 //! prefix(xs, z) == flatten(transform(xs, [](auto x) {
25 //! return concat(lift<M>(z), lift<M>(x));
26 //! }))
27 //! @endcode
28 //!
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
32 //! @code
33 //! [z, x1, z, x2, ..., z, xn]
34 //! @endcode
35 //! As explained above, this can be generalized to other MonadPlus models,
36 //! with various levels of interest.
37 //!
38 //!
39 //! Signature
40 //! ---------
41 //! Given a MonadPlus `M`, the signature is
42 //! @f$ \mathrm{prefix} : M(T) \times T \to M(T) @f$.
43 //!
44 //! @param xs
45 //! A monadic structure.
46 //!
47 //! @param pref
48 //! A value (the prefix) to insert before each element of a monadic
49 //! structure.
50 //!
51 //!
52 //! Example
53 //! -------
54 //! @include example/prefix.cpp
55#ifdef BOOST_HANA_DOXYGEN_INVOKED
56 constexpr auto prefix = [](auto&& xs, auto&& pref) {
57 return tag-dispatched;
58 };
59#else
60 template <typename M, typename = void>
61 struct prefix_impl : prefix_impl<M, when<true>> { };
62
63 struct prefix_t {
64 template <typename Xs, typename Pref>
65 constexpr auto operator()(Xs&& xs, Pref&& pref) const;
66 };
67
68 constexpr prefix_t prefix{};
69#endif
70BOOST_HANA_NAMESPACE_END
71
72#endif // !BOOST_HANA_FWD_PREFIX_HPP