Stephan T. Lavavej explained the case he was talking about in a tweet:
我想到的情况是,您可以获取重载/模板化函数的地址,如果它用于初始化特定类型的变量,这将消除您想要的变量的歧义。 (有一个消除歧义的列表。)
我们可以从cppreference page on Address of overloaded function 看到这样的例子,我在下面排除了一些:
int f(int) { return 1; }
int f(double) { return 2; }
void g( int(&f1)(int), int(*f2)(double) ) {}
int main(){
g(f, f); // selects int f(int) for the 1st argument
// and int f(double) for the second
auto foo = []() -> int (*)(int) {
return f; // selects int f(int)
};
auto p = static_cast<int(*)(int)>(f); // selects int f(int)
}
Michael Park adds:
也不限于初始化具体类型。它也可以仅从参数的数量推断
并提供this live example:
void overload(int, int) {}
void overload(int, int, int) {}
template <typename T1, typename T2,
typename A1, typename A2>
void f(void (*)(T1, T2), A1&&, A2&&) {}
template <typename T1, typename T2, typename T3,
typename A1, typename A2, typename A3>
void f(void (*)(T1, T2, T3), A1&&, A2&&, A3&&) {}
int main () {
f(&overload, 1, 2);
}
我稍微详细说明了more here。