Is it possible to detect the default parameters of a function at compile-time?
问题 #include <thread> #include <functional> using namespace std; void f(int n = 7) {} void g(function<void()> fn) { fn(); // same as f(7) } template<typename Callable> auto GetDefaultArg(Callable fn, size_t arg_ordinal) { // What to put here? } int main() { auto fn = bind(f, GetDefaultArg(f, 1)); g(fn); } As illustrated in the code above, I want to implement a template function GetDefaultArg to detect the default paratemters of a function. It it possible in current C++? 回答1: No you can't detect