mirror of
https://github.com/boostorg/fusion.git
synced 2025-07-23 00:57:20 +02:00
make for_each aware of segments
[SVN r73899]
This commit is contained in:
@ -13,6 +13,7 @@
|
|||||||
#include <boost/fusion/iterator/next.hpp>
|
#include <boost/fusion/iterator/next.hpp>
|
||||||
#include <boost/fusion/iterator/deref.hpp>
|
#include <boost/fusion/iterator/deref.hpp>
|
||||||
#include <boost/fusion/iterator/distance.hpp>
|
#include <boost/fusion/iterator/distance.hpp>
|
||||||
|
#include <boost/fusion/support/category_of.hpp>
|
||||||
#include <boost/mpl/bool.hpp>
|
#include <boost/mpl/bool.hpp>
|
||||||
|
|
||||||
namespace boost { namespace fusion {
|
namespace boost { namespace fusion {
|
||||||
@ -36,7 +37,7 @@ namespace detail
|
|||||||
|
|
||||||
template <typename Sequence, typename F, typename Tag>
|
template <typename Sequence, typename F, typename Tag>
|
||||||
inline void
|
inline void
|
||||||
for_each(Sequence& seq, F const& f, Tag)
|
for_each_dispatch(Sequence& seq, F const& f, Tag)
|
||||||
{
|
{
|
||||||
detail::for_each_linear(
|
detail::for_each_linear(
|
||||||
fusion::begin(seq)
|
fusion::begin(seq)
|
||||||
@ -117,12 +118,19 @@ namespace detail
|
|||||||
|
|
||||||
template <typename Sequence, typename F>
|
template <typename Sequence, typename F>
|
||||||
inline void
|
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<Sequence>::type begin;
|
typedef typename result_of::begin<Sequence>::type begin;
|
||||||
typedef typename result_of::end<Sequence>::type end;
|
typedef typename result_of::end<Sequence>::type end;
|
||||||
for_each_unrolled<result_of::distance<begin, end>::type::value>::call(fusion::begin(seq), f);
|
for_each_unrolled<result_of::distance<begin, end>::type::value>::call(fusion::begin(seq), f);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <typename Sequence, typename F>
|
||||||
|
inline void
|
||||||
|
for_each(Sequence& seq, F const& f, mpl::false_) // unsegmented implementation
|
||||||
|
{
|
||||||
|
detail::for_each_dispatch(seq, f, typename traits::category_of<Sequence>::type());
|
||||||
|
}
|
||||||
}}}
|
}}}
|
||||||
|
|
||||||
|
|
||||||
|
@ -4,11 +4,12 @@
|
|||||||
Distributed under the Boost Software License, Version 1.0. (See accompanying
|
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)
|
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)
|
#if !defined(BOOST_FUSION_SEGMENTED_FOR_EACH_HPP_INCLUDED)
|
||||||
#define BOOST_FUSION_FOR_EACH_S_HPP_INCLUDED
|
#define BOOST_FUSION_SEGMENTED_FOR_EACH_HPP_INCLUDED
|
||||||
|
|
||||||
|
#include <boost/mpl/bool.hpp>
|
||||||
#include <boost/fusion/support/void.hpp>
|
#include <boost/fusion/support/void.hpp>
|
||||||
#include <boost/fusion/algorithm/iteration/for_each.hpp>
|
#include <boost/fusion/algorithm/iteration/for_each_fwd.hpp>
|
||||||
#include <boost/fusion/support/segmented_fold_until.hpp>
|
#include <boost/fusion/support/segmented_fold_until.hpp>
|
||||||
|
|
||||||
namespace boost { namespace fusion { namespace detail
|
namespace boost { namespace fusion { namespace detail
|
||||||
@ -35,32 +36,13 @@ namespace boost { namespace fusion { namespace detail
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
template <typename Sequence, typename F>
|
||||||
|
inline void
|
||||||
|
for_each(Sequence& seq, F const& f, mpl::true_) // segmented implementation
|
||||||
|
{
|
||||||
|
fusion::segmented_fold_until(seq, void_(), segmented_for_each_fun<F>(f));
|
||||||
|
}
|
||||||
}}}
|
}}}
|
||||||
|
|
||||||
namespace boost { namespace fusion
|
|
||||||
{
|
|
||||||
namespace result_of
|
|
||||||
{
|
|
||||||
template <typename Sequence, typename F>
|
|
||||||
struct for_each_s
|
|
||||||
{
|
|
||||||
typedef void type;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename Sequence, typename F>
|
|
||||||
inline void
|
|
||||||
for_each_s(Sequence& seq, F const& f)
|
|
||||||
{
|
|
||||||
fusion::segmented_fold_until(seq, void_(), detail::segmented_for_each_fun<F>(f));
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename Sequence, typename F>
|
|
||||||
inline void
|
|
||||||
for_each_s(Sequence const& seq, F const& f)
|
|
||||||
{
|
|
||||||
fusion::segmented_fold_until(seq, void_(), detail::segmented_for_each_fun<F>(f));
|
|
||||||
}
|
|
||||||
}}
|
|
||||||
|
|
||||||
#endif
|
#endif
|
@ -9,11 +9,11 @@
|
|||||||
#define BOOST_FUSION_FOR_EACH_20070527_0943
|
#define BOOST_FUSION_FOR_EACH_20070527_0943
|
||||||
|
|
||||||
#include <boost/fusion/algorithm/iteration/detail/for_each.hpp>
|
#include <boost/fusion/algorithm/iteration/detail/for_each.hpp>
|
||||||
|
#include <boost/fusion/algorithm/iteration/detail/segmented_for_each.hpp>
|
||||||
|
#include <boost/fusion/support/is_segmented.hpp>
|
||||||
|
|
||||||
#include <boost/fusion/support/category_of.hpp>
|
namespace boost { namespace fusion
|
||||||
|
{
|
||||||
namespace boost { namespace fusion {
|
|
||||||
|
|
||||||
namespace result_of
|
namespace result_of
|
||||||
{
|
{
|
||||||
template <typename Sequence, typename F>
|
template <typename Sequence, typename F>
|
||||||
@ -23,20 +23,18 @@ namespace boost { namespace fusion {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
struct random_access_traversal_tag;
|
|
||||||
|
|
||||||
template <typename Sequence, typename F>
|
template <typename Sequence, typename F>
|
||||||
inline void
|
inline void
|
||||||
for_each(Sequence& seq, F const& f)
|
for_each(Sequence& seq, F const& f)
|
||||||
{
|
{
|
||||||
detail::for_each(seq, f, typename traits::category_of<Sequence>::type());
|
detail::for_each(seq, f, typename traits::is_segmented<Sequence>::type());
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename Sequence, typename F>
|
template <typename Sequence, typename F>
|
||||||
inline void
|
inline void
|
||||||
for_each(Sequence const& seq, F const& f)
|
for_each(Sequence const& seq, F const& f)
|
||||||
{
|
{
|
||||||
detail::for_each(seq, f, typename traits::category_of<Sequence>::type());
|
detail::for_each(seq, f, typename traits::is_segmented<Sequence>::type());
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
|
|
||||||
|
27
include/boost/fusion/algorithm/iteration/for_each_fwd.hpp
Normal file
27
include/boost/fusion/algorithm/iteration/for_each_fwd.hpp
Normal file
@ -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 <typename Sequence, typename F>
|
||||||
|
struct for_each;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename Sequence, typename F>
|
||||||
|
void
|
||||||
|
for_each(Sequence& seq, F const& f);
|
||||||
|
|
||||||
|
template <typename Sequence, typename F>
|
||||||
|
void
|
||||||
|
for_each(Sequence const& seq, F const& f);
|
||||||
|
}}
|
||||||
|
|
||||||
|
#endif
|
@ -7,7 +7,7 @@
|
|||||||
==============================================================================*/
|
==============================================================================*/
|
||||||
#include <boost/detail/lightweight_test.hpp>
|
#include <boost/detail/lightweight_test.hpp>
|
||||||
#include <boost/fusion/container/vector/vector.hpp>
|
#include <boost/fusion/container/vector/vector.hpp>
|
||||||
#include <boost/fusion/algorithm/iteration/ext_/for_each_s.hpp>
|
#include <boost/fusion/algorithm/iteration/for_each.hpp>
|
||||||
#include <boost/fusion/container/generation/make_vector.hpp>
|
#include <boost/fusion/container/generation/make_vector.hpp>
|
||||||
#include "../sequence/tree.hpp"
|
#include "../sequence/tree.hpp"
|
||||||
|
|
||||||
@ -26,7 +26,7 @@ main()
|
|||||||
using namespace boost::fusion;
|
using namespace boost::fusion;
|
||||||
|
|
||||||
{
|
{
|
||||||
for_each_s(
|
for_each(
|
||||||
make_tree(
|
make_tree(
|
||||||
make_vector(double(0),'B')
|
make_vector(double(0),'B')
|
||||||
, make_tree(
|
, make_tree(
|
||||||
|
Reference in New Issue
Block a user