| 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 | |
| 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> |
| 20 | #include <algorithm> |
| 21 | |
| 22 | namespace boost |
| 23 | { |
| 24 | namespace range |
| 25 | { |
| 26 | |
| 27 | /// \brief template function copy |
| 28 | /// |
| 29 | /// range-based version of the copy std algorithm |
| 30 | /// |
| 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) |
| 36 | { |
| 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) ); |
| 40 | |
| 41 | BOOST_DEDUCED_TYPENAME range_iterator<const SinglePassRange>::type source = ::boost::begin(rng); |
| 42 | |
| 43 | for (Size i = 0; i < n; ++i, ++out, ++source) |
| 44 | *out = *source; |
| 45 | |
| 46 | return out; |
| 47 | } |
| 48 | |
| 49 | } // namespace range |
| 50 | using ::boost::range::copy_n; |
| 51 | } // namespace boost |
| 52 | |
| 53 | #endif // include guard |
| 54 |
