import std.stdio : writefln; void test(string str) { writefln("%d, %d", str.length, str.capacity); str.length = 10; writefln("%d, %d", str.length, str.capacity); }
void main() { string str; str.reserve(1024); //str.length = str.capacity; writefln("%d, %d", str.length, str.capacity); test(str); writefln("%d, %d", str.length, str.capacity); } The output is: 0, 1358 0, 1358 10, 1358 0, 0 If I uncomment the line str.length = str.capacity; then the output is: 1358, 1358 1358, 1358 10, 0 1358, 1358 why?