Open In App

is_polymorphic template in C++

Last Updated : 19 Nov, 2018
Comments
Improve
Suggest changes
Like Article
Like
Report
The std::is_polymorphic template of C++ STL is used to checks whether the type is a polymorphic class type or not. It returns a boolean value showing the same. Syntax:
template < class T > struct is_polymorphic;
Parameter: This template contains single parameter T (Trait class) to check whether T is a polymorphic class type or not. Return Value:This template returns a boolean value as shown below:
  • True: if the type is a polymorphic class.
  • False: if the type is a non-polymorphic class.
Below programs illustrate the std::is_polymorphic template in C++ STL: Program 1: CPP
// C++ program to illustrate
// std::is_polymorphic template

#include <iostream>
#include <type_traits>
using namespace std;

struct gfg {
    virtual void foo();
};

struct geeks : gfg {
};

class raj {
    virtual void foo() = 0;
};

struct sam : raj {
};

int main()
{
    cout << boolalpha;
    cout << "is_polymorphic:"
         << '\n';
    cout << "gfg:"
         << is_polymorphic<gfg>::value
         << '\n';
    cout << "geeks:"
         << is_polymorphic<geeks>::value
         << '\n';
    cout << "raj:"
         << is_polymorphic<raj>::value
         << '\n';
    cout << "sam:"
         << is_polymorphic<sam>::value
         << '\n';

    return 0;
}
Output:
is_polymorphic:
gfg:true
geeks:true
raj:true
sam:true
Program 2: CPP
// C++ program to illustrate
// std::is_polymorphic template

#include <iostream>
#include <type_traits>
using namespace std;

struct gfg {
    int m;
};

struct sam {
    virtual void foo() = 0;
};

class raj : sam {
};

int main()
{
    cout << boolalpha;
    cout << "is_polymorphic:"
         << '\n';
    cout << "gfg:"
         << is_polymorphic<gfg>::value
         << '\n';
    cout << "sam:"
         << is_polymorphic<sam>::value
         << '\n';
    cout << "raj:"
         << is_polymorphic<raj>::value
         << '\n';

    return 0;
}
Output:
is_polymorphic:
gfg:false
sam:true
raj:true

Article Tags :
Practice Tags :

Similar Reads