diff --git a/include/boost/fusion/algorithm/iteration/detail/for_each.hpp b/include/boost/fusion/algorithm/iteration/detail/for_each.hpp index a23517c8..f2fcc4e7 100644 --- a/include/boost/fusion/algorithm/iteration/detail/for_each.hpp +++ b/include/boost/fusion/algorithm/iteration/detail/for_each.hpp @@ -13,6 +13,7 @@ #include #include #include +#include #include namespace boost { namespace fusion { @@ -36,7 +37,7 @@ namespace detail template inline void - for_each(Sequence& seq, F const& f, Tag) + for_each_dispatch(Sequence& seq, F const& f, Tag) { detail::for_each_linear( fusion::begin(seq) @@ -117,12 +118,19 @@ namespace detail template inline void - for_each(Sequence& seq, F const& f, random_access_traversal_tag) + for_each_dispatch(Sequence& seq, F const& f, random_access_traversal_tag) { typedef typename result_of::begin::type begin; typedef typename result_of::end::type end; for_each_unrolled::type::value>::call(fusion::begin(seq), f); } + + template + inline void + for_each(Sequence& seq, F const& f, mpl::false_) // unsegmented implementation + { + detail::for_each_dispatch(seq, f, typename traits::category_of::type()); + } }}} diff --git a/include/boost/fusion/algorithm/iteration/ext_/for_each_s.hpp b/include/boost/fusion/algorithm/iteration/detail/segmented_for_each.hpp similarity index 62% rename from include/boost/fusion/algorithm/iteration/ext_/for_each_s.hpp rename to include/boost/fusion/algorithm/iteration/detail/segmented_for_each.hpp index 4ea4b141..f7ffb24d 100644 --- a/include/boost/fusion/algorithm/iteration/ext_/for_each_s.hpp +++ b/include/boost/fusion/algorithm/iteration/detail/segmented_for_each.hpp @@ -4,11 +4,12 @@ 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_FOR_EACH_S_HPP_INCLUDED) -#define BOOST_FUSION_FOR_EACH_S_HPP_INCLUDED +#if !defined(BOOST_FUSION_SEGMENTED_FOR_EACH_HPP_INCLUDED) +#define BOOST_FUSION_SEGMENTED_FOR_EACH_HPP_INCLUDED +#include #include -#include +#include #include namespace boost { namespace fusion { namespace detail @@ -35,32 +36,13 @@ namespace boost { namespace fusion { namespace detail } }; }; + + template + inline void + for_each(Sequence& seq, F const& f, mpl::true_) // segmented implementation + { + fusion::segmented_fold_until(seq, void_(), segmented_for_each_fun(f)); + } }}} -namespace boost { namespace fusion -{ - namespace result_of - { - template - struct for_each_s - { - typedef void type; - }; - } - - template - inline void - for_each_s(Sequence& seq, F const& f) - { - fusion::segmented_fold_until(seq, void_(), detail::segmented_for_each_fun(f)); - } - - template - inline void - for_each_s(Sequence const& seq, F const& f) - { - fusion::segmented_fold_until(seq, void_(), detail::segmented_for_each_fun(f)); - } -}} - #endif diff --git a/include/boost/fusion/algorithm/iteration/for_each.hpp b/include/boost/fusion/algorithm/iteration/for_each.hpp index fffb0f00..ab8b8f0e 100644 --- a/include/boost/fusion/algorithm/iteration/for_each.hpp +++ b/include/boost/fusion/algorithm/iteration/for_each.hpp @@ -9,11 +9,11 @@ #define BOOST_FUSION_FOR_EACH_20070527_0943 #include +#include +#include -#include - -namespace boost { namespace fusion { - +namespace boost { namespace fusion +{ namespace result_of { template @@ -23,20 +23,18 @@ namespace boost { namespace fusion { }; } - struct random_access_traversal_tag; - template inline void for_each(Sequence& seq, F const& f) { - detail::for_each(seq, f, typename traits::category_of::type()); + detail::for_each(seq, f, typename traits::is_segmented::type()); } template inline void for_each(Sequence const& seq, F const& f) { - detail::for_each(seq, f, typename traits::category_of::type()); + detail::for_each(seq, f, typename traits::is_segmented::type()); } }} diff --git a/include/boost/fusion/algorithm/iteration/for_each_fwd.hpp b/include/boost/fusion/algorithm/iteration/for_each_fwd.hpp new file mode 100644 index 00000000..544915d9 --- /dev/null +++ b/include/boost/fusion/algorithm/iteration/for_each_fwd.hpp @@ -0,0 +1,27 @@ +/*============================================================================= + 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_FOR_EACH_FWD_HPP_INCLUDED) +#define BOOST_FUSION_FOR_EACH_FWD_HPP_INCLUDED + +namespace boost { namespace fusion +{ + namespace result_of + { + template + struct for_each; + } + + template + void + for_each(Sequence& seq, F const& f); + + template + void + for_each(Sequence const& seq, F const& f); +}} + +#endif diff --git a/test/algorithm/segmented_for_each.cpp b/test/algorithm/segmented_for_each.cpp index 3d1e4a60..b1f8c1b7 100644 --- a/test/algorithm/segmented_for_each.cpp +++ b/test/algorithm/segmented_for_each.cpp @@ -7,7 +7,7 @@ ==============================================================================*/ #include #include -#include +#include #include #include "../sequence/tree.hpp" @@ -26,7 +26,7 @@ main() using namespace boost::fusion; { - for_each_s( + for_each( make_tree( make_vector(double(0),'B') , make_tree(