Open In App

type_traits::is_null_pointer in C++

Last Updated : 28 May, 2020
Comments
Improve
Suggest changes
Like Article
Like
Report
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: CPP14
// C++ program to illustrate
// is_null_pointer template

#include <bits/stdc++.h>
#include <type_traits>
using namespace std;

// Driver Code
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: CPP14
// C++ program to illustrate
// is_null_pointer template

#include <bits/stdc++.h>

#include <type_traits>
using namespace std;

// Driver Code
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/

Next Article
Article Tags :
Practice Tags :

Similar Reads