1 /*
2    Copyright (c) Marshall Clow 2017.
3 
4    Distributed under the Boost Software License, Version 1.0. (See accompanying
5    file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6 */
7 
8 /// \file  for_each_n.hpp
9 /// \brief Apply a functor to the elements of a sequence
10 /// \author Marshall Clow
11 
12 #ifndef BOOST_ALGORITHM_FOR_EACH_N_HPP
13 #define BOOST_ALGORITHM_FOR_EACH_N_HPP
14 
15 #include <utility>      // for std::pair
16 
17 #include <boost/config.hpp>
18 
19 namespace boost { namespace algorithm {
20 
21 /// \fn for_each_n(InputIterator first, Size n, Function f);
22 /// \return first + n
23 ///
24 /// \param first    The start of the first range.
25 /// \param n        One past the end of the first range.
26 /// \param f        A functor to apply to the elements of the sequence
27 /// \note           If f returns a result, the result is ignored.
28 template<class InputIterator, class Size, class Function>
29 InputIterator for_each_n(InputIterator first, Size n, Function f)
30 {
31     for ( ; n > 0; --n, ++first )
32         f(*first);
33 
34     return first;
35 }
36 
37 }} // namespace boost and algorithm
38 
39 #endif // BOOST_ALGORITHM_FOR_EACH_N_HPP
40