Re: [Discussion] Usefulness of Algebraic?

2016-02-13 Thread Sönke Ludwig via Digitalmars-d
For reference, the TaggedAlgebraic struct that I wrote some time ago supports this: https://github.com/s-ludwig/taggedalgebraic You could do something similar to this: struct Option(T) { struct Kinds(T) { typeof(null) none; T some; } TaggedAlgebraic!Kinds data; alias data this;

[Discussion] Usefulness of Algebraic?

2016-02-13 Thread maik klein via Digitalmars-d
struct Some(T){ T value; } struct None{} struct Option(T){ alias OptionAdt(T) = Algebraic!(Some!T, None); OptionAdt!T value; //Should default to none //OptionAdt!T value = OptionAdt!T(None()); /* Error: memcpy cannot be interpreted at compile time, because it has no