www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - How do you append to a dynamic array using move semantics?

reply cy <dlang verge.info.tm> writes:
struct Thing {
    disable this(this);
}
...
items ~= move(item); // Error: struct Thing is not copyable 
because it is annotated with  disable

++items.length
move(items[$-1],item); // Error: struct Thing is not copyable 
because it is annotated with  disable

appender(items).put(move(item)); // Error: template 
std.array.Appender!(Thing[]).Appender.put cannot deduce function 
from argument types !()(Thing)

...?
Mar 23 2016
parent reply ag0aep6g <anonymous example.com> writes:
On 24.03.2016 00:26, cy wrote:
 ++items.length
 move(items[$-1],item); // Error: struct Thing is not copyable because it
 is annotated with  disable
You got the order of arguments wrong here. Source goes first, target second. Works for me with `move(item, items[$-1]);`.
Mar 23 2016
next sibling parent ag0aep6g <anonymous example.com> writes:
On 24.03.2016 00:44, ag0aep6g wrote:
 On 24.03.2016 00:26, cy wrote:
 ++items.length
 move(items[$-1],item); // Error: struct Thing is not copyable because it
 is annotated with  disable
You got the order of arguments wrong here. Source goes first, target second. Works for me with `move(item, items[$-1]);`.
Though it should compile the other way around, too. And it does for me.
Mar 23 2016
prev sibling parent cy <dlang verge.info.tm> writes:
On Wednesday, 23 March 2016 at 23:44:55 UTC, ag0aep6g wrote:
 You got the order of arguments wrong here. Source goes first,
Oh, derp. Thanks. Right then... it works as expected.
Mar 23 2016