type_traits::is_null_pointer in C++
Last Updated :
28 May, 2020
The type_traits::is_null_pointer of C++ STL is used to check whether the given type is null_pointer or not. It returns the boolean value either true or false. Below is the syntax for the same:
Header File:
#include<type_traits>
Syntax:
template class T struct is_null_pointer;
Parameter: The template type_traits::is_null_pointer accepts a single parameter T (Trait class) to check whether T is a null_pointer or not.
Return Values:
- True: If the type is a null_pointer.
- False: If the pointer is not null pointer.
Below programs illustrate the std::is_null_pointer template in C++ STL:
Program 1:
#include <bits/stdc++.h>
#include <type_traits>
using namespace std;
int main()
{
cout << boolalpha;
cout << "is_null_pointer:" << endl;
cout << "int *&: "
<< is_null_pointer< decltype (nullptr)>::value
<< '\n' ;
cout << "int *[10]: "
<< is_null_pointer< int * [10]>::value
<< '\n' ;
cout << "float *: "
<< is_null_pointer< float *>::value
<< '\n' ;
cout << "int[10]:"
<< is_null_pointer< int [10]>::value
<< '\n' ;
return 0;
}
|
Output:
is_null_pointer:
int *&: true
int *[10]: false
float *: false
int[10]:false
Program 2:
#include <bits/stdc++.h>
#include <type_traits>
using namespace std;
int main()
{
cout << boolalpha
<< is_null_pointer< decltype (nullptr)>::value
<< endl
<< is_null_pointer< int *>::value
<< endl
<< is_pointer< decltype (nullptr)>::value
<< endl
<< is_pointer< int *>::value
<< endl;
}
|
Output:
true
false
false
true
Reference: http://www.cplusplus.com/reference/type_traits/is_null_pointer/
Share your thoughts in the comments
Please Login to comment...