On Wednesday, 8 August 2018 at 20:54:13 UTC, Paul Backus wrote:
SumType is a generic sum type for modern D. It is meant as an
alternative to `std.variant.Algebraic`.
Features:
- Pattern matching, including support for structural matching
(*)
- Self-referential types, using `This`
- Works with `pure`, `@safe`, `@nogc`, and `immutable` (*)
- Zero runtime overhead compared to hand-written C
- No heap allocation
- Does not rely on runtime type information (`TypeInfo`) (*)
Starred features (*) are those that are missing from
`Algebraic`.
Code examples are available in the documentation (linked below).
New since the last announced version, 0.3.0:
- Types with destructors and postblits are now handled
correctly.
- Unreachable handlers in `match` calls are now a
compile-time error.
- `match` handlers can now operate on the stored value by
reference.
- A new method, `tryMatch`, allows for non-exhaustive pattern
matching.
- Various small improvements to the documentation.
Documentation: https://pbackus.github.io/sumtype/sumtype.html
DUB: https://code.dlang.org/packages/sumtype
Github: https://github.com/pbackus/sumtype
Nice,
but destructor SumType.~this() can call destroy on reference type
like class:
bool destructed = false;
class C{
~this(){
destructed = true;
}
}
struct S{
~this(){
}
}
void main(){
auto c = new C;
{
auto st = SumType!(C, S)(c);
}
assert(destructed == true);
}