ref struct?

Mafi mafi at example.org
Tue Oct 11 08:01:28 PDT 2011


Am 09.10.2011 19:52, schrieb bearophile:
> (I show this here because it's probably a silly idea, but it may a chance to learn something.)
> Do you like the idea of a POD that is always managed by reference, as class instances?
>
>
> ref struct Foo {}
> static assert(Foo.sizeof == 1);
> void main() {
>      Foo f1; // void reference
>      Foo f2 = new Foo; // by reference
> }
>
>
> It is as light as a struct, but you don't need to use the pointer syntax to manage a Foo instance, the code is cleaner. There is no info field inside a ref struct, so in some situations the destructor doesn't get called, like regular structs.
>
> Bye,
> bearophile

What about:

struct FooData {...}
alias FooData* Foo;

//dot syntax etc works like you want
//only problem: (new FooData) instead of (new Foo)


More information about the Digitalmars-d-learn mailing list