Re: SumType extraction

2024-06-28 Thread Josh Holtrop via Digitalmars-d-learn
On Friday, 28 June 2024 at 22:25:40 UTC, drug007 wrote: Both yes and no, you check the type once, but then check for null, so a double check is performed nonetheless. But for me it's a minor difference. There are two common ways to handle sumtypes: using either an explicit type tag or implici

Re: SumType extraction

2024-06-28 Thread drug007 via Digitalmars-d-learn
On 28.06.2024 15:43, Josh Holtrop wrote: On Friday, 28 June 2024 at 10:52:01 UTC, drug007 wrote: Nothing prevents that, and indeed I still plan to use item.match! like that when I need to handle multiple/all types. I just wanted the get! functionality when I only expect or want to handle one t

Re: SumType extraction

2024-06-28 Thread Josh Holtrop via Digitalmars-d-learn
On Friday, 28 June 2024 at 10:52:01 UTC, drug007 wrote: 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;

Re: SumType extraction

2024-06-28 Thread drug007 via Digitalmars-d-learn
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) { /