https://issues.dlang.org/show_bug.cgi?id=8845

--- Comment #21 from Nick Treleaven <n...@geany.org> ---
I came up with a lvalueOf!rvalue template which hopefully is memory-safe. Not
tested with Walter's DIP1000 scope branch (yet).

enum typeof(v[0])[v.length] staticArray(v...) = [v];

ref const(T) lvalueOf(alias rvalue, T=typeof(rvalue))
    (return ref T rv = *staticArray!rvalue.ptr) @trusted
{
    return rv;
}

auto foo(ref const int i) {assert(i == -1);}

@safe @nogc unittest
{
    static assert(!__traits(compiles, foo(0-1)));
    foo(lvalueOf!(0-1));
}

--

Reply via email to