Function Vector.shrinkToFit

Requests the Vector to reduce its capacity to fit its length.

void shrinkToFit (
  const bool reallocate = true
) scope;

The request is non-binding.

This function has no effect on the vector length and cannot alter its content.

Examples

Vector!(int, 6) vec = Vector!(int, 6).build(1, 2, 3);

assert(vec.capacity == typeof(vec).minimalCapacity);

vec.reserve(vec.capacity * 2);
assert(vec.capacity > typeof(vec).minimalCapacity);

vec.shrinkToFit();
assert(vec.capacity == typeof(vec).minimalCapacity);