algorithm.mutation.destroyAll: New

Fix #71.
This commit is contained in:
2018-10-29 11:14:33 +01:00
parent 64ceb0330c
commit 1e46109e50
3 changed files with 53 additions and 21 deletions

View File

@ -414,27 +414,19 @@ struct Array(T)
*/
@property void length(size_t len) @trusted
{
if (len == length)
{
return;
}
else if (len > length)
if (len > length)
{
reserve(len);
initializeAll(this.data[length_ .. len]);
}
else
{
static if (hasElaborateDestructor!T)
{
const T* end = this.data + length_ - 1;
for (T* e = this.data + len; e != end; ++e)
{
destroy(*e);
}
}
destroyAll(this.data[len .. this.length_]);
}
if (len != length)
{
length_ = len;
}
length_ = len;
}
///