rvalue based copy

Adam D. Ruppe via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Mon Mar 30 10:14:26 PDT 2015


On Monday, 30 March 2015 at 17:09:14 UTC, matovitch wrote:
>(I am gessing ref argument explitly means no rvalue)

That's right. I'd first say don't use ref, just use "const S" and 
it will work and probably do what you need efficiently.

If you do want it to be ref though, rvalues aren't allowed unless 
you make it "auto ref" which needs to be a template:

// this will work, second set of () makes it a template
// then auto ref makes it use ref for lvalues and non-ref for 
rvalues
// automatially
     void opAssign()(const auto ref S s)
     {
         //...
     }


More information about the Digitalmars-d-learn mailing list