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)
7 // For more information, see http://www.boost.org/libs/range/
9 #ifndef BOOST_RANGE_ALGORITHM_COPY_N_HPP_INCLUDED
10 #define BOOST_RANGE_ALGORITHM_COPY_N_HPP_INCLUDED
12 #include <boost/assert.hpp>
13 #include <boost/concept_check.hpp>
14 #include <boost/range/begin.hpp>
15 #include <boost/range/end.hpp>
16 #include <boost/range/concepts.hpp>
17 #include <boost/range/distance.hpp>
18 #include <boost/range/iterator.hpp>
19 #include <boost/range/iterator_range.hpp>
27 /// \brief template function copy
29 /// range-based version of the copy std algorithm
31 /// \pre SinglePassRange is a model of the SinglePassRangeConcept
32 /// \pre OutputIterator is a model of the OutputIteratorConcept
33 /// \pre 0 <= n <= distance(rng)
34 template< class SinglePassRange, class Size, class OutputIterator >
35 inline OutputIterator copy_n(const SinglePassRange& rng, Size n, OutputIterator out)
37 BOOST_RANGE_CONCEPT_ASSERT(( SinglePassRangeConcept<const SinglePassRange> ));
38 BOOST_ASSERT( n <= static_cast<Size>(::boost::distance(rng)) );
39 BOOST_ASSERT( n >= static_cast<Size>(0) );
41 BOOST_DEDUCED_TYPENAME range_iterator<const SinglePassRange>::type source = ::boost::begin(rng);
43 for (Size i = 0; i < n; ++i, ++out, ++source)
50 using ::boost::range::copy_n;
53 #endif // include guard