UDAs on enum members

Chris Wright via Digitalmars-d digitalmars-d at puremagic.com
Wed Jul 13 05:40:50 PDT 2016


On Wed, 13 Jul 2016 11:57:21 +0000, Tomer Filiba wrote:
> And while we're on the subject, why can't enums have methods?

Why not use a free function?

import std.stdio;
enum Foo { bar, baz }

void print(Foo f) {
  final switch(f) {
    case Foo.bar:
      writeln("bar");
      break;
    case Foo.baz:
      writeln("baz");
      break;
  }
}

void main() {
  Foo.bar.print();
}

> At the
> risk of sounding as if I like Java (I don't :) ), it's a really nice
> language feature.

Nothing wrong with liking things from Java.


More information about the Digitalmars-d mailing list