SumType extraction

drug007 drug2004 at bk.ru
Fri Jun 28 22:25:40 UTC 2024


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 type without all 
> the additional pattern matching syntax.
> 
> But, I think my:
> 
> ```d
>      if (Foo foo = item.get!Foo)
>      {
>          /* do something with foo */
>      }
> ```
> 
> is still only checking the type once due to the one call to match! in 
> get!, right?

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 implicit type handling. Both have their pros and cons. As I 
know (can be wrong) std.sumtype implies type handlers not type tags.


More information about the Digitalmars-d-learn mailing list