Is there a simple way to convert C++ enum to string?

后端 未结 30 2764
我在风中等你
我在风中等你 2020-11-22 10:37

Suppose we have some named enums:

enum MyEnum {
      FOO,
      BAR = 0x50
};

What I googled for is a script (any language) that scans all

30条回答
  •  再見小時候
    2020-11-22 11:09

    @hydroo: Without the extra file:

    #define SOME_ENUM(DO) \
        DO(Foo) \
        DO(Bar) \
        DO(Baz)
    
    #define MAKE_ENUM(VAR) VAR,
    enum MetaSyntacticVariable{
        SOME_ENUM(MAKE_ENUM)
    };
    
    #define MAKE_STRINGS(VAR) #VAR,
    const char* const MetaSyntacticVariableNames[] = {
        SOME_ENUM(MAKE_STRINGS)
    };
    

提交回复
热议问题