Destructors, const structs, and opEquals

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Sun Dec 5 06:18:13 PST 2010


On 12/5/10 12:04 AM, Steven Schveighoffer wrote:
> I'm totally confused. I thought the point of auto ref was to pass by
> value if it's an rvalue (since the data is already on the stack). If
> this is not the case, then why not just make ref work that way? Why
> wouldn't I mark all my functions as auto ref to avoid being pestered by
> the compiler?

Because you sometimes do care about dealing with a true lvalue. Consider:

void bump(ref int x) {
   ++x;
}

Then:

unsigned int y;
bump(y); // you don't want this to go through
short z;
bump(z); // you don't want this to go through
int w;
bump(w * 2); // you don't want this to go through


Andrei


More information about the Digitalmars-d mailing list