std.sumtype?

Oleg B code.viator at gmail.com
Mon Aug 30 10:20:20 UTC 2021


On Sunday, 29 August 2021 at 17:49:05 UTC, Paul Backus wrote:
> `staticIndexOf` returns `-1` when the type is not found, and 
> `255` is what you get when you cast `-1` to `ubyte`.

Yes, I understand, but it wasn't problem.

> Note that this version has [the problem you complained about 
> before][1] where it does not distinguish between the `int[]` 
> and the `const(int[])` members of a `const(SumType!(int[], 
> const(int[])))`. This is unavoidable--`match` itself is not 
> capable of distinguishing between those members, so anything 
> that uses `match` will also fail to do so.
>
> If this is still a problem for you, you can strip off the 
> qualifier from the `SumType` before calling `typeIndex`:
>
> ```d
>         return cast(TaggedTagType!(T))((cast(Unqual!T) 
> val).typeIndex);
> ```

No problem with `typeIndex`, but `std.sumtype` have no 
`typeIndex`.

If I understand correctly problem must resolve by removing 
`const` before `match`.

Is this code will be correct?

```d
auto typeIndex(T)(in T val) if (is(T == SumType!Args, Args...))
{
   return match!(v => staticIndexOf!(typeof(v), 
T.Types))(*(cast(T*)&val));
}
```

In what cases I get different result between your version with 
`CopyTypeQualifiers` and my?




More information about the Digitalmars-d mailing list