Skip to content
Related Articles

Related Articles

Improve Article

is_class template in C++

  • Last Updated : 19 Nov, 2018
Geek Week

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::




// 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;
}
Output:
is_class:
GFG1: true
GFG2: false

Program 2:




// 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;
}
Output:
is_class:
int: false
GFG1: true
GFG2: true
Want to learn from the best curated videos and practice problems, check out the C++ Foundation Course for Basic to Advanced C++ and C++ STL Course for foundation plus STL.  To complete your preparation from learning a language to DS Algo and many more,  please refer Complete Interview Preparation Course.



My Personal Notes arrow_drop_up
Recommended Articles
Page :