is_class template in C++

The std::is_class template of C++ STL is used to check whether the given type is class or not. It returns a boolean value showing the same.

Syntax:

template <class T> struct is_class;

Parameter: This template accepts single parameter T (Trait class) to check whether T is a class or not.

Return Value: This template returns a boolean value as shown below:

  • True: If a type is a class class.
  • False: If a type is a class class.

Below programs illustrate the std::is_class template in C++:

Program 1::

filter_none

edit
close

play_arrow

link
brightness_4
code

// C++ program to illustrate
// is_class template
  
#include <iostream>
#include <type_traits>
using namespace std;
  
class GFG1 {
};
  
union GFG2 {
    int var1;
    float var2;
};
  
int main()
{
    cout << boolalpha;
    cout << "is_class:" << endl;
    cout << "GFG1: "
         << is_class<GFG1>::value << endl;
    cout << "GFG2: "
         << is_class<GFG2>::value << endl;
    return 0;
}

chevron_right


Output:

is_class:
GFG1: true
GFG2: false

Program 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

// C++ program to illustrate
// is_class template
  
#include <iostream>
#include <type_traits>
using namespace std;
  
class GFG1 {
    int var1;
    float var2;
    char var3;
};
  
struct GFG2 {
    union {
        int var4;
        float var5;
    };
};
  
int main()
{
    cout << boolalpha;
    cout << "is_class:" << endl;
    cout << "int: "
         << is_class<int>::value << endl;
    cout << "GFG1: "
         << is_class<GFG1>::value << endl;
    cout << "GFG2: "
         << is_class<GFG2>::value << endl;
    return 0;
}

chevron_right


Output:

is_class:
int: false
GFG1: true
GFG2: true


My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



Improved By : rajasethupathi



Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.