1
/*=============================================================================
2
Copyright (c) 2001-2006 Joel de Guzman
4
Distributed under the Boost Software License, Version 1.0. (See accompanying
5
file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6
==============================================================================*/
7
#if !defined(FUSION_FOR_EACH_05052005_1028)
8
#define FUSION_FOR_EACH_05052005_1028
10
#include <boost/fusion/sequence/intrinsic/begin.hpp>
11
#include <boost/fusion/sequence/intrinsic/end.hpp>
12
#include <boost/fusion/iterator/equal_to.hpp>
13
#include <boost/fusion/iterator/next.hpp>
14
#include <boost/fusion/iterator/deref.hpp>
15
#include <boost/fusion/iterator/distance.hpp>
16
#include <boost/mpl/bool.hpp>
18
namespace boost { namespace fusion {
21
template <typename First, typename Last, typename F>
23
for_each_linear(First const&, Last const&, F const&, mpl::true_)
27
template <typename First, typename Last, typename F>
29
for_each_linear(First const& first, Last const& last, F const& f, mpl::false_)
32
detail::for_each_linear(fusion::next(first), last, f,
33
result_of::equal_to<typename result_of::next<First>::type, Last>());
37
template <typename Sequence, typename F, typename Tag>
39
for_each(Sequence& seq, F const& f, Tag)
41
detail::for_each_linear(
45
, result_of::equal_to<
46
typename result_of::begin<Sequence>::type
47
, typename result_of::end<Sequence>::type>());
51
struct for_each_unrolled
53
template<typename I0, typename F>
54
static void call(I0 const& i0, F const& f)
57
typedef typename result_of::next<I0>::type I1;
58
I1 i1(fusion::next(i0));
60
typedef typename result_of::next<I1>::type I2;
61
I2 i2(fusion::next(i1));
63
typedef typename result_of::next<I2>::type I3;
64
I3 i3(fusion::next(i2));
66
for_each_unrolled<N-4>::call(fusion::next(i3), f);
71
struct for_each_unrolled<3>
73
template<typename I0, typename F>
74
static void call(I0 const& i0, F const& f)
77
typedef typename result_of::next<I0>::type I1;
78
I1 i1(fusion::next(i0));
80
typedef typename result_of::next<I1>::type I2;
81
I2 i2(fusion::next(i1));
87
struct for_each_unrolled<2>
89
template<typename I0, typename F>
90
static void call(I0 const& i0, F const& f)
93
typedef typename result_of::next<I0>::type I1;
94
I1 i1(fusion::next(i0));
100
struct for_each_unrolled<1>
102
template<typename I0, typename F>
103
static void call(I0 const& i0, F const& f)
110
struct for_each_unrolled<0>
112
template<typename It, typename F>
113
static void call(It const&, F const&)
118
template <typename Sequence, typename F>
120
for_each(Sequence& seq, F const& f, random_access_traversal_tag)
122
typedef typename result_of::begin<Sequence>::type begin;
123
typedef typename result_of::end<Sequence>::type end;
124
for_each_unrolled<result_of::distance<begin, end>::type::value>::call(fusion::begin(seq), f);