Skip to content
Related Articles
Open in App
Not now

Related Articles

std::is_default_constructible in C++ with Examples

Improve Article
Save Article
  • Last Updated : 12 Jun, 2020
Improve Article
Save Article

The std::is_default_constructible template of C++ STL is present in the <type_traits> header file. The std::is_default_constructible template of C++ STL is used to check whether the T is default constructible or not. A default constructible can be constructed without arguments or initialization values. It return the boolean value true if T is default constructible type, Otherwise return false.

Header File:


Template Class:

template <class T> 
struct is_default_constructible;


std::is_default_constructible>class T> ::value

Parameters: The template std::is_default_constructible accepts a single parameter T(Trait class) to check whether T is default constructible type or not.

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

  • True: If the type T is default constructible.
  • False: If the type T is not default constructible.

Below is the program to illustrates the std::is_default_constructible template in C/C++:


// C++ program to illustrate
// std::is_default_constructible
#include <bits/stdc++.h>
#include <type_traits>
using namespace std;
// Declare structures
struct A {
struct B {
    int n;
    B() = default;
// Class
class classA {
    ~classA() = delete;
// Inherited class
class classB : classA {
// Driver Code
int main()
    cout << boolalpha;
    // Check if int is default constructible?
    cout << "int : "
         << is_default_constructible<int>::value
         << endl;
    // Check if struct A is default constructible?
    cout << "struct A: "
         << is_default_constructible<A>::value
         << endl;
    // Check if struct B is default constructible?
    cout << "struct B: "
         << is_default_constructible<B>::value
         << endl;
    // Check if classA is default constructible?
    cout << "classA: "
         << is_default_constructible<classA>::value
         << endl;
    // Check if classB is default constructible?
    cout << "classB: "
         << is_default_constructible<classB>::value
         << endl;
    return 0;


int : true
struct A: true
struct B: true
classA: false
classB: false


My Personal Notes arrow_drop_up
Related Articles

Start Your Coding Journey Now!