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