Function destroyAll

Destroys all elements in the range.

void destroyAll(Range) (
  Range range
)
if (isInputRange!Range && hasLvalueElements!Range);

This function has effect only if the element type of Range has an elaborate destructor, i.e. it is a struct with an explicit or generated by the compiler destructor.

Parameters

NameDescription
Range Input range type.
range Input range.

Example

static struct WithDtor
{
    private size_t* counter;
    ~this() @nogc nothrow pure
    {
        if (this.counter !is null)
        {
            ++(*this.counter);
        }
    }
}

size_t counter;
WithDtor[2] withDtor = [WithDtor(&counter), WithDtor(&counter)];

destroyAll(withDtor[]);

assert(counter == 2);