copy_n.hpp 1.2 KB

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