There are these in <type_traits>
:
is_pointer<>
is_function<>
is_member_function_pointer<>
But not this:
is_function_pointer<>
Why is it so?
The traits in [meta.unary.cat] are intended to classify each type into a single category. Is it a void, integral, pointer, etc. At this level, pointer-to-function is no different than pointer-to-int. And note that a pointer to a member is not a pointer. It is merely an english homonym.
It was intended that every type return true to exactly one trait in [meta.unary.cat]. And in this categorization, both a function pointer and a scalar pointer would both return true under is_pointer
.
I will note that we did not achieve our objective. nullptr_t
escapes our goal. But we got close. Here is a graphical representation of the current type_traits classification.
Update:
This is a correctly working program with correct output:
#include <iostream>
#include <type_traits>
typedef void (*fptr)();
typedef int* intptr;
int main()
{
std::cout << std::is_function<fptr>::value << '\n';
std::cout << std::is_pointer<fptr>::value << '\n';
std::cout << std::is_pointer<intptr>::value << '\n';
}
0
1
1
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With