std.sumtype?

jmh530 john.michael.hall at gmail.com
Tue Mar 23 00:16:16 UTC 2021


On Monday, 22 March 2021 at 23:25:07 UTC, Paul Backus wrote:
> [snip]
>
> Not sure what `BaseTypeOf` is supposed to do here, but if you 
> want to extract a particular type from a SumType it's pretty 
> easy:
>
> Target to(Target, Source)(Source source)
>     if (isSumType!Source && staticIndexOf!(Target, 
> Source.Types) >= 0)
> {
>     // Will throw MatchException if the wrong type is found
>     return source.tryMatch!((Target target) => target));
> }

I was BaseTypeofOf!Temperature would be returning Fahrenheit in 
that case. But yes, this looks like it would do what I was 
thinking.


More information about the Digitalmars-d mailing list