Feature to get or add value to an associative array.
Steven Schveighoffer
schveiguy at yahoo.com
Fri Apr 20 14:02:17 UTC 2018
On 4/20/18 4:24 AM, Nick Treleaven wrote:
> On Wednesday, 18 April 2018 at 16:47:50 UTC, ag0aep6g wrote:
>> You can get a pointer from the ref return:
>>
>> Value* p = &aa.slot("key", { inserted = true; return Value.init; });
>
> This is not @safe, even with -dip1000:
>
> Error: cannot take address of ref return of f() in @safe function main
Hm... I would have expected it to work in dip1000.
Hard for me to understand what dip1000 is doing, but it seems like an
omission:
@safe ref int foo(return ref int x) { return x; }
void main() @safe
{
int x;
scope int *xp = &x; // OK with dip1000
xp = foo(x); // Error, even though it's exactly the same
}
And in this case, it doesn't even need to be scope, as it's GC data. How
does one communicate that the ref return is of GC data and can be
escaped as much as you want?
-Steve
More information about the Digitalmars-d
mailing list