On 12/11/2018 4:51 AM, Nicholas Wilson wrote:
> Returning a reference
Wow, thats f*ck'n stupid! https://run.dlang.io/is/SAplYw

It's quite deliberate.

ref in C++ is a type constructor, but it's so special-cased to behave like a storage class, it might as well be one. In D it is.

(For example, ref in C++ can only appear at the top level. There are no "pointers to refs".)

refs exist so the lifetime of them can be controlled for memory safety. Treating them as flexibly as pointers would make that pretty difficult. refs are the primary way a memory safe container can expose pointers to its contents.

Reply via email to