|
|
|||
File indexing completed on 2025-12-15 09:53:05
0001 /*! 0002 @file 0003 Forward declares `boost::hana::reverse_fold`. 0004 0005 Copyright Louis Dionne 2013-2022 0006 Distributed under the Boost Software License, Version 1.0. 0007 (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) 0008 */ 0009 0010 #ifndef BOOST_HANA_FWD_REVERSE_FOLD_HPP 0011 #define BOOST_HANA_FWD_REVERSE_FOLD_HPP 0012 0013 #include <boost/hana/config.hpp> 0014 0015 0016 namespace boost { namespace hana { 0017 //! Equivalent to `reverse_fold` in Boost.Fusion and Boost.MPL. 0018 //! @ingroup group-Foldable 0019 //! 0020 //! This method has the same semantics as `reverse_fold` in Boost.Fusion 0021 //! and Boost.MPL, with the extension that an initial state is not 0022 //! required. This method is equivalent to `fold_right`, except that 0023 //! the accumulating function must take its arguments in reverse order, 0024 //! to match the order used in Fusion. In other words, 0025 //! @code 0026 //! reverse_fold(sequence, state, f) == fold_right(sequence, state, flip(f)) 0027 //! reverse_fold(sequence, f) == fold_right(sequence, flip(f)) 0028 //! @endcode 0029 //! 0030 //! @note 0031 //! This method is a convenience alias to `fold_right`. As an alias, 0032 //! `reverse_fold` is not tag-dispatched on its own and `fold_right` 0033 //! should be customized instead. 0034 //! 0035 //! 0036 //! Signature 0037 //! --------- 0038 //! Given a `Foldable` `F` and an optional initial state of tag `S`, 0039 //! the signatures for `reverse_fold` are 0040 //! \f[ 0041 //! \mathtt{reverse\_fold} : F(T) \times S \times (S \times T \to S) \to S 0042 //! \f] 0043 //! 0044 //! for the variant with an initial state, and 0045 //! \f[ 0046 //! \mathtt{reverse\_fold} : F(T) \times (T \times T \to T) \to T 0047 //! \f] 0048 //! 0049 //! for the variant without an initial state. 0050 //! 0051 //! @param xs 0052 //! The structure to fold. 0053 //! 0054 //! @param state 0055 //! The initial value used for folding. 0056 //! 0057 //! @param f 0058 //! A binary function called as `f(state, x)`, where `state` is the 0059 //! result accumulated so far and `x` is an element in the structure. 0060 //! For reverse folds without an initial state, the function is called as 0061 //! `f(x1, x2)`, where `x1` and `x2` are elements of the structure. 0062 //! 0063 //! 0064 //! Example 0065 //! ------- 0066 //! @include example/reverse_fold.cpp 0067 #ifdef BOOST_HANA_DOXYGEN_INVOKED 0068 constexpr auto reverse_fold = [](auto&& xs[, auto&& state], auto&& f) -> decltype(auto) { 0069 return fold_right(forwarded(xs), forwarded(state), flip(forwarded(f))); 0070 }; 0071 #else 0072 struct reverse_fold_t { 0073 template <typename Xs, typename S, typename F> 0074 constexpr decltype(auto) operator()(Xs&& xs, S&& s, F&& f) const; 0075 0076 template <typename Xs, typename F> 0077 constexpr decltype(auto) operator()(Xs&& xs, F&& f) const; 0078 }; 0079 0080 BOOST_HANA_INLINE_VARIABLE constexpr reverse_fold_t reverse_fold{}; 0081 #endif 0082 }} // end namespace boost::hana 0083 0084 #endif // !BOOST_HANA_FWD_REVERSE_FOLD_HPP
| [ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
|
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
|