How to print current type of a SumType?

Chris Piker chris at hoopjump.com
Sun Oct 1 01:17:50 UTC 2023


Hi D

I've a simple question but it's bedeviling me anyway.  How do I 
get a string representation of the current type of a SumType?  
I'm trying to avoid something like this:

```d
alias Vec3 = SumType!(void* /* invalid vector */, byte[3], 
short[3], char[][3]);

string prnType(Vec3 vec){

   return vec.match!(
      (void* _) => "void*",
      (byte[3] _) => "byte[3]",
      (short[3] _) => "short[3]",
      (char[][3] _) => "char[][3]"
   );
}
```

I'm sure there's a much easier way, especially once there's a 
largish number of vector types.

Thanks,



More information about the Digitalmars-d-learn mailing list