How to print current type of a SumType?
Chris Piker
chris at hoopjump.com
Sun Oct 1 02:18:32 UTC 2023
On Sunday, 1 October 2023 at 01:17:50 UTC, Chris Piker wrote:
> ```d
> alias Vec3 = SumType!(void* /* invalid vector */, byte[3],
> short[3], char[][3]);
>
> ```
I know it's bad form to reply to my own question, but I think I
found a reasonably simple way:
```d
string prnType(Vec3 vec){
return vec.match!( t => typeof(t).stringof);
}
```
which is hardly worth making into a function of it's own. Other
suggestions are welcome of course.
SumTypes are really tripping me up. Unlearning years of writing
C takes more time then I'd prefer.
More information about the Digitalmars-d-learn
mailing list