1 | /*=============================================================================
|
---|
2 | Copyright (c) 2003 Joel de Guzman
|
---|
3 | Copyright (c) 2004 Peder Holt
|
---|
4 |
|
---|
5 | Use, modification and distribution is subject to the Boost Software
|
---|
6 | License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
---|
7 | http://www.boost.org/LICENSE_1_0.txt)
|
---|
8 | ==============================================================================*/
|
---|
9 | #if !defined(FUSION_ALGORITHM_FOLD_HPP)
|
---|
10 | #define FUSION_ALGORITHM_FOLD_HPP
|
---|
11 |
|
---|
12 | #include <boost/spirit/fusion/algorithm/detail/fold.ipp>
|
---|
13 |
|
---|
14 | namespace boost { namespace fusion
|
---|
15 | {
|
---|
16 | namespace meta
|
---|
17 | {
|
---|
18 | template <typename Sequence, typename State, typename F>
|
---|
19 | struct fold
|
---|
20 | {
|
---|
21 | typedef typename
|
---|
22 | detail::static_fold<
|
---|
23 | typename meta::begin<Sequence>::type
|
---|
24 | , typename meta::end<Sequence>::type
|
---|
25 | , State
|
---|
26 | , F
|
---|
27 | >::type
|
---|
28 | type;
|
---|
29 | };
|
---|
30 | }
|
---|
31 |
|
---|
32 | namespace function
|
---|
33 | {
|
---|
34 | struct fold
|
---|
35 | {
|
---|
36 | template <typename Sequence, typename State, typename F>
|
---|
37 | struct apply : meta::fold<Sequence, State, F> {};
|
---|
38 |
|
---|
39 | template <typename Sequence, typename State, typename F>
|
---|
40 | inline typename apply<Sequence const, State, F>::type
|
---|
41 | operator()(Sequence const& seq, State const& state, F const& f) const
|
---|
42 | {
|
---|
43 | return detail::fold(
|
---|
44 | fusion::begin(seq)
|
---|
45 | , fusion::end(seq)
|
---|
46 | , state
|
---|
47 | , f
|
---|
48 | , is_same<
|
---|
49 | BOOST_DEDUCED_TYPENAME meta::begin<Sequence const>::type
|
---|
50 | , BOOST_DEDUCED_TYPENAME meta::end<Sequence const>::type>()
|
---|
51 | );
|
---|
52 | }
|
---|
53 |
|
---|
54 | template <typename Sequence, typename State, typename F>
|
---|
55 | inline typename apply<Sequence, State, F>::type
|
---|
56 | operator()(Sequence& seq, State const& state, F const& f) const
|
---|
57 | {
|
---|
58 | return detail::fold(
|
---|
59 | fusion::begin(seq)
|
---|
60 | , fusion::end(seq)
|
---|
61 | , state
|
---|
62 | , f
|
---|
63 | , is_same<
|
---|
64 | BOOST_DEDUCED_TYPENAME meta::begin<Sequence>::type
|
---|
65 | , BOOST_DEDUCED_TYPENAME meta::end<Sequence>::type>()
|
---|
66 | );
|
---|
67 | }
|
---|
68 | };
|
---|
69 | }
|
---|
70 |
|
---|
71 | function::fold const fold = function::fold();
|
---|
72 | }}
|
---|
73 |
|
---|
74 | #endif
|
---|
75 |
|
---|