diff --git a/include/boost/fusion/algorithm/iteration/accumulate.hpp b/include/boost/fusion/algorithm/iteration/accumulate.hpp index aa52a99b..b4d1e276 100644 --- a/include/boost/fusion/algorithm/iteration/accumulate.hpp +++ b/include/boost/fusion/algorithm/iteration/accumulate.hpp @@ -7,6 +7,7 @@ #if !defined(FUSION_ACCUMULATE_09172005_1032) #define FUSION_ACCUMULATE_09172005_1032 +#include #include namespace boost { namespace fusion diff --git a/include/boost/fusion/algorithm/iteration/accumulate_fwd.hpp b/include/boost/fusion/algorithm/iteration/accumulate_fwd.hpp new file mode 100644 index 00000000..9c0bd115 --- /dev/null +++ b/include/boost/fusion/algorithm/iteration/accumulate_fwd.hpp @@ -0,0 +1,28 @@ +/*============================================================================= + Copyright (c) 2011 Eric Niebler + + Distributed under the Boost Software License, Version 1.0. (See accompanying + file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +==============================================================================*/ +#if !defined(BOOST_FUSION_ACCUMULATE_FWD_HPP_INCLUDED) +#define BOOST_FUSION_ACCUMULATE_FWD_HPP_INCLUDED + +namespace boost { namespace fusion +{ + namespace result_of + { + template + struct accumulate; + } + + template + typename result_of::accumulate::type + accumulate(Sequence& seq, State const& state, F f); + + template + typename result_of::accumulate::type + accumulate(Sequence const& seq, State const& state, F f); +}} + +#endif + diff --git a/include/boost/fusion/algorithm/iteration/detail/fold.hpp b/include/boost/fusion/algorithm/iteration/detail/fold.hpp index cf92a354..7d8eb334 100644 --- a/include/boost/fusion/algorithm/iteration/detail/fold.hpp +++ b/include/boost/fusion/algorithm/iteration/detail/fold.hpp @@ -15,6 +15,7 @@ #include #include #include +#include #include #include #include @@ -347,53 +348,73 @@ namespace boost { namespace fusion type; }; - template + template struct BOOST_PP_CAT(BOOST_FUSION_FOLD_NAME,_impl) { typedef typename BOOST_PP_CAT( result_of_first_unrolled,BOOST_FUSION_FOLD_NAME)< StateRef - , BOOST_FUSION_FOLD_IMPL_FIRST_IT_META_TRANSFORM(It0) + , BOOST_FUSION_FOLD_IMPL_FIRST_IT_META_TRANSFORM( + typename result_of::BOOST_FUSION_FOLD_IMPL_FIRST_IT_FUNCTION::type + ) , F , SeqSize >::type type; static type - call(StateRef state, It0 const& it0, F f) + call(StateRef state, Seq& seq, F f) { - return BOOST_PP_CAT(unrolled_,BOOST_FUSION_FOLD_NAME)< - type - , SeqSize - >::call(state,BOOST_FUSION_FOLD_IMPL_FIRST_IT_TRANSFORM(it0),f); + typedef + BOOST_PP_CAT(unrolled_,BOOST_FUSION_FOLD_NAME)< + type + , SeqSize + > + unrolled_impl; + + return unrolled_impl::call( + state, + BOOST_FUSION_FOLD_IMPL_FIRST_IT_TRANSFORM( + fusion::BOOST_FUSION_FOLD_IMPL_FIRST_IT_FUNCTION(seq)), + f); } }; - template - struct BOOST_PP_CAT(BOOST_FUSION_FOLD_NAME,_impl)<0,StateRef,It0,F> + template + struct BOOST_PP_CAT(BOOST_FUSION_FOLD_NAME,_impl)<0,StateRef,Seq,F> { typedef StateRef type; static StateRef - call(StateRef state, It0 const&, F) + call(StateRef state, Seq&, F) { return static_cast(state); } }; + + template + struct BOOST_PP_CAT(result_of_, BOOST_FUSION_FOLD_NAME) + : BOOST_PP_CAT(BOOST_FUSION_FOLD_NAME,_impl)< + result_of::size::value + , typename add_reference< + typename add_const::type + >::type + , Seq + , F + > + {}; } namespace result_of { template struct BOOST_FUSION_FOLD_NAME - : detail::BOOST_PP_CAT(BOOST_FUSION_FOLD_NAME,_impl)< - size::value - , typename add_reference< - typename add_const::type - >::type - , typename BOOST_FUSION_FOLD_IMPL_FIRST_IT_FUNCTION::type + : detail::BOOST_PP_CAT(result_of_, BOOST_FUSION_FOLD_NAME)< + Seq + , State , F + , traits::is_segmented::type::value > {}; } @@ -408,7 +429,7 @@ namespace boost { namespace fusion { return result_of::BOOST_FUSION_FOLD_NAME::call( state, - fusion::BOOST_FUSION_FOLD_IMPL_FIRST_IT_FUNCTION(seq), + seq, f); } @@ -422,7 +443,7 @@ namespace boost { namespace fusion { return result_of::BOOST_FUSION_FOLD_NAME::call( state, - fusion::BOOST_FUSION_FOLD_IMPL_FIRST_IT_FUNCTION(seq), + seq, f); } @@ -436,7 +457,7 @@ namespace boost { namespace fusion { return result_of::BOOST_FUSION_FOLD_NAME::call( state, - fusion::BOOST_FUSION_FOLD_IMPL_FIRST_IT_FUNCTION(seq), + seq, f); } @@ -450,7 +471,7 @@ namespace boost { namespace fusion { return result_of::BOOST_FUSION_FOLD_NAME::call( state, - fusion::BOOST_FUSION_FOLD_IMPL_FIRST_IT_FUNCTION(seq), + seq, f); } }} diff --git a/include/boost/fusion/algorithm/iteration/ext_/fold_s.hpp b/include/boost/fusion/algorithm/iteration/detail/segmented_fold.hpp similarity index 58% rename from include/boost/fusion/algorithm/iteration/ext_/fold_s.hpp rename to include/boost/fusion/algorithm/iteration/detail/segmented_fold.hpp index ce0f7434..2371e189 100644 --- a/include/boost/fusion/algorithm/iteration/ext_/fold_s.hpp +++ b/include/boost/fusion/algorithm/iteration/detail/segmented_fold.hpp @@ -7,7 +7,7 @@ #if !defined(BOOST_FUSION_FOLD_S_HPP_INCLUDED) #define BOOST_FUSION_FOLD_S_HPP_INCLUDED -#include +#include #include namespace boost { namespace fusion { namespace detail @@ -33,35 +33,27 @@ namespace boost { namespace fusion { namespace detail } }; }; -}}} -namespace boost { namespace fusion -{ - namespace result_of + // The default implementation of this lives in detail/fold.hpp + template + struct result_of_fold; + + template + struct result_of_fold { - template - struct fold_s - : result_of::segmented_fold_until< + typedef + typename result_of::segmented_fold_until< Sequence, State, - detail::segmented_fold_fun - > - {}; - } + segmented_fold_fun + >::type + type; - template - typename result_of::fold_s::type - fold_s(Sequence& seq, State const& state, F const& f) - { - return fusion::segmented_fold_until(seq, state, detail::segmented_fold_fun(f)); - } - - template - typename result_of::fold_s::type - fold_s(Sequence const& seq, State const& state, F const& f) - { - return fusion::segmented_fold_until(seq, state, detail::segmented_fold_fun(f)); - } -}} + static type call(State& state, Sequence& seq, Fun fun) + { + return fusion::segmented_fold_until(seq, state, segmented_fold_fun(fun)); + } + }; +}}} #endif diff --git a/include/boost/fusion/algorithm/iteration/fold.hpp b/include/boost/fusion/algorithm/iteration/fold.hpp index 347fb4f1..4b9d7d46 100644 --- a/include/boost/fusion/algorithm/iteration/fold.hpp +++ b/include/boost/fusion/algorithm/iteration/fold.hpp @@ -10,6 +10,8 @@ #ifndef BOOST_FUSION_ALGORITHM_ITERATION_FOLD_HPP #define BOOST_FUSION_ALGORITHM_ITERATION_FOLD_HPP +#include #include +#include #endif diff --git a/include/boost/fusion/algorithm/iteration/fold_fwd.hpp b/include/boost/fusion/algorithm/iteration/fold_fwd.hpp new file mode 100644 index 00000000..edb43e01 --- /dev/null +++ b/include/boost/fusion/algorithm/iteration/fold_fwd.hpp @@ -0,0 +1,52 @@ +/*============================================================================= + Copyright (c) 2011 Eric Niebler + + Distributed under the Boost Software License, Version 1.0. (See accompanying + file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +==============================================================================*/ + +#ifndef BOOST_FUSION_ALGORITHM_ITERATION_FOLD_FWD_HPP +#define BOOST_FUSION_ALGORITHM_ITERATION_FOLD_FWD_HPP + +namespace boost { namespace fusion +{ + namespace result_of + { + template + struct fold; + } + + template + typename result_of::fold< + Seq + , State const + , F + >::type + fold(Seq& seq, State const& state, F f); + + template + typename result_of::fold< + Seq const + , State const + , F + >::type + fold(Seq const& seq, State const& state, F f); + + template + typename result_of::fold< + Seq + , State const + , F + >::type + fold(Seq& seq, State& state, F f); + + template + typename result_of::fold< + Seq const + , State const + , F + >::type + fold(Seq const& seq, State& state, F f); +}} + +#endif diff --git a/include/boost/fusion/algorithm/iteration/iter_fold.hpp b/include/boost/fusion/algorithm/iteration/iter_fold.hpp index 59cbfd8c..722d6ef8 100644 --- a/include/boost/fusion/algorithm/iteration/iter_fold.hpp +++ b/include/boost/fusion/algorithm/iteration/iter_fold.hpp @@ -10,6 +10,7 @@ #define BOOST_FUSION_ITER_FOLD +#include #include #undef BOOST_FUSION_ITER_FOLD diff --git a/include/boost/fusion/algorithm/iteration/iter_fold_fwd.hpp b/include/boost/fusion/algorithm/iteration/iter_fold_fwd.hpp new file mode 100644 index 00000000..96ff387d --- /dev/null +++ b/include/boost/fusion/algorithm/iteration/iter_fold_fwd.hpp @@ -0,0 +1,52 @@ +/*============================================================================= + Copyright (c) 2011 Eric Niebler + + Distributed under the Boost Software License, Version 1.0. (See accompanying + file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +==============================================================================*/ + +#ifndef BOOST_FUSION_ALGORITHM_ITERATION_ITER_FOLD_FWD_HPP +#define BOOST_FUSION_ALGORITHM_ITERATION_ITER_FOLD_FWD_HPP + +namespace boost { namespace fusion +{ + namespace result_of + { + template + struct iter_fold; + } + + template + typename result_of::iter_fold< + Seq + , State const + , F + >::type + iter_fold(Seq& seq, State const& state, F f); + + template + typename result_of::iter_fold< + Seq const + , State const + , F + >::type + iter_fold(Seq const& seq, State const& state, F f); + + template + typename result_of::iter_fold< + Seq + , State const + , F + >::type + iter_fold(Seq& seq, State& state, F f); + + template + typename result_of::iter_fold< + Seq const + , State const + , F + >::type + iter_fold(Seq const& seq, State& state, F f); +}} + +#endif diff --git a/include/boost/fusion/algorithm/iteration/reverse_fold.hpp b/include/boost/fusion/algorithm/iteration/reverse_fold.hpp index bb09db5d..2ee4fd96 100644 --- a/include/boost/fusion/algorithm/iteration/reverse_fold.hpp +++ b/include/boost/fusion/algorithm/iteration/reverse_fold.hpp @@ -10,6 +10,7 @@ #define BOOST_FUSION_REVERSE_FOLD +#include #include #undef BOOST_FUSION_REVERSE_FOLD diff --git a/include/boost/fusion/algorithm/iteration/reverse_fold_fwd.hpp b/include/boost/fusion/algorithm/iteration/reverse_fold_fwd.hpp new file mode 100644 index 00000000..40546b53 --- /dev/null +++ b/include/boost/fusion/algorithm/iteration/reverse_fold_fwd.hpp @@ -0,0 +1,52 @@ +/*============================================================================= + Copyright (c) 2011 Eric Niebler + + Distributed under the Boost Software License, Version 1.0. (See accompanying + file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +==============================================================================*/ + +#ifndef BOOST_FUSION_ALGORITHM_ITERATION_REVERSE_FOLD_FWD_HPP +#define BOOST_FUSION_ALGORITHM_ITERATION_REVERSE_FOLD_FWD_HPP + +namespace boost { namespace fusion +{ + namespace result_of + { + template + struct reverse_fold; + } + + template + typename result_of::reverse_fold< + Seq + , State const + , F + >::type + reverse_fold(Seq& seq, State const& state, F f); + + template + typename result_of::reverse_fold< + Seq const + , State const + , F + >::type + reverse_fold(Seq const& seq, State const& state, F f); + + template + typename result_of::reverse_fold< + Seq + , State const + , F + >::type + reverse_fold(Seq& seq, State& state, F f); + + template + typename result_of::reverse_fold< + Seq const + , State const + , F + >::type + reverse_fold(Seq const& seq, State& state, F f); +}} + +#endif diff --git a/include/boost/fusion/algorithm/iteration/reverse_iter_fold.hpp b/include/boost/fusion/algorithm/iteration/reverse_iter_fold.hpp index 80079f48..2931301f 100644 --- a/include/boost/fusion/algorithm/iteration/reverse_iter_fold.hpp +++ b/include/boost/fusion/algorithm/iteration/reverse_iter_fold.hpp @@ -11,6 +11,7 @@ #define BOOST_FUSION_REVERSE_FOLD #define BOOST_FUSION_ITER_FOLD +#include #include #undef BOOST_FUSION_REVERSE_FOLD diff --git a/include/boost/fusion/algorithm/iteration/reverse_iter_fold_fwd.hpp b/include/boost/fusion/algorithm/iteration/reverse_iter_fold_fwd.hpp new file mode 100644 index 00000000..a28b4eec --- /dev/null +++ b/include/boost/fusion/algorithm/iteration/reverse_iter_fold_fwd.hpp @@ -0,0 +1,52 @@ +/*============================================================================= + Copyright (c) 2011 Eric Niebler + + Distributed under the Boost Software License, Version 1.0. (See accompanying + file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +==============================================================================*/ + +#ifndef BOOST_FUSION_ALGORITHM_ITERATION_REVERSE_ITER_FOLD_FWD_HPP +#define BOOST_FUSION_ALGORITHM_ITERATION_REVERSE_ITER_FOLD_FWD_HPP + +namespace boost { namespace fusion +{ + namespace result_of + { + template + struct reverse_iter_fold; + } + + template + typename result_of::reverse_iter_fold< + Seq + , State const + , F + >::type + reverse_iter_fold(Seq& seq, State const& state, F f); + + template + typename result_of::reverse_iter_fold< + Seq const + , State const + , F + >::type + reverse_iter_fold(Seq const& seq, State const& state, F f); + + template + typename result_of::reverse_iter_fold< + Seq + , State const + , F + >::type + reverse_iter_fold(Seq& seq, State& state, F f); + + template + typename result_of::reverse_iter_fold< + Seq const + , State const + , F + >::type + reverse_iter_fold(Seq const& seq, State& state, F f); +}} + +#endif diff --git a/test/algorithm/segmented_fold.cpp b/test/algorithm/segmented_fold.cpp index 6375473e..d023cac8 100644 --- a/test/algorithm/segmented_fold.cpp +++ b/test/algorithm/segmented_fold.cpp @@ -9,7 +9,7 @@ #include #include #include -#include +#include #include #include "../sequence/tree.hpp" @@ -31,7 +31,7 @@ process_tree(Tree const &tree) using namespace boost; std::stringstream str; - fusion::fold_s(tree, &str, write_string()); + fusion::fold(tree, &str, write_string()); std::string res = str.str(); BOOST_TEST_EQ(res, "a b c 1 2 3 100 e f 0 B 1 h i 4 5 6 j k l "); diff --git a/test/sequence/segmented_iterator_range.cpp b/test/sequence/segmented_iterator_range.cpp index 55d9e33b..e7cfaf46 100644 --- a/test/sequence/segmented_iterator_range.cpp +++ b/test/sequence/segmented_iterator_range.cpp @@ -7,7 +7,7 @@ ==============================================================================*/ #include #include -#include +#include #include #include #include @@ -59,7 +59,7 @@ process_tree(Tree const &tree) slice_t slice(si, fi); std::stringstream sout; - fusion::for_each_s(slice, ostream_fun(sout)); + fusion::for_each(slice, ostream_fun(sout)); BOOST_TEST((sout.str() == "100 e f 0 B ")); }