Blog post: What D got wrong
Walter Bright
newshound2 at digitalmars.com
Wed Dec 12 07:44:12 UTC 2018
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.
More information about the Digitalmars-d-announce
mailing list