Re: D move semantics

2017-07-30 Thread Moritz Maxeiner via Digitalmars-d-learn
On Sunday, 30 July 2017 at 16:12:41 UTC, piotrekg2 wrote: What is the idiomatic D code equivalent to this c++ code? There's no direct equivalent of all your code to D using only druntime+phobos AFAIK. class Block { [...] }; Since you don't seem to be using reference type semantics or

D move semantics

2017-07-30 Thread piotrekg2 via Digitalmars-d-learn
What is the idiomatic D code equivalent to this c++ code? class Block { public: Block() : data_(new char[4096]) {} ... // NOTE: both members marked noexcept Block(Block &) noexcept = default; Block& operator=(Block &) noexcept = default; ... private: std::unique_ptr

Re: How do you append to a dynamic array using move semantics?

2016-03-23 Thread cy via Digitalmars-d-learn
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.

Re: How do you append to a dynamic array using move semantics?

2016-03-23 Thread ag0aep6g via Digitalmars-d-learn
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,

Re: How do you append to a dynamic array using move semantics?

2016-03-23 Thread ag0aep6g via Digitalmars-d-learn
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]);`.

How do you append to a dynamic array using move semantics?

2016-03-23 Thread cy via Digitalmars-d-learn
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));

Move Semantics

2015-09-29 Thread Alex via Digitalmars-d-learn
Another question on move semantics from the cheap seats... See my code here: http://dpaste.dzfl.pl/995c5af59dd6 There are indeed three questions, all marked in the code, so the rest of the text here is maybe redundant... but just in case and for summary: I try to model a inner class of some

Re: Move Semantics

2015-09-29 Thread Alex via Digitalmars-d-learn
Thank you very much for the comments. It is much clearer now. The .outer link is just a shortcut, which does not mean I don't have to reset it, where I have to. So... essentially, my expectation WAS to subjective and I have to separate better, what is the part of the model in my head and what

Re: Move Semantics

2015-09-29 Thread anonymous via Digitalmars-d-learn
On Tuesday 29 September 2015 16:38, Alex wrote: > Another question on move semantics from the cheap seats... > > See my code here: http://dpaste.dzfl.pl/995c5af59dd6 [...] > The first (minor) question is: > I have to initialize some dummy inner objects, before I can apply &g

Re: Move Semantics

2015-09-29 Thread Ali Çehreli via Digitalmars-d-learn
On 09/29/2015 07:38 AM, Alex wrote: > See my code here: http://dpaste.dzfl.pl/995c5af59dd6 > Following my code, the inner object I moved does not disappear from the > array in the source outer object. Why? > After I moved the inner object to the new outer object, the pointer to > the outer