
ALINK="#ff0000">
copy_n
Prototypetemplate <class InputIterator, class Size, class OutputIterator> OutputIterator copy_n(InputIterator first, Size count, OutputIterator result); DescriptionCopy_n copies elements from the range [first, first + n) to the range [result, result + n). That is, it performs the assignments *result = *first, *(result + 1) = *(first + 1), and so on. Generally, for every integer i from 0 up to (but not including) n, copy_n performs the assignment *(result + i) = *(first + i). Assignments are performed in forward order, i.e. in order of increasing n. [1]The return value is result + n. DefinitionDefined in the standard header algorithm, and in the nonstandard backwardcompatibility header algo.h. This function is an SGI extension; it is not part of the C++ standard.Requirements on types
Preconditions
ComplexityLinear. Exactly n assignments are performed.Examplevector<int> V(5); iota(V.begin(), V.end(), 1); list<int> L(V.size()); copy_n(V.begin(), V.size(), L.begin()); assert(equal(V.begin(), V.end(), L.begin())); Notes[1] Copy_n is almost, but not quite, redundant. If first is an input iterator, as opposed to a forward iterator, then the copy_n operation can't be expressed in terms of copy. See alsocopy, copy_backwardCopyright © 1999 Silicon Graphics, Inc. All Rights Reserved. TrademarkInformation
