#include #include #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 decltype(auto) test(Callable &&c, Args &&...args) { using result_type = std::invoke_result_t; std::function function = std::forward(c); return function(std::forward(args)...); } int main() { test(function); test(lambda); test(functor_type{}); test(&struct_type::method, struct_type{}); }