Justin Whear:

In addition to the suggestions of Algebraic or Variant elsewhere in this thread, it's trivial to implement your own concrete tagged unions:

struct MyTaggedUnion
{
   enum Type { Int, Float, String }
   Type tag;

   union {
      int int_;
      float float_;
      string string_;
   }
}

You can also hide the union members with private and only allow access
via property getters that check the tag.

See for a bare-bones built-in pattern matching, with an optional "opMatch" struct method that gets called by the improved switch:
https://d.puremagic.com/issues/show_bug.cgi?id=596

Bye,
bearophile

Reply via email to