course
course copied to clipboard
获取枚举名代码不适用于clang+msvc
以下代码不适用于clang15+msvc(vs2022)的情形
#if defined(_MSC_VER)
size_t pos = s.find(',');
pos += 1;
size_t pos2 = s.find('>', pos);
#else
在执行这一段前,s的值为:"const char *__cdecl 函数名 [T = 枚举, N = 枚举::枚举常量]"
我现在改为以下代码可以正常使用:
#if defined(_MSC_VER) && !defined(__clang__)
size_t pos = s.find(',');
pos += 1;
size_t pos2 = s.find('>', pos);
#elif defined(__clang__)
size_t pos = s.find("N = ");
pos += 1;
size_t pos2 = s.find(']', pos);
#else
size_t pos = s.find("N = ");
pos += 4;
size_t pos2 = s.find_first_of(";]", pos);
#endif