SumType extraction

drug007 drug2004 at bk.ru
Fri Jun 28 10:52:01 UTC 2024


What prevents you from doing:
```D
import std.sumtype;

class Foo {}
class Bar {}

alias Item = SumType!(Foo, Bar);

void main()
{
     Item[] items = [Item(new Foo()), Item(new Bar()), Item(new Foo()), 
Item(new Bar())];
     foreach (item; items)
     {
         item.match!(
             (Foo v) { /* do something with foo */ },
             (_) {}
         );
     }
}
```
?
It's more effective by the way - you check the type once only.


More information about the Digitalmars-d-learn mailing list