Chris@16
|
1 /*
|
Chris@16
|
2 Copyright (c) Marshall Clow 2011-2012.
|
Chris@16
|
3
|
Chris@16
|
4 Distributed under the Boost Software License, Version 1.0. (See accompanying
|
Chris@16
|
5 file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
Chris@16
|
6 */
|
Chris@16
|
7
|
Chris@16
|
8 /// \file copy_n.hpp
|
Chris@16
|
9 /// \brief Copy n items from one sequence to another
|
Chris@16
|
10 /// \author Marshall Clow
|
Chris@16
|
11
|
Chris@16
|
12 #ifndef BOOST_ALGORITHM_COPY_N_HPP
|
Chris@16
|
13 #define BOOST_ALGORITHM_COPY_N_HPP
|
Chris@16
|
14
|
Chris@16
|
15 #include <algorithm> // for std::copy_n, if available
|
Chris@16
|
16
|
Chris@16
|
17 namespace boost { namespace algorithm {
|
Chris@16
|
18
|
Chris@16
|
19 /// \fn copy_n ( InputIterator first, Size n, OutputIterator result )
|
Chris@16
|
20 /// \brief Copies exactly n (n > 0) elements from the range starting at first to
|
Chris@16
|
21 /// the range starting at result.
|
Chris@16
|
22 /// \return The updated output iterator
|
Chris@16
|
23 ///
|
Chris@16
|
24 /// \param first The start of the input sequence
|
Chris@16
|
25 /// \param n The number of elements to copy
|
Chris@16
|
26 /// \param result An output iterator to write the results into
|
Chris@16
|
27 /// \note This function is part of the C++2011 standard library.
|
Chris@16
|
28 /// We will use the standard one if it is available,
|
Chris@16
|
29 /// otherwise we have our own implementation.
|
Chris@16
|
30 template <typename InputIterator, typename Size, typename OutputIterator>
|
Chris@16
|
31 OutputIterator copy_n ( InputIterator first, Size n, OutputIterator result )
|
Chris@16
|
32 {
|
Chris@16
|
33 for ( ; n > 0; --n, ++first, ++result )
|
Chris@16
|
34 *result = *first;
|
Chris@16
|
35 return result;
|
Chris@16
|
36 }
|
Chris@16
|
37 }} // namespace boost and algorithm
|
Chris@16
|
38
|
Chris@16
|
39 #endif // BOOST_ALGORITHM_COPY_IF_HPP
|