D doesn't have weak references. So how can I make a associative array of objects without preventing their destruction?
Dukc
ajieskola at gmail.com
Fri May 10 13:27:40 UTC 2024
Steven Schveighoffer kirjoitti 10.5.2024 klo 16.01:
> On Friday, 10 May 2024 at 11:05:28 UTC, Dukc wrote:
>> This also gets inferred as `pure` - meaning that if you use it twice
>> for the same `WeakRef`, the compiler may reuse the result of the first
>> dereference for the second call, without checking whether the referred
>> value has changed!
>
> This would be weak pure since the reference is mutable. This cannot be
> memoized.
The difference is the type. With a pointer parameter (both a bare one
and one in a struct), the compiler can cache the result only when the
pointed data is similar. However, here we have an integer parameter. It
can be cached if it itself is similar to the one in the other function
call. The compiler doesn't have to know, nor can know, when a `size_t`
is a pointer in disguise.
More information about the Digitalmars-d-learn
mailing list