C++20中引入了std::source_location,用来描述函数调用的上下文信息。
其主要的成员函数如下:
line()
:获取行号。column()
:获取列号。file_name()
:获取文件名。function_name()
:获取函数域名。
#include <iostream>
#include <string_view>
#include <source_location>
void log(std::string_view message, const std::source_location& location = std::source_location::current())
{
std::cout << location.file_name() << ':'
<< location.line() << ' '
<< "func:"<<location.function_name() << ' '
<< "log:"<<message &