1

How to iterate over enums ?

It is donot work

enum Bool : int { no = 0, yes }
Bool boll;
foraech( e, bool){
    writeln(e);
}
1
  • I don't know "d", but is that a typo on your second line, should boll be bool?
    – Flexicoder
    Commented Mar 22, 2014 at 11:33

1 Answer 1

10

There are so many mistakes within your code, so I just give you a code that works:

import std.stdio;
import std.traits;

void main() {
    enum Bool { no = 0, yes }
    foreach (e; [EnumMembers!Bool]) {
        writeln(e);
    }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.