ref locals

Manu turkeyman at gmail.com
Wed Aug 14 14:26:34 UTC 2024


This is kinda rhetorical, since I've asked this a million times, and we all
know the answer... but seriously; why can't we declare ref locals?

Lots of functions return a ref; and we need to capture the result of those
functions appropriately.

ref T f();

void t()
{
  ref T result = f();  // <-- there's no good reason to reject this
}

I don't understand why this doesn't come up every few days, everytime a new
user appears. Is this really okay? Why does this make me feel so
frustrated, but nobody else seems to care?

... "Use a pointer!" ...

void t()
{
  T* result_ptr = &f();  // seriously?
}

I feel embarrassed by this suggestion, why don't you feel embarrassed by
this suggestion?
It's also pretty shit that taking a pointer of a function's result like
that is not compatible with ufcs, where it instead attempts to create a
function pointer.

It gets worse when the function is property-like.

void t()
{
  T* prop_ptr = &myThing.prop;
}

error: cannot implicitly convert expression `& f` of type `T delegate()
ref` to `T*`

A new D user will look at that and think it's stupid... at least; I look at
that and I think it's stupid!
ref locals already please, this has gone on long enough!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20240815/d105ecac/attachment-0001.htm>


More information about the Digitalmars-d mailing list