On Friday, 20 July 2018 at 10:08:03 UTC, Dgame wrote:
On Friday, 20 July 2018 at 09:39:47 UTC, Nicholas Wilson wrote:
On Friday, 20 July 2018 at 09:03:18 UTC, Dukc wrote:
appending something (like .byRef or byRef!long, the latter making an implicit type conversion)

That can't work: either it returns an expired stack temporary (*very* bad), or allocates with no way to deallocate (bad).

What about something like this?

----
import std.stdio;

ref T byRef(T)(T value) {
    static T _val = void;
    _val = value;

    return _val;
}

void foo(ref int a) {
    writeln("A = ", a);
}

void main() {
    foo(42.byRef);
    foo(23.byRef);
}
----

Perhaps semantically correct, but practically a non-starter, due to the performance implications of loading and storing to thread-local storage and by extension the severe impact on compiler optimizations. And also syntactically ugly, even if you shorten it to something like `1.r`.

Anyway, I think the DIP is the best way forward - just remove the stupid and unnecessary restriction.

Reply via email to