File indexing completed on 2025-01-18 09:38:17
0001
0002
0003
0004
0005
0006
0007
0008 #ifndef BOOST_HOF_GUARD_REVERSE_FOLD_H
0009 #define BOOST_HOF_GUARD_REVERSE_FOLD_H
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045
0046
0047
0048
0049
0050
0051
0052
0053
0054
0055
0056
0057
0058
0059
0060
0061
0062
0063
0064
0065
0066
0067
0068
0069
0070
0071
0072
0073
0074
0075
0076
0077
0078
0079
0080
0081
0082 #include <boost/hof/detail/callable_base.hpp>
0083 #include <boost/hof/detail/delegate.hpp>
0084 #include <boost/hof/detail/compressed_pair.hpp>
0085 #include <boost/hof/detail/move.hpp>
0086 #include <boost/hof/detail/make.hpp>
0087 #include <boost/hof/detail/static_const_var.hpp>
0088
0089 namespace boost { namespace hof { namespace detail {
0090
0091 struct v_reverse_fold
0092 {
0093 BOOST_HOF_RETURNS_CLASS(v_reverse_fold);
0094 template<class F, class State, class T, class... Ts>
0095 constexpr BOOST_HOF_SFINAE_MANUAL_RESULT(const F&, result_of<const v_reverse_fold&, id_<const F&>, id_<State>, id_<Ts>...>, id_<T>)
0096 operator()(const F& f, State&& state, T&& x, Ts&&... xs) const BOOST_HOF_SFINAE_MANUAL_RETURNS
0097 (
0098 f((*BOOST_HOF_CONST_THIS)(f, BOOST_HOF_FORWARD(State)(state), BOOST_HOF_FORWARD(Ts)(xs)...), BOOST_HOF_FORWARD(T)(x))
0099 );
0100
0101 template<class F, class State>
0102 constexpr State operator()(const F&, State&& state) const noexcept
0103 {
0104 return BOOST_HOF_FORWARD(State)(state);
0105 }
0106 };
0107
0108 }
0109
0110 template<class F, class State=void>
0111 struct reverse_fold_adaptor
0112 : detail::compressed_pair<detail::callable_base<F>, State>
0113 {
0114 typedef detail::compressed_pair<detail::callable_base<F>, State> base_type;
0115 BOOST_HOF_INHERIT_CONSTRUCTOR(reverse_fold_adaptor, base_type)
0116
0117 template<class... Ts>
0118 constexpr const detail::callable_base<F>& base_function(Ts&&... xs) const noexcept
0119 {
0120 return this->first(xs...);
0121 }
0122
0123 template<class... Ts>
0124 constexpr State get_state(Ts&&... xs) const noexcept
0125 {
0126 return this->second(xs...);
0127 }
0128
0129 BOOST_HOF_RETURNS_CLASS(reverse_fold_adaptor);
0130
0131 template<class... Ts>
0132 constexpr BOOST_HOF_SFINAE_RESULT(detail::v_reverse_fold, id_<const detail::callable_base<F>&>, id_<State>, id_<Ts>...)
0133 operator()(Ts&&... xs) const BOOST_HOF_SFINAE_RETURNS
0134 (
0135 detail::v_reverse_fold()(
0136 BOOST_HOF_MANGLE_CAST(const detail::callable_base<F>&)(BOOST_HOF_CONST_THIS->base_function(xs...)),
0137 BOOST_HOF_MANGLE_CAST(State)(BOOST_HOF_CONST_THIS->get_state(xs...)),
0138 BOOST_HOF_FORWARD(Ts)(xs)...
0139 )
0140 )
0141 };
0142
0143
0144 template<class F>
0145 struct reverse_fold_adaptor<F, void>
0146 : detail::callable_base<F>
0147 {
0148 BOOST_HOF_INHERIT_CONSTRUCTOR(reverse_fold_adaptor, detail::callable_base<F>)
0149
0150 template<class... Ts>
0151 constexpr const detail::callable_base<F>& base_function(Ts&&... xs) const noexcept
0152 {
0153 return boost::hof::always_ref(*this)(xs...);
0154 }
0155
0156 BOOST_HOF_RETURNS_CLASS(reverse_fold_adaptor);
0157
0158 template<class... Ts>
0159 constexpr BOOST_HOF_SFINAE_RESULT(detail::v_reverse_fold, id_<const detail::callable_base<F>&>, id_<Ts>...)
0160 operator()(Ts&&... xs) const BOOST_HOF_SFINAE_RETURNS
0161 (
0162 detail::v_reverse_fold()(
0163 BOOST_HOF_MANGLE_CAST(const detail::callable_base<F>&)(BOOST_HOF_CONST_THIS->base_function(xs...)),
0164 BOOST_HOF_FORWARD(Ts)(xs)...
0165 )
0166 )
0167 };
0168
0169 BOOST_HOF_DECLARE_STATIC_VAR(reverse_fold, detail::make<reverse_fold_adaptor>);
0170
0171 }}
0172
0173 #endif