I read about std::is_pointer
in C++.
Then I wrote the program and check whether T
is a pointer type or not using std::is_pointer
.
#include <iostream>
int main()
{
std::cout<<std::boolalpha;
std::cout<<"char : " <<std::is_pointer<char>::value<<std::endl; // OK
std::cout<<"char * : "<<std::is_pointer<char *>::value<<std::endl; // OK
std::cout<<"char ** : "<<std::is_pointer<char **>::value<<std::endl; // OK
std::cout<<"char *** : "<<std::is_pointer<char ***>::value<<std::endl; // OK
std::cout<<"std::nullptr_t : "<<std::is_pointer<std::nullptr_t>::value<<std::endl; // Not ok, Why false??
}
Output : [Wandbox Demo]
char : false
char * : true
char ** : true
char *** : true
std::nullptr_t : false
Why is std::is_pointer<std::nullptr_t>::value
equal to false
?
Because std::nullptr_t
is not a pointer type. And is_pointer
only evaluates to true
for pointer types.
nullptr_t
is convertible to a pointer, but it isn't a pointer. Indeed, nullptr_t
is not a class type, integral, floating-point, enumerator, or any kind of type other than is_null_pointer
type. It has its own unique classification in the categorization of types.