Meta:

Nullable will work in this case, but it doesn't solve the general problem with Algebraic.

Then is this an acceptable solution?


import std.variant;

struct None {}

template Option(T) {
    alias Option = Algebraic!(T, None);
}

Option!int unreliable(int val) pure nothrow {
    if (val == 0) {
        return typeof(return)(None());
    } else {
        return typeof(return)(val);
    }
}

void main() {}


Bye,
bearophile

Reply via email to