File indexing completed on 2025-01-18 09:31:09
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010 # if BOOST_WORKAROUND (BOOST_MSVC, < 1500)
0011 # define BOOST_FUSION_FOLD_IMPL_ENABLER(T) void
0012 # else
0013 # define BOOST_FUSION_FOLD_IMPL_ENABLER(T) typename T::type
0014 # endif
0015 namespace boost { namespace fusion
0016 {
0017 namespace detail
0018 {
0019 template<int SeqSize, typename It, typename State, typename F, typename = void
0020 # if BOOST_WORKAROUND (BOOST_MSVC, < 1500)
0021
0022 , bool = SeqSize == 0
0023 # endif
0024 >
0025 struct result_of_it_reverse_fold
0026 {};
0027 template<typename It, typename State, typename F>
0028 struct result_of_it_reverse_fold<0,It,State,F
0029 , typename boost::enable_if_has_type<BOOST_FUSION_FOLD_IMPL_ENABLER(State)>::type
0030 # if BOOST_WORKAROUND (BOOST_MSVC, < 1500)
0031 , true
0032 # endif
0033 >
0034 {
0035 typedef typename State::type type;
0036 };
0037 template<int SeqSize, typename It, typename State, typename F>
0038 struct result_of_it_reverse_fold<SeqSize,It,State,F
0039 , typename boost::enable_if_has_type<
0040 # if BOOST_WORKAROUND (BOOST_MSVC, >= 1500)
0041
0042
0043
0044 typename boost::disable_if_c<SeqSize == 0, State>::type::type
0045 # else
0046 BOOST_FUSION_FOLD_IMPL_ENABLER(State)
0047 # endif
0048 >::type
0049 # if BOOST_WORKAROUND (BOOST_MSVC, < 1500)
0050 , false
0051 # endif
0052 >
0053 : result_of_it_reverse_fold<
0054 SeqSize-1
0055 , typename result_of::prior<It>::type
0056 , boost::result_of<
0057 F(
0058 typename add_reference<typename State::type>::type,
0059 typename fusion::result_of::deref<It const>::type
0060 )
0061 >
0062 , F
0063 >
0064 {};
0065 template<typename It, typename State, typename F>
0066 BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
0067 inline typename result_of_it_reverse_fold<
0068 0
0069 , It
0070 , State
0071 , F
0072 >::type
0073 it_reverse_fold(mpl::int_<0>, It const&, typename State::type state, F&)
0074 {
0075 return state;
0076 }
0077 template<typename It, typename State, typename F, int SeqSize>
0078 BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
0079 inline typename lazy_enable_if_c<
0080 SeqSize != 0
0081 , result_of_it_reverse_fold<
0082 SeqSize
0083 , It
0084 , State
0085 , F
0086 >
0087 >::type
0088 it_reverse_fold(mpl::int_<SeqSize>, It const& it, typename State::type state, F& f)
0089 {
0090 return it_reverse_fold<
0091 typename result_of::prior<It>::type
0092 , boost::result_of<
0093 F(
0094 typename add_reference<typename State::type>::type,
0095 typename fusion::result_of::deref<It const>::type
0096 )
0097 >
0098 , F
0099 >(
0100 mpl::int_<SeqSize-1>()
0101 , fusion::prior(it)
0102 , f(state, fusion::deref(it))
0103 , f
0104 );
0105 }
0106 template<typename Seq, typename State, typename F
0107 , bool = traits::is_sequence<Seq>::value
0108 , bool = traits::is_segmented<Seq>::value>
0109 struct result_of_reverse_fold
0110 {};
0111 template<typename Seq, typename State, typename F>
0112 struct result_of_reverse_fold<Seq, State, F, true, false>
0113 : result_of_it_reverse_fold<
0114 result_of::size<Seq>::value
0115 , typename fusion::result_of::prior< typename result_of::end<Seq>::type >::type
0116 , add_reference<State>
0117 , F
0118 >
0119 {};
0120 template<typename Seq, typename State, typename F>
0121 BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
0122 inline typename result_of_reverse_fold<Seq, State, F>::type
0123 reverse_fold(Seq& seq, State& state, F& f)
0124 {
0125 return it_reverse_fold<
0126 typename fusion::result_of::prior< typename result_of::end<Seq>::type >::type
0127 , add_reference<State>
0128 , F
0129 >(
0130 typename result_of::size<Seq>::type()
0131 , fusion::prior( fusion::end(seq) )
0132 , state
0133 , f
0134 );
0135 }
0136 }
0137 namespace result_of
0138 {
0139 template<typename Seq, typename State, typename F>
0140 struct reverse_fold
0141 : detail::result_of_reverse_fold<Seq, State, F>
0142 {};
0143 }
0144 template<typename Seq, typename State, typename F>
0145 BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
0146 inline typename result_of::reverse_fold<
0147 Seq
0148 , State const
0149 , F
0150 >::type
0151 reverse_fold(Seq& seq, State const& state, F f)
0152 {
0153 return detail::reverse_fold<Seq, State const, F>(seq, state, f);
0154 }
0155 template<typename Seq, typename State, typename F>
0156 BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
0157 inline typename result_of::reverse_fold<
0158 Seq const
0159 , State const
0160 , F
0161 >::type
0162 reverse_fold(Seq const& seq, State const& state, F f)
0163 {
0164 return detail::reverse_fold<Seq const, State const, F>(seq, state, f);
0165 }
0166 template<typename Seq, typename State, typename F>
0167 BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
0168 inline typename result_of::reverse_fold<
0169 Seq
0170 , State
0171 , F
0172 >::type
0173 reverse_fold(Seq& seq, State& state, F f)
0174 {
0175 return detail::reverse_fold<Seq, State, F>(seq, state, f);
0176 }
0177 template<typename Seq, typename State, typename F>
0178 BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
0179 inline typename result_of::reverse_fold<
0180 Seq const
0181 , State
0182 , F
0183 >::type
0184 reverse_fold(Seq const& seq, State& state, F f)
0185 {
0186 return detail::reverse_fold<Seq const, State, F>(seq, state, f);
0187 }
0188 }}