On Tuesday, 24 February 2026 at 22:10:08 UTC, Kapendev wrote:
On Tuesday, 24 February 2026 at 21:56:47 UTC, monkyyy wrote:
[...]

```d
// Tagged union.
struct Base { int x, y, w, h; ubyte type; }
struct Foo { Base base; int hp; }
struct Goo { Base base; string name; }
union Entity1 { Base base; Foo foo; Goo goo; }

// MEGA struct.
struct Entity2 {
    int x, y, w, h;
    int hp;
    string name;
    ubyte type;
}

void main() {
    auto e1 = Entity1();
e1.base.x += 1; // Can just do that without checking or void magic.
    auto e2 = Entity2();
    e2.x += 2;      // It's the same thing.

    import std.stdio;
    writeln("Entity1 size: ", e1.sizeof);
    writeln("Entity2 size: ", e2.sizeof);
}
```

Thats a compromise between fat structs and components, everywhere you have base it acts fat

Reply via email to