copy_n.hpp 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. // Copyright Neil Groves 2009. Use, modification and
  2. // distribution is subject to the Boost Software License, Version
  3. // 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  4. // http://www.boost.org/LICENSE_1_0.txt)
  5. //
  6. //
  7. // For more information, see http://www.boost.org/libs/range/
  8. //
  9. #ifndef BOOST_RANGE_ALGORITHM_COPY_N_HPP_INCLUDED
  10. #define BOOST_RANGE_ALGORITHM_COPY_N_HPP_INCLUDED
  11. #include <boost/assert.hpp>
  12. #include <boost/concept_check.hpp>
  13. #include <boost/range/begin.hpp>
  14. #include <boost/range/end.hpp>
  15. #include <boost/range/concepts.hpp>
  16. #include <boost/range/distance.hpp>
  17. #include <boost/range/iterator.hpp>
  18. #include <boost/range/iterator_range.hpp>
  19. #include <algorithm>
  20. namespace boost
  21. {
  22. namespace range
  23. {
  24. /// \brief template function copy
  25. ///
  26. /// range-based version of the copy std algorithm
  27. ///
  28. /// \pre SinglePassRange is a model of the SinglePassRangeConcept
  29. /// \pre OutputIterator is a model of the OutputIteratorConcept
  30. /// \pre 0 <= n <= distance(rng)
  31. template< class SinglePassRange, class Size, class OutputIterator >
  32. inline OutputIterator copy_n(const SinglePassRange& rng, Size n, OutputIterator out)
  33. {
  34. BOOST_RANGE_CONCEPT_ASSERT(( SinglePassRangeConcept<const SinglePassRange> ));
  35. BOOST_ASSERT( n <= static_cast<Size>(::boost::distance(rng)) );
  36. BOOST_ASSERT( n >= static_cast<Size>(0) );
  37. BOOST_DEDUCED_TYPENAME range_iterator<const SinglePassRange>::type source = ::boost::begin(rng);
  38. for (Size i = 0; i < n; ++i, ++out, ++source)
  39. *out = *source;
  40. return out;
  41. }
  42. } // namespace range
  43. using ::boost::range::copy_n;
  44. } // namespace boost
  45. #endif // include guard