On Thursday, 7 May 2020 at 15:36:36 UTC, Ben Jones wrote:
On Thursday, 7 May 2020 at 14:53:10 UTC, Steven Schveighoffer
wrote:
As others have recommended, I suggest using TaggedAlgebraic. I
recently have been using it to create an algebraic type to
hold a MYSQL value, so I can migrate the mysql-native library
to be @safe (mysql-native currently uses Variant for
everything).
-Steve
I've been using SumType... What are the main differences
between it and TaggedAlgebraic?
As far as I can tell, there are two main differences:
1. TaggedAlgebraic has some convenient operator overloads that
can assert at runtime if called improperly (i.e., when the
contained type does not support the operation). SumType never
asserts at runtime, and instead requires you to use `match` for
these operations to ensure that they are only performed on the
appropriate types.
2. TaggedAlgebraic requires you to declare a union type as a
"base", whereas SumType takes the list of member types directly
as template arguments.
If you want more detailed information, both have online
documentation:
TaggedAlgebraic:
https://vibed.org/api/taggedalgebraic.taggedalgebraic/
SumType: https://pbackus.github.io/sumtype/sumtype.html