std.sumtype?

Nick Treleaven nick at geany.org
Wed Mar 31 17:41:51 UTC 2021


On Tuesday, 23 March 2021 at 16:29:52 UTC, Steven Schveighoffer 
wrote:
> Consider an assert that validates a SumType is a certain type:
>
> SumType!(string, float, int) someType;
> ...
> someType.match!((T t) {assert(is(T == int)); });
>
> vs.
>
> assert(someType.typeIndex == 2);

How about e.g.:

assert(someType.has!int);

int i = someType.unwrap!int; // asserts has!int


More information about the Digitalmars-d mailing list