Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:47:40

0001 // Copyright 2005 Daniel Wallin. 
0002 // Copyright 2005 Joel de Guzman.
0003 // Copyright 2005 Dan Marsden. 
0004 //
0005 // Use, modification and distribution is subject to the Boost Software 
0006 // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
0007 // http://www.boost.org/LICENSE_1_0.txt)
0008 //
0009 // Modeled after range_ex, Copyright 2004 Eric Niebler
0010 
0011 #ifndef BOOST_PHOENIX_ALGORITHM_ITERATION_HPP
0012 #define BOOST_PHOENIX_ALGORITHM_ITERATION_HPP
0013 
0014 #include <algorithm>
0015 #include <numeric>
0016 
0017 #include <boost/phoenix/stl/algorithm/detail/begin.hpp>
0018 #include <boost/phoenix/stl/algorithm/detail/end.hpp>
0019 
0020 #include <boost/phoenix/function/adapt_callable.hpp>
0021 
0022 namespace boost { namespace phoenix {
0023     namespace impl
0024     {
0025         struct for_each
0026         {
0027             template <typename Sig>
0028             struct result;
0029 
0030             template<typename This, class R, class F>
0031             struct result<This(R&, F)>
0032                 : result<This(R&, F const &)>
0033             {};
0034 
0035             template<typename This, class R, class F>
0036             struct result<This(R&, F &)>
0037             {
0038                 typedef F type;
0039             };
0040 
0041             template<class R, class F>
0042             F const operator()(R& r, F const& fn) const
0043             {        
0044                 return std::for_each(detail::begin_(r), detail::end_(r), fn);
0045             }
0046         };
0047 
0048         struct accumulate
0049         {
0050             template <typename Sig>
0051             struct result;
0052             
0053             template<typename This, class R, class I>
0054             struct result<This(R&, I)>
0055                 : result<This(R&, I const &)>
0056             {};
0057             
0058             template<typename This, class R, class I>
0059             struct result<This(R&, I &)>
0060             {
0061                 typedef I type;
0062             };
0063             
0064             template<typename This, class R, class I, class C>
0065             struct result<This(R&, I, C)>
0066                 : result<This(R&, I const &, C)>
0067             {};
0068 
0069             template<typename This, class R, class I, class C>
0070             struct result<This(R&, I &, C)>
0071             {
0072                 typedef I type;
0073             };
0074 
0075             template<class R, class I>
0076             I
0077             operator()(R& r, I i) const
0078             {
0079                 return std::accumulate(detail::begin_(r), detail::end_(r), i);
0080             }
0081 
0082             template<class R, class I, class C>
0083             I
0084             operator()(R& r, I i, C c) const
0085             {
0086                 return std::accumulate(detail::begin_(r), detail::end_(r), i, c);
0087             }
0088         };
0089     }
0090 
0091     BOOST_PHOENIX_ADAPT_CALLABLE(for_each, impl::for_each, 2)
0092     BOOST_PHOENIX_ADAPT_CALLABLE(accumulate, impl::accumulate, 2)
0093     BOOST_PHOENIX_ADAPT_CALLABLE(accumulate, impl::accumulate, 3)
0094 
0095 }}
0096 
0097 #endif