Discussion: Rvalue refs and a Move construtor for D
Suleyman
sahmi.soulaimane at gmail.com
Thu Sep 5 17:53:29 UTC 2019
On Thursday, 5 September 2019 at 15:49:37 UTC, kinke wrote:
> [...]
>
> void main()
> {
> auto s = S(_1GB);
> // does NOT call move ctor, just passes `s` by ref directly
> instead of a moved-to
> // temporary
> bar(__move(s));
> // after the call, destruct `s` and reset to T.init
That sounds like an optional optimization for the compiler.
That's if the compiler finds that s is never used after the call
to bar.
> assert(s.length == 0); // s is still usable
> // this now does call the move ctor:
> auto s2 = __move(s);
> } // `s` goes out of scope and is destructed again
Calling the destructor twice is not more efficient than one call
to the move constructor and one call to the destructor.
More information about the Digitalmars-d
mailing list