Following function will return the reference to a object Foo
embedded in a Variant.
class Foo {}
Variant fun() {
Variant v;
v = new Foo();
return v;
}
According to the source code of VariantN.opAssign,
the assignment is done by:
memcpy(&store, &rhs, rhs.sizeof);
fptr = &handler!(T);
where rhs is new Foo(), store is embedded storage in Variant,
and fptr is accessor function also work as data tag.
Very efficient implementation.
But wait, how does GC detect there still be a live reference to
the object Foo?
Because store is just a fix sized array of bytes.
ubyte[size] store;
GC cannot be aware of the reference, right?
Thanks, aki