]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/boost/hana/fwd/reverse_fold.hpp
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / boost / boost / hana / fwd / reverse_fold.hpp
1 /*!
2 @file
3 Forward declares `boost::hana::reverse_fold`.
4
5 @copyright Louis Dionne 2013-2017
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)
8 */
9
10 #ifndef BOOST_HANA_FWD_REVERSE_FOLD_HPP
11 #define BOOST_HANA_FWD_REVERSE_FOLD_HPP
12
13 #include <boost/hana/config.hpp>
14
15
16 namespace boost { namespace hana {
17 //! Equivalent to `reverse_fold` in Boost.Fusion and Boost.MPL.
18 //! @ingroup group-Foldable
19 //!
20 //! This method has the same semantics as `reverse_fold` in Boost.Fusion
21 //! and Boost.MPL, with the extension that an initial state is not
22 //! required. This method is equivalent to `fold_right`, except that
23 //! the accumulating function must take its arguments in reverse order,
24 //! to match the order used in Fusion. In other words,
25 //! @code
26 //! reverse_fold(sequence, state, f) == fold_right(sequence, state, flip(f))
27 //! reverse_fold(sequence, f) == fold_right(sequence, flip(f))
28 //! @endcode
29 //!
30 //! @note
31 //! This method is a convenience alias to `fold_right`. As an alias,
32 //! `reverse_fold` is not tag-dispatched on its own and `fold_right`
33 //! should be customized instead.
34 //!
35 //!
36 //! Signature
37 //! ---------
38 //! Given a `Foldable` `F` and an optional initial state of tag `S`,
39 //! the signatures for `reverse_fold` are
40 //! \f[
41 //! \mathtt{reverse\_fold} : F(T) \times S \times (S \times T \to S) \to S
42 //! \f]
43 //!
44 //! for the variant with an initial state, and
45 //! \f[
46 //! \mathtt{reverse\_fold} : F(T) \times (T \times T \to T) \to T
47 //! \f]
48 //!
49 //! for the variant without an initial state.
50 //!
51 //! @param xs
52 //! The structure to fold.
53 //!
54 //! @param state
55 //! The initial value used for folding.
56 //!
57 //! @param f
58 //! A binary function called as `f(state, x)`, where `state` is the
59 //! result accumulated so far and `x` is an element in the structure.
60 //! For reverse folds without an initial state, the function is called as
61 //! `f(x1, x2)`, where `x1` and `x2` are elements of the structure.
62 //!
63 //!
64 //! Example
65 //! -------
66 //! @include example/reverse_fold.cpp
67 #ifdef BOOST_HANA_DOXYGEN_INVOKED
68 constexpr auto reverse_fold = [](auto&& xs[, auto&& state], auto&& f) -> decltype(auto) {
69 return fold_right(forwarded(xs), forwarded(state), flip(forwarded(f)));
70 };
71 #else
72 struct reverse_fold_t {
73 template <typename Xs, typename S, typename F>
74 constexpr decltype(auto) operator()(Xs&& xs, S&& s, F&& f) const;
75
76 template <typename Xs, typename F>
77 constexpr decltype(auto) operator()(Xs&& xs, F&& f) const;
78 };
79
80 BOOST_HANA_INLINE_VARIABLE constexpr reverse_fold_t reverse_fold{};
81 #endif
82 }} // end namespace boost::hana
83
84 #endif // !BOOST_HANA_FWD_REVERSE_FOLD_HPP