rvalue based copy
anonymous via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Mon Mar 30 10:25:38 PDT 2015
On Monday, 30 March 2015 at 17:21:53 UTC, Steven Schveighoffer
wrote:
> One solution is to overload
>
> void opAssign(ref const S s) {...}
> void opAssign(const S s) {...}
>
> lvalues will go into the ref version, rvalues into the non-ref.
> There won't be any copying of data, so you still save a
> postblit and copying on the stack.
>
> But you have to repeat the implementation.
You can call the ref version from the non-ref version:
void opAssign(ref const S s) {...}
void opAssign(const S s) {opAssign(s); /* calls the ref version
*/}
Of course, only do this when the ref version doesn't store &s.
More information about the Digitalmars-d-learn
mailing list