|
ALINK="#ff0000">
uninitialized_fill_n
Prototypetemplate <class ForwardIterator, class Size, class T> ForwardIterator uninitialized_fill_n(ForwardIterator first, Size n, const T& x); DescriptionIn C++, the operator new allocates memory for an object and then creates an object at that location by calling a constructor. Occasionally, however, it is useful to separate those two operations. [1] If each iterator in the range [first, first + n) points to uninitialized memory, then uninitialized_fill_n creates copies of x in that range. That is, for each iterator i in the range [first, first + n), uninitialized_fill_n creates a copy of x in the location pointed to i by calling construct(&*i, x).DefinitionDefined in the standard header memory, and in the nonstandard backward-compatibility header algo.h.Requirements on types
Preconditions
ComplexityLinear. Exactly n constructor calls.Exampleclass Int { public: Int(int x) : val(x) {} int get() { return val; } private: int val; }; int main() { const int N = 137; Int val(46); Int* A = (Int*) malloc(N * sizeof(Int)); uninitialized_fill_n(A, N, val); } Notes[1] In particular, this sort of low-level memory management is used in the implementation of some container classes. See alsoAllocators, construct, destroy, uninitialized_copy, uninitialized_fill, raw_storage_iteratorCopyright © 1999 Silicon Graphics, Inc. All Rights Reserved. TrademarkInformation
|