最近我偶然发现了std::is_invocable,它将被引入到C++17标准中。我想知道为什么它需要用户提供函数指针的类型,而不是直接提供函数指针本身,这可能更方便,特别是因为非类型模板参数现在可以是无限制的。
我的意思可以通过下面的例子来解释
void hello_world() {
cout << "Hello world" << endl;
}
int main() {
cout << std::is_invocable_v<decltype(hello_world)> << endl;
// as opposed to being able to do
// cout << std::is_invocable_v<hello_world> << endl;
return 0;
}
template auto
. - Barry