You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm reading optional.d of the current master 9940ac3. I'm wondering about this code here, starting in line 136:
void opAssign()(const None) if (isMutable!T) {
if (!this.empty) {
destroy(this._value);
this._empty = true;
}
}
Why is the call to destroy here when T is a class? When I reassign one of the references (such as this Optional!T) to a given class object, I usually don't need to destroy the GC-ed class. It can even be harmful if there are other references to the same object:
#!/usr/bin/rdmd
import std.stdio;
import optional;
class C {
int i;
this(int ai) { i = ai; }
}
void main()
{
C my = new C(3);
Optional!C opt = some(my);
writeln(my.i); // prints 3
opt = none;
writeln(my.i); // prints 0, but should print 3
}
Should this code print 0 or 3?
The text was updated successfully, but these errors were encountered:
I'm reading
optional.d
of the current master 9940ac3. I'm wondering about this code here, starting in line 136:Why is the call to destroy here when
T
is a class? When I reassign one of the references (such as thisOptional!T
) to a given class object, I usually don't need to destroy the GC-ed class. It can even be harmful if there are other references to the same object:Should this code print
0
or3
?The text was updated successfully, but these errors were encountered: