// Collection of code snippets by Arne Vajhøj 
// (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) 
#include <iostream>
#include <string>
#include <cstring>

using namespace std;

string EnumName(int v, char *names)
{
    string res = "";
    int n = 0;
    for(int i = 0; i < strlen(names); i++) 
    {
        if(names[i]==',')
        {
            n++;
        }
        else
        {
            if(n==v) res += names[i];
        }
    }
    return res;
}

#define ENUM(name,...) \
enum name##Enum { __VA_ARGS__ }; \
string name##Name(name##Enum v) { return EnumName((int)v, #__VA_ARGS__); };

ENUM(Some,test1,test2)
ENUM(Another,a,b,c,d,e,f)

int main()
{
    SomeEnum e;
    e = test1;
    cout << e << " " << SomeName(e) << endl;
    e = test2;
    cout << e << " " << SomeName(e) << endl;
    AnotherEnum e2;
    e2 = d;
    cout << e2 << " " << AnotherName(e2) << endl;
    return 0;
}
