Why is std.variant bad?
Paul Backus
snarwin at gmail.com
Sat Sep 20 03:01:55 UTC 2025
On Saturday, 20 September 2025 at 01:46:47 UTC, monkyyy wrote:
> This was before my time. I was under the impression that it was
> somehow class and oo related badness when people talked about
> using TypeInfo; but when I my own experiments say that typeinfo
> is just another tool
>
> I see 3k lines of code compared to my 50; Im going to say its
> but the postmorden seems wrong.
>
> my code:
> https://gist.github.com/crazymonkyyy/14e36a99dd307c5d6e37bdb3ca2524a7
IMO there isn't really anything wrong with `Variant`. Given what
it's trying to do, using `TypeInfo` or something similar is
pretty much unavoidable. (Technically, `Variant` uses its own
custom form of RTTI that's more lightweight than `TypeInfo`, but
it still requires an extra level of indirection at runtime.)
The problem is with `Algebraic`, which uses RTTI even when all of
the types are known at compile time--totally unnecessary.
More information about the Digitalmars-d-learn
mailing list