#include #include #include void loc(std::source_location l = std::source_location::current()) { std::cout << l.file_name() << ':' << l.line() << ' ' << l.function_name() << "\n"; } void function() { loc(); } auto lambda = [] { loc(); }; struct functor_type { void operator()() { loc(); } }; struct struct_type { void method() { loc(); } }; template std::invoke_result_t test(Callable &&c, Args &&...args) { return std::invoke(std::forward(c), std::forward(args)...); } int main() { test(function); test(lambda); test(functor_type{}); test(&struct_type::method, struct_type{}); }