TypedPtr

Undocumented in source.
alias TypedPtr = TypedPtrBase!()

Examples

static struct S
{
    int value;
}

auto ptr = S(200).makeTyped;
assert(!ptr.isNull);
assert(ptr.contains!S);
assert(ptr.ptrUnsafeAs!S.value == 200);
ptr.access!S((scope ref s)
{
    s.value *= 2;
});
assert(ptr.ptrUnsafeAs!S.value == 400);
ptr = S(100);
assert(ptr.ptrUnsafeAs!S.value == 100);

// opAssign cannot change types.
// bool threw = false;
// try ptr = 200;
// catch(Error error)
//     threw = true;
// assert(threw);

// But setForce can
ptr.setByForce(200);
assert(ptr.contains!int);
assert(*ptr.ptrUnsafeAs!int == 200);

ptr = null;
assert(ptr.isNull);

Meta