Feature to get or add value to an associative array.
Steven Schveighoffer
schveiguy at yahoo.com
Fri Apr 20 15:00:39 UTC 2018
On 4/20/18 10:34 AM, Uknown wrote:
> On Friday, 20 April 2018 at 14:02:17 UTC, Steven Schveighoffer wrote:
>> 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?
>>
>
> The error seems to be about type mismatching, it works if you use auto.
> I don't see how you could convert the `ref int` to `int *`
> https://run.dlang.io/is/eIJMIK
Sorry, it was a typo. In my real code I have:
xp = &(foo(x));
That's what I get for hand-typing instead of copy-pasting :)
-Steve
More information about the Digitalmars-d
mailing list