我希望我的函数通过将另一个函数作为参数get_source
来返回一个类型。std::source_location
例如,我有一个名为helloMessage
and的函数,sumOf
它具有以下参数类型和返回类型:
void helloMessage(const char* message);
int sumOf(int num1, int num2);
假设我有一个函数,它将从函数对象获取源位置,然后返回其值:
template <typename function_t>
std::source_location get_source(function_t func);
输入:
auto info_1 = get_source(helloMessage);
auto info_2 = get_source(sumOf);
std::cout
<< "info_1: " << info_1.function_name() << '\n'
<< "info_2: " << info_2.function_name() << '\n';
这是我的预期输出:
void helloMessage(const char*)
int sumOf(int, int)
我怎样才能做到这一点?