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;
  @property bool hasValue() const
    { return data.kind == TaggedAlgebraic!Kinds.Kind.some; }
}

void test()
{
  Option!int opt;
  assert(!opt.hasValue);
  opt = 12;
  assert(opt.hasValue);
  assert(opt == 12);
}

Reply via email to