EnumText

Builds and enum string out of a string array

template EnumText (
string name
string[] list
bool first = true
) {
static if(first)
enum begin;
static if(!(first))
static if(list.length > 0)
enum k;
static if(!(first))
static if(list.length > 0)
enum code;
static if(!(first))
static if(!(list.length > 0))
enum code;
}

Examples

enum list = ["red", "green", "blue"];
mixin(EnumText!("Colour", list));
static assert(Colour.red == list[0]);
static assert(Colour.green == list[1]);
static assert(Colour.blue == list[2]);