summaryrefslogtreecommitdiff
path: root/boost/spirit/home/phoenix/stl/algorithm/iteration.hpp
blob: c11905e738ebf1d7812825f7a74658eaeb82397c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
// Copyright 2005 Daniel Wallin. 
// Copyright 2005 Joel de Guzman.
// Copyright 2005 Dan Marsden. 
//
// Use, modification and distribution is subject to 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)
//
// Modeled after range_ex, Copyright 2004 Eric Niebler

#ifndef PHOENIX_ALGORITHM_ITERATION_HPP
#define PHOENIX_ALGORITHM_ITERATION_HPP

#include <algorithm>
#include <numeric>

#include <boost/spirit/home/phoenix/stl/algorithm/detail/begin.hpp>
#include <boost/spirit/home/phoenix/stl/algorithm/detail/end.hpp>

#include <boost/spirit/home/phoenix/function/function.hpp>

namespace boost { namespace phoenix {
namespace impl
{
    struct for_each
    {
        template<class R, class F>
        struct result
        {
            typedef F type;
        };

        template<class R, class F>
        F operator()(R& r, F fn) const
        {        
            return std::for_each(detail::begin_(r), detail::end_(r), fn);
        }
    };

    struct accumulate
    {
        template<class R, class I, class C = void>
        struct result
        {
            typedef I type;
        };

        template<class R, class I>
        typename result<R,I>::type
        operator()(R& r, I i) const
        {
            return std::accumulate(detail::begin_(r), detail::end_(r), i);
        }

        template<class R, class I, class C>
        typename result<R,I,C>::type
        operator()(R& r, I i, C c) const
        {
            return std::accumulate(detail::begin_(r), detail::end_(r), i, c);
        }
    };
}

function<impl::for_each> const for_each = impl::for_each();
function<impl::accumulate> const accumulate = impl::accumulate();

}}

#endif