有与__builtin__FUNCTION()等效的MSVC吗
Is there MSVC equivalent for __builtin__FUNCTION()?
根据这个答案,我们可以在GCC中使用__builtin__FUNCTION()
找到调用函数的名称。这方面有MSVC的等效方案吗?
std::source_location
将是未来的跨平台解决方案,允许您做:
void log(const std::string& message, const std::experimental::source_location& location = std::experimental::source_location::current())
{
std::cout << location.function_name() << ": " << message << "n";
}
int main()
{
log("test");
}
在这之前,我所知道的最好的解决方案是使用宏来捕获__FUNCTION__
的值,并将其传递给您的函数。例如:
void log(const std::string& message, const std::string& function)
{
}
#define LOG(message) log(message, __FUNCTION__)
int main()
{
LOG("test");
}
是的,VS 2019 16.6 Preview 2(根据此链接(添加了这样的内部函数(__builtin_FILE()
、__builtin_FUNCTION()
、__builtin_LINE()
、__builtin_COLUMN()
(,以支持c++20std::source_location
。
相关文章:
- MSVC多行宏编译器错误
- 为什么使用__LINE_的代码在发布模式下在MSVC下编译,而不是在调试模式下
- MSVC是否支持C++11样式的属性而不是__declspec
- MSVC将仅移动结构参数解释为指针
- C++17中函数模板中的静态数组初始化(MSVC 2019)
- 有与__builtin__FUNCTION()等效的MSVC吗
- 为什么 gcc 编译这个而 msvc 没有
- 看起来is_nothrow_constructible_v()在MSVC中被破坏了,我错了吗
- 正在解码MSVC 32位版本的程序集(作业).没有手术做什么
- MSVC 忽略 [[maybe_unused]] 的功能?
- std::vector::p ush_back() 不会在 MSVC 上编译具有已删除移动构造函数的对象
- MSVC中的宏观扩展问题
- "Ill-defined for-loop - loop executes infinitely" (MSVC C6295)
- __CHAR_BIT__宏是否为 MSVC 编译器预定义?
- 不正确的操作数类型 MSVC
- 使用 MSVC 调试类型
- CRTP 中的复制赋值运算符 - gcc vs clang 和 msvc
- MSVC(Visual C++)是否有等效的-weffc ++?
- 命名空间范围内的外部 - GCC vs clang vs msvc
- Visual C++: MSVC vs. GCC+CLANG: 处理 lambda 捕获类成员变量,正确的方法是什么?