[Issue 15662] Cannot move struct with defined opAssign due to @disabled post-blit

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Thu Feb 18 04:44:45 PST 2016


https://issues.dlang.org/show_bug.cgi?id=15662

--- Comment #9 from Dicebot <public at dicebot.lv> ---
(In reply to Kenji Hara from comment #8)
> 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);
> }

Yes, this is close to what I had in mind (main difference is that I need
re-allocation to be allowed too, invalidating previous block, but that is also
trivially doable).

The problem I see with such approach is usual type erasure druntime often
suffers from. Requiring same qualifiers for array elements and appended one is
overly limited but relaxing it means the functions needs to reimplement all the
implicit conversion checks compiler already does.

--


More information about the Digitalmars-d-bugs mailing list