Blog Post: Beating std::visit Without Really Trying

Paul Backus snarwin at gmail.com
Mon Oct 7 01:38:04 UTC 2019


On Monday, 7 October 2019 at 01:09:34 UTC, Andrei Alexandrescu 
wrote:
> Well also in the case of SumType there's not even much 
> battle-testing. It's more of an implementation than a design. 
> Take the existing variant, keep the interface, remove the 
> cruft, put in the new nice code. Make it pass the unittests, 
> and release. Of course it's an involved process, but definitely 
> not more difficult than writing the new code to start with. The 
> author receives credit as the primary author of the facility. 
> It is wonderful service to the community - not only offers 
> better speed for new code, but it instantly enhances speed of 
> existing variant uses.

Just to clarify: SumType isn't, and was never intended to be, a 
drop-in replacement for Algebraic. Their interfaces are similar 
enough that porting code from Algebraic to SumType shouldn't be 
too difficult, but even within the common subset, there are 
incompatibilities. For example, here's a post from an old sumtype 
announcement thread where I discuss the differences between 
SumType's `match` and Algebraic's `visit`:

https://forum.dlang.org/post/xipgrrfljdnyhrhnmsij@forum.dlang.org

If SumType is ever added to Phobos, it will have to be alongside 
Algebraic, as an alternative, not as a replacement.


More information about the Digitalmars-d-announce mailing list