Pattern matching via switch?
Luhrel
lucien.perregaux at gmail.com
Sat Mar 14 20:54:41 UTC 2020
On Saturday, 14 March 2020 at 19:04:28 UTC, 12345swordy wrote:
> I.E.
>
> switch (object)
> case Type1 t1:
> case Type2 t2:
> case Type3 t3:
As far as I know, there's no way to do that in a switch.
However, you can do something like this:
---
void main()
{
auto i = new Type1();
foo(i);
}
void foo(T)(T type)
{
static if (is(T == Type1))
{
// ...
}
else static if (is(T == Type2))
{
// ...
}
// ...
}
---
Hope this helps
More information about the Digitalmars-d-learn
mailing list