1.test_callable_plain,作用:判断参数是否与函数声明一致
using false_t = char;
struct true_t {
false_t data[2];
};
static_assert(sizeof(false_t) != sizeof(true_t), "I can't work :(");
template <
typename Method,
typename ...Args,
typename = decltype(std::declval<Method>()(
std::declval<Args>()...))>
true_t test_callable_plain(Method &&, Args &&...) noexcept;
false_t test_callable_plain(...) noexcept;
template <typename Method, typename ...Args>
struct is_callable_plain
: std::bool_constant<(
sizeof(test_callable_plain(
std::declval<Method>(),
std::declval<Args>()...
)) == sizeof(true_t))> {
};
template <typename Method, typename ...Args>
constexpr bool is_callable_plain_v = is_callable_plain<Method, Args...>::value;
//使用示例代码
void FnC(int age, string name) {
}
int main()
{
auto c1 = test_callable_plain(FnC, 1); //c1值为false_t
auto c2 = test_callable_plain(FnC, 1,"FFF"); //c2值为true_t
constexpr auto c3 = is_callable_plain_v<decltype(FnC), int>; //false
constexpr auto c4 = is_callable_plain_v<decltype(FnC), int,string>;//true
}
标签:false,auto,Telegram,callable,源码,plain,test,true,点滴 From: https://www.cnblogs.com/qing123/p/17354596.html