define a function and a pointer to it, and then determine whether the function pointer is a function after dereferencing
void test1() {}
int main()
{
void(*t1)() = test1;
std::cout << std::is_function<decltype(*t1)>::value << std::endl;
std::cout << std::is_function<decltype(test1)>::value << std::endl;
std::cout << (typeid(decltype(test1)).hash_code() == typeid(decltype(*t1)).hash_code()) << std::endl;
return 0;
}
the final output is:
0
1
1
directly compare the types of * T1 and test1, and the results show that the types are the same, but why the first output is 0
I know that when a function is called with a function name, it will be converted to a function pointer
. Do you wonder why the wrong
is caused by the rules of template matching parameters? Partial implementation of is_function:
template<typename>
struct is_function
: public false_type { };
template<typename _Res, typename... _ArgTypes>
struct is_function<_Res(_ArgTypes...)>
: public true_type { };