1 // Copyright 2005 Daniel Wallin.
2 // Copyright 2005 Joel de Guzman.
3 // Copyright 2005 Dan Marsden.
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)
9 // Modeled after range_ex, Copyright 2004 Eric Niebler
11 #ifndef BOOST_PHOENIX_ALGORITHM_ITERATION_HPP
12 #define BOOST_PHOENIX_ALGORITHM_ITERATION_HPP
17 #include <boost/phoenix/stl/algorithm/detail/begin.hpp>
18 #include <boost/phoenix/stl/algorithm/detail/end.hpp>
20 #include <boost/phoenix/function/adapt_callable.hpp>
22 namespace boost { namespace phoenix {
27 template <typename Sig>
30 template<typename This, class R, class F>
31 struct result<This(R&, F)>
32 : result<This(R&, F const &)>
35 template<typename This, class R, class F>
36 struct result<This(R&, F &)>
41 template<class R, class F>
42 F const operator()(R& r, F const& fn) const
44 return std::for_each(detail::begin_(r), detail::end_(r), fn);
50 template <typename Sig>
53 template<typename This, class R, class I>
54 struct result<This(R&, I)>
55 : result<This(R&, I const &)>
58 template<typename This, class R, class I>
59 struct result<This(R&, I &)>
64 template<typename This, class R, class I, class C>
65 struct result<This(R&, I, C)>
66 : result<This(R&, I const &, C)>
69 template<typename This, class R, class I, class C>
70 struct result<This(R&, I &, C)>
75 template<class R, class I>
77 operator()(R& r, I i) const
79 return std::accumulate(detail::begin_(r), detail::end_(r), i);
82 template<class R, class I, class C>
84 operator()(R& r, I i, C c) const
86 return std::accumulate(detail::begin_(r), detail::end_(r), i, c);
91 BOOST_PHOENIX_ADAPT_CALLABLE(for_each, impl::for_each, 2)
92 BOOST_PHOENIX_ADAPT_CALLABLE(accumulate, impl::accumulate, 2)
93 BOOST_PHOENIX_ADAPT_CALLABLE(accumulate, impl::accumulate, 3)