On Monday, 30 March 2015 at 17:14:27 UTC, Adam D. Ruppe wrote:
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.

Yes but you know what they say does it really do a copy of the struct or is the compiler smart enougth most of the time to avoid copy. (I think it's called return value optimization).

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)
    {
        //...
    }

Why is this only restricted to templates ?

Reply via email to