Function BasicString.capacity

Returns the size of the storage space currently allocated for the BasicString, expressed in terms of characters (utf code units).

size_t capacity() const pure nothrow @nogc @property scope @trusted;

This capacity is not necessarily equal to the string length. It can be equal or greater, with the extra space allowing the object to optimize its operations when new characters are added to the BasicString.

Notice that this capacity does not suppose a limit on the length of the BasicString. When this capacity is exhausted and more is needed, it is automatically expanded by the object (reallocating it storage space).

The capacity of a BasicString can be altered any time the object is modified, even if this modification implies a reduction in size.

The capacity of a BasicString can be explicitly altered by calling member reserve.


BasicString!char str;
assert(str.capacity == BasicString!char.minimalCapacity);

str.reserve(str.capacity + 1);
assert(str.capacity > BasicString!char.minimalCapacity);