12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697 |
- #ifndef BOOST_PHOENIX_ALGORITHM_ITERATION_HPP
- #define BOOST_PHOENIX_ALGORITHM_ITERATION_HPP
- #include <algorithm>
- #include <numeric>
- #include <boost/phoenix/stl/algorithm/detail/begin.hpp>
- #include <boost/phoenix/stl/algorithm/detail/end.hpp>
- #include <boost/phoenix/function/adapt_callable.hpp>
- namespace boost { namespace phoenix {
- namespace impl
- {
- struct for_each
- {
- template <typename Sig>
- struct result;
- template<typename This, class R, class F>
- struct result<This(R&, F)>
- : result<This(R&, F const &)>
- {};
- template<typename This, class R, class F>
- struct result<This(R&, F &)>
- {
- typedef F type;
- };
- template<class R, class F>
- F const operator()(R& r, F const& fn) const
- {
- return std::for_each(detail::begin_(r), detail::end_(r), fn);
- }
- };
- struct accumulate
- {
- template <typename Sig>
- struct result;
-
- template<typename This, class R, class I>
- struct result<This(R&, I)>
- : result<This(R&, I const &)>
- {};
-
- template<typename This, class R, class I>
- struct result<This(R&, I &)>
- {
- typedef I type;
- };
-
- template<typename This, class R, class I, class C>
- struct result<This(R&, I, C)>
- : result<This(R&, I const &, C)>
- {};
- template<typename This, class R, class I, class C>
- struct result<This(R&, I &, C)>
- {
- typedef I type;
- };
- template<class R, class I>
- I
- operator()(R& r, I i) const
- {
- return std::accumulate(detail::begin_(r), detail::end_(r), i);
- }
- template<class R, class I, class C>
- I
- operator()(R& r, I i, C c) const
- {
- return std::accumulate(detail::begin_(r), detail::end_(r), i, c);
- }
- };
- }
- BOOST_PHOENIX_ADAPT_CALLABLE(for_each, impl::for_each, 2)
- BOOST_PHOENIX_ADAPT_CALLABLE(accumulate, impl::accumulate, 2)
- BOOST_PHOENIX_ADAPT_CALLABLE(accumulate, impl::accumulate, 3)
- }}
- #endif
|