Imported Upstream version 1.51.0
[platform/upstream/boost.git] / boost / spirit / home / phoenix / stl / algorithm / iteration.hpp
1 // Copyright 2005 Daniel Wallin. 
2 // Copyright 2005 Joel de Guzman.
3 // Copyright 2005 Dan Marsden. 
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 // Modeled after range_ex, Copyright 2004 Eric Niebler
10
11 #ifndef PHOENIX_ALGORITHM_ITERATION_HPP
12 #define PHOENIX_ALGORITHM_ITERATION_HPP
13
14 #include <algorithm>
15 #include <numeric>
16
17 #include <boost/spirit/home/phoenix/stl/algorithm/detail/begin.hpp>
18 #include <boost/spirit/home/phoenix/stl/algorithm/detail/end.hpp>
19
20 #include <boost/spirit/home/phoenix/function/function.hpp>
21
22 namespace boost { namespace phoenix {
23 namespace impl
24 {
25     struct for_each
26     {
27         template<class R, class F>
28         struct result
29         {
30             typedef F type;
31         };
32
33         template<class R, class F>
34         F operator()(R& r, F fn) const
35         {        
36             return std::for_each(detail::begin_(r), detail::end_(r), fn);
37         }
38     };
39
40     struct accumulate
41     {
42         template<class R, class I, class C = void>
43         struct result
44         {
45             typedef I type;
46         };
47
48         template<class R, class I>
49         typename result<R,I>::type
50         operator()(R& r, I i) const
51         {
52             return std::accumulate(detail::begin_(r), detail::end_(r), i);
53         }
54
55         template<class R, class I, class C>
56         typename result<R,I,C>::type
57         operator()(R& r, I i, C c) const
58         {
59             return std::accumulate(detail::begin_(r), detail::end_(r), i, c);
60         }
61     };
62 }
63
64 function<impl::for_each> const for_each = impl::for_each();
65 function<impl::accumulate> const accumulate = impl::accumulate();
66
67 }}
68
69 #endif