## destroy
## Prototype
template <class T> void destroy(T* pointer); template <class ForwardIterator> void destroy(ForwardIterator first, ForwardIterator last); ## DescriptionIn C++, the operator The first version of The second version of ## DefinitionDefined in the standard header memory, and in the nonstandard backward-compatibility header algo.h. The ## Requirements on typesFor the first version of -
`T` 's destructor,`~T` , is accessible.
For the second version of -
`ForwardIterator` is a model of ForwardIterator. -
`ForwardIterator` is mutable. -
`ForwardIterator` 's value type has an accessible destructor.
## PreconditionsFor the first version of -
`pointer` points to a valid object of type`T` .
For the second version of -
`[first, last)` is a valid range. -
Each iterator
`i` in`[first, last)` points to a valid object.
## ComplexityThe run-time complexity of the second version is linear: it calls the destructor exactly ## Exampleclass Int { public: Int(int x) : val(x) {} int get() { return val; } private: int val; }; int main() { Int A[] = { Int(1), Int(2), Int(3), Int(4) }; destroy(A, A + 4); construct(A, Int(10)); construct(A + 1, Int(11)); construct(A + 2, Int(12)); construct(A + 3, Int(13)); } ## Notes[1] In particular, ## See alsoAllocators, |