Domanda

How to iterate over enums ?

It is donot work

enum Bool : int { no = 0, yes }
Bool boll;
foraech( e, bool){
    writeln(e);
}
È stato utile?

Soluzione

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);
    }
}
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top