https://issues.dlang.org/show_bug.cgi?id=15662
--- Comment #8 from Kenji Hara <[email protected]> --- (In reply to Dicebot from comment #6) > No objections here. Question is - how to implement it inside a library > (without modifying compiler) if this array.length loophole is closed? Only > thing that comes to my mind is to reinterpret cast it to array of > `ubyte[T.sizeof]` and do manual blit copy but that feels very error-prone. It would need some @trusted code and runtime check, because currently there's not enough compile-time information to guarantee its safety. My quick implementation: void moveAppend(T)(ref T[] arr, T elem) { if (!arr.capacity) throw new Error("cannot append"); swap(*(arr.ptr + arr.length), elem); arr = arr.ptr[0 .. arr.length + 1]; // *uninitialize* elem, as same as std.algorithm.move memcpy(&elem, typeid(T).initializer().ptr, sz); } --
