• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Boost.Range library
2 //
3 //  Copyright Neil Groves 2009. Use, modification and
4 //  distribution is subject to the Boost Software License, Version
5 //  1.0. (See accompanying file LICENSE_1_0.txt or copy at
6 //  http://www.boost.org/LICENSE_1_0.txt)
7 //
8 // For more information, see http://www.boost.org/libs/range/
9 //
10 #ifndef BOOST_RANGE_ALGORITHM_EXT_FOR_EACH_HPP_INCLUDED
11 #define BOOST_RANGE_ALGORITHM_EXT_FOR_EACH_HPP_INCLUDED
12 
13 #include <boost/range/config.hpp>
14 #include <boost/range/concepts.hpp>
15 #include <boost/range/difference_type.hpp>
16 #include <boost/range/begin.hpp>
17 #include <boost/range/end.hpp>
18 #include <boost/assert.hpp>
19 
20 namespace boost
21 {
22     namespace range_detail
23     {
24         template<class InputIterator1, class InputIterator2, class Fn2>
for_each_impl(InputIterator1 first1,InputIterator1 last1,InputIterator2 first2,InputIterator2 last2,Fn2 fn)25         inline Fn2 for_each_impl(InputIterator1 first1, InputIterator1 last1,
26                                  InputIterator2 first2, InputIterator2 last2,
27                                  Fn2 fn)
28         {
29             for (; first1 != last1 && first2 != last2; ++first1, ++first2)
30             {
31                 fn(*first1, *first2);
32             }
33             return fn;
34         }
35     }
36 
37     namespace range
38     {
39         template<class SinglePassRange1, class SinglePassRange2, class Fn2>
for_each(const SinglePassRange1 & rng1,const SinglePassRange2 & rng2,Fn2 fn)40         inline Fn2 for_each(const SinglePassRange1& rng1, const SinglePassRange2& rng2, Fn2 fn)
41         {
42             BOOST_RANGE_CONCEPT_ASSERT(( SinglePassRangeConcept<const SinglePassRange1> ));
43             BOOST_RANGE_CONCEPT_ASSERT(( SinglePassRangeConcept<const SinglePassRange2> ));
44 
45             return ::boost::range_detail::for_each_impl(
46                 ::boost::begin(rng1), ::boost::end(rng1),
47                 ::boost::begin(rng2), ::boost::end(rng2), fn);
48         }
49 
50         template<class SinglePassRange1, class SinglePassRange2, class Fn2>
for_each(const SinglePassRange1 & rng1,SinglePassRange2 & rng2,Fn2 fn)51         inline Fn2 for_each(const SinglePassRange1& rng1, SinglePassRange2& rng2, Fn2 fn)
52         {
53             BOOST_RANGE_CONCEPT_ASSERT(( SinglePassRangeConcept<const SinglePassRange1> ));
54             BOOST_RANGE_CONCEPT_ASSERT(( SinglePassRangeConcept<SinglePassRange2> ));
55 
56             return ::boost::range_detail::for_each_impl(
57                 ::boost::begin(rng1), ::boost::end(rng1),
58                 ::boost::begin(rng2), ::boost::end(rng2), fn);
59         }
60 
61         template<class SinglePassRange1, class SinglePassRange2, class Fn2>
for_each(SinglePassRange1 & rng1,const SinglePassRange2 & rng2,Fn2 fn)62         inline Fn2 for_each(SinglePassRange1& rng1, const SinglePassRange2& rng2, Fn2 fn)
63         {
64             BOOST_RANGE_CONCEPT_ASSERT(( SinglePassRangeConcept<SinglePassRange1> ));
65             BOOST_RANGE_CONCEPT_ASSERT(( SinglePassRangeConcept<const SinglePassRange2> ));
66 
67             return ::boost::range_detail::for_each_impl(
68                 ::boost::begin(rng1), ::boost::end(rng1),
69                 ::boost::begin(rng2), ::boost::end(rng2), fn);
70         }
71 
72         template<class SinglePassRange1, class SinglePassRange2, class Fn2>
for_each(SinglePassRange1 & rng1,SinglePassRange2 & rng2,Fn2 fn)73         inline Fn2 for_each(SinglePassRange1& rng1, SinglePassRange2& rng2, Fn2 fn)
74         {
75             BOOST_RANGE_CONCEPT_ASSERT(( SinglePassRangeConcept<SinglePassRange1> ));
76             BOOST_RANGE_CONCEPT_ASSERT(( SinglePassRangeConcept<SinglePassRange2> ));
77 
78             return ::boost::range_detail::for_each_impl(
79                 ::boost::begin(rng1), ::boost::end(rng1),
80                 ::boost::begin(rng2), ::boost::end(rng2), fn);
81         }
82     } // namespace range
83     using range::for_each;
84 } // namespace boost
85 
86 #endif // include guard
87