C++20引入了is_invocable,用于判定某个可执行类型(函数,lambda,函数对象等)的函数签名
1.is_invocable/is_invocable_v检查函数参数类型
#include <type_traits>
#include <iostream>
using namespace std;auto func1(char) -> int (*)()
{return nullptr;
}int func2(int, int)
{return 1;
}int main()
{cout<<is_invocable<decltype(func1), char>::value<<endl; //输出1cout<<is_invocable<decltype(func1), int>::value<<endl; //输出1cout<<is_invocable<decltype(func1), void>::value<<endl; //输出0cout<<is_invocable_v<decltype(func2), int, int><<endl; //输出1cout<<is_invocable_v<decltype(func2), int, char><<endl; //输出1cout<<is_invocable_v<decltype(func2)><<endl; //输出0cout<<is_invocable_v<decltype(func2), void><<endl;/ //输出0return 0;
}