Making castSwitch pure
StarCanopy
starcanopy at protonmail.com
Tue Sep 6 02:08:42 UTC 2022
Using
[castSwitch](https://dlang.org/phobos/std_algorithm_comparison.html#.castSwitch) for the first time, I was dismayed that it's an impure function template, even if every handler is pure. It seems that the reason for this is because the pertinent overload of TypeInfo.opEquals uses TypeInfo.toString, which is impure (for reasons of which I'm ignorant, since it overrides toString with const, @safe, and nothrow).
It's unfortunate one seemingly can't just replace the call to
opEquals with `typeid(a) is typeid(b)`, but opEqual's logic is
simple, and could just be replicated with toString invocations
replaced with TypeInfo.name.
Nonetheless, this increases fragility within castSwitch, and
possibly sets a bad precedent, so I doubt it would be accepted.
Any thoughts, however, for fixing this and similar problems? The
ProtoObject proposal seems dead, if that's relevant.
More information about the Digitalmars-d
mailing list