parallel101 / course

高性能并行编程与优化 - 课件
https://space.bilibili.com/263032155
Other
3.62k stars 532 forks source link

获取枚举名代码不适用于clang+msvc #21

Open weypro opened 1 year ago

weypro commented 1 year ago

以下代码不适用于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