3 Forward declares `boost::hana::reverse_fold`.
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)
10 #ifndef BOOST_HANA_FWD_REVERSE_FOLD_HPP
11 #define BOOST_HANA_FWD_REVERSE_FOLD_HPP
13 #include <boost/hana/config.hpp>
16 namespace boost { namespace hana {
17 //! Equivalent to `reverse_fold` in Boost.Fusion and Boost.MPL.
18 //! @ingroup group-Foldable
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,
26 //! reverse_fold(sequence, state, f) == fold_right(sequence, state, flip(f))
27 //! reverse_fold(sequence, f) == fold_right(sequence, flip(f))
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.
38 //! Given a `Foldable` `F` and an optional initial state of tag `S`,
39 //! the signatures for `reverse_fold` are
41 //! \mathtt{reverse\_fold} : F(T) \times S \times (S \times T \to S) \to S
44 //! for the variant with an initial state, and
46 //! \mathtt{reverse\_fold} : F(T) \times (T \times T \to T) \to T
49 //! for the variant without an initial state.
52 //! The structure to fold.
55 //! The initial value used for folding.
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.
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)));
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;
76 template <typename Xs, typename F>
77 constexpr decltype(auto) operator()(Xs&& xs, F&& f) const;
80 BOOST_HANA_INLINE_VARIABLE constexpr reverse_fold_t reverse_fold{};
82 }} // end namespace boost::hana
84 #endif // !BOOST_HANA_FWD_REVERSE_FOLD_HPP