Safely moving structs in D
bitwise via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Wed Jan 25 12:53:09 PST 2017
On Tuesday, 24 January 2017 at 11:46:47 UTC, Jonathan M Davis
wrote:
> On Monday, January 23, 2017 22:26:58 bitwise via
> Digitalmars-d-learn wrote:
>> [...]
>
> Moving structs is fine. The postblit constructor is for when
> they're copied. A copy is unnecessary if the original isn't
> around anymore - e.g. passing an rvalue to a function can move
> the value; it doesn't need to copy it. Even passing an lvalue
> doesn't need to result in a copy if the lvalue is not
> referenced at any point after that function call. However, if
> you're going to end up with two distinct copies, then they need
> to actually be copies, and a postblit constructor will be
> called.
>
> [...]
Awesome, thanks - this makes sense.
More information about the Digitalmars-d-learn
mailing list