()@system{ BasicString!char str = "123"; char[] slice = str[]; assert(slice.length == str.length); assert(slice.ptr is str.ptr); str.reserve(str.capacity * 2); assert(slice.length == str.length); assert(slice.ptr !is str.ptr); // slice contains dangling pointer. }(); ()@safe{ FixedString!(char, 20) str = "123"; char[] slice = str[]; assert(slice.length == str.length); assert(slice.ptr is str.ptr); assert(slice == "123"); }();
Return slice of all character.
The slice returned may be invalidated by further calls to other member functions that modify the object.