digitalmars.D - Making castSwitch pure
- StarCanopy (10/10) Sep 05 2022 Using
Using [castSwitch](https://dlang.org/phobos/std_algorithm_comparis 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.
Sep 05 2022