weak_ptr alternative
Kamil Koczurek
koczurekk at gmail.com
Sun Aug 5 20:10:49 UTC 2018
Is there a way to keep track of objects without owning them? That
is, could I have a smart pointer that behaves somewhat like this:
WeakPtr!Class wptr = getSomeInstance();
auto obj = wptr.peek; //[1]
if(obj !is null) {
obj.stuff();
}
[1]: If wptr points to something that is still reachable from
somewhere else (and wasn't yet marked for collection by GC),
.peek would return a normal reference of type Class. OTOH, when
no active reference is present it should return null.
More information about the Digitalmars-d-learn
mailing list