What's wrong with std.variant.Variant?

Dukc ajieskola at gmail.com
Mon Jun 15 04:08:14 UTC 2020


On Sunday, 14 June 2020 at 18:04:57 UTC, Paul Backus wrote:
> FYI, SumType works with nothrow and @nogc, and can solve all of 
> your other problems with std.variant as well. :)
>
> Duplicate types are not supported out-of-the-box, but can very 
> easily be accomplished using `std.typecons.Typedef`:
>
>     alias InPixels = Typedef!(int[2], int[2].init, "InPixels");
>     alias InMeters = Typedef!(float[2], float[2].init, 
> "InMeters");
>     alias SourceSizes = Typedef!(float[2], float[2].init, 
> "SourceSizes");
>     alias PictureSize = SumType!(InPixels, InMeters, 
> SourceSizes);

Supporting all attributes definitely sounds good. OTOH your 
example isn't as DRY as with Taggedalgebraic:

```
alias PictureSize = TaggedUnion!PictureSize_;
union PictureSize_
{   int[2] inPixels;
     float[2] inMeters;
     float[2] inSourceSizes;
}
```

In essence, the problem is that I want an union with a 
customizable tag, not an afterwards defined "base class" for the 
types. I'd check Atila's library first for the latter. But I 
definitely could adapt `SumType` for my use with some extra 
wrapping.


More information about the Digitalmars-d mailing list