ref const(T) the same as C++'s const T&?

Lutger Blijdestijn lutger.blijdestijn at gmail.com
Tue Feb 15 14:47:36 PST 2011


Jonathan M Davis wrote:

...
> 
> Personally, it wouldn't hurt my feelings any to have const ref take
> temporaries. I do not understand why it's a problem. But Andrei insists
> that it is. Presumably Walter agrees, but I don't know. They could very
> well be right and that it's overall better _not_ to have const ref take
> temporaries, but it _is_ annoying. Since I don't understand what the real
> problem with not knowing whether const ref is actually referring to an
> lvalue or rvalue is, I can't really judge whether they're right or wrong.
> However, Andrei is certain that it's on of C++'s biggest mistakes.
> 
> Regardless, the general push has been that structs be cheap to copy, and I
> would argue that if you're structs _aren't_ relatively cheap to copy, you
> should at least consider rethinking your design. Sometimes COW or ref
> semantics will probably be required though.
> 
> There may be a way to solve this problem reasonably and still have const
> ref require lvalues, but for the moment, we have to deal with it.
> 
> - Jonathan M Davis

For reference, here is a link to the thread discussing it: http://www.mail-
archive.com/digitalmars-d at puremagic.com/msg44075.html

If I understood that discussion correctly, 'auto ref' is supposed to solve 
the rvalue references problem but are not completely implemented yet.


More information about the Digitalmars-d mailing list