std.sumtype?

Schrom, Brian T Brian.Schrom at pnnl.gov
Mon Mar 29 19:20:49 UTC 2021


On Mon, Mar 29, 2021 at 11:41:39AM -0400, Steven Schveighoffer via Digitalmars-d wrote:
> Check twice before you click! This email originated from outside PNNL.
> 
> 

>From beerconf this weekend, I think I got a little bit of clarity on
the reluctance to return the tag/index.  E.g. it's an implementation
detail and shouldn't be accessible.

If I understand correctly, SumType matches on Type and not on the Tag part.  The tag part
happens to be a needed implementation detail since there isn't RTTI.  The
big distinction between a "tagged union" and this SumType is that a 
tagged union can have multiple tags with the same underlying type 
and dispatch happens on tag, so they can be distinguished.  Whereas,
this SumType dispatches on Type, so can only have distinct types.  I
guess there is a caveat that const sort of differentiates as
separate, but don't think that is really part of the abstract
concept.

If there are better terms to differentiate these two concepts, I'm
interested in adding them to my vocabulary.


More information about the Digitalmars-d mailing list