]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/hana/include/boost/hana/fwd/fold_right.hpp
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / boost / libs / hana / include / boost / hana / fwd / fold_right.hpp
1 /*!
2 @file
3 Forward declares `boost::hana::fold_right`.
4
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)
8 */
9
10 #ifndef BOOST_HANA_FWD_FOLD_RIGHT_HPP
11 #define BOOST_HANA_FWD_FOLD_RIGHT_HPP
12
13 #include <boost/hana/config.hpp>
14 #include <boost/hana/core/when.hpp>
15
16
17 BOOST_HANA_NAMESPACE_BEGIN
18 //! Right-fold of a structure using a binary operation and an optional
19 //! initial reduction state.
20 //! @ingroup group-Foldable
21 //!
22 //! `fold_right` is a right-associative fold using a binary operation.
23 //! Given a structure containing `x1, ..., xn`, a function `f` and
24 //! an optional initial state, `fold_right` applies `f` as follows
25 //! @code
26 //! f(x1, f(x2, f(x3, f(x4, ... f(xn-1, xn) ... )))) // without state
27 //! f(x1, f(x2, f(x3, f(x4, ... f(xn, state) ... )))) // with state
28 //! @endcode
29 //!
30 //! @note
31 //! It is worth noting that the order in which the binary function should
32 //! expect its arguments is reversed from `fold_left`.
33 //!
34 //! When the structure is empty, two things may arise. If an initial
35 //! state was provided, it is returned as-is. Otherwise, if the no-state
36 //! version of the function was used, an error is triggered. When the
37 //! stucture contains a single element and the no-state version of the
38 //! function was used, that single element is returned as is.
39 //!
40 //!
41 //! Signature
42 //! ---------
43 //! Given a `Foldable` `F` and an optional initial state of tag `S`,
44 //! the signatures for `fold_right` are
45 //! \f[
46 //! \mathtt{fold\_right} : F(T) \times S \times (T \times S \to S) \to S
47 //! \f]
48 //!
49 //! for the variant with an initial state, and
50 //! \f[
51 //! \mathtt{fold\_right} : F(T) \times (T \times T \to T) \to T
52 //! \f]
53 //!
54 //! for the variant without an initial state.
55 //!
56 //! @param xs
57 //! The structure to fold.
58 //!
59 //! @param state
60 //! The initial value used for folding.
61 //!
62 //! @param f
63 //! A binary function called as `f(x, state)`, where `state` is the
64 //! result accumulated so far and `x` is an element in the structure.
65 //! For right folds without an initial state, the function is called as
66 //! `f(x1, x2)`, where `x1` and `x2` are elements of the structure.
67 //!
68 //!
69 //! Example
70 //! -------
71 //! @include example/fold_right.cpp
72 #ifdef BOOST_HANA_DOXYGEN_INVOKED
73 constexpr auto fold_right = [](auto&& xs[, auto&& state], auto&& f) -> decltype(auto) {
74 return tag-dispatched;
75 };
76 #else
77 template <typename T, typename = void>
78 struct fold_right_impl : fold_right_impl<T, when<true>> { };
79
80 struct fold_right_t {
81 template <typename Xs, typename State, typename F>
82 constexpr decltype(auto) operator()(Xs&& xs, State&& state, F&& f) const;
83
84 template <typename Xs, typename F>
85 constexpr decltype(auto) operator()(Xs&& xs, F&& f) const;
86 };
87
88 constexpr fold_right_t fold_right{};
89 #endif
90 BOOST_HANA_NAMESPACE_END
91
92 #endif // !BOOST_HANA_FWD_FOLD_RIGHT_HPP