std::is_constructible template in C++ with Examples
Last Updated :
12 Dec, 2022
The std::is_constructible template of C++ STL is present in the <type_traits> header file. The std::is_constructible template of C++ STL is used to check whether the given type T is constructible type with the set of arguments or not. It return the boolean value true if T is of constructible type, Otherwise return false. Header File:
#include<type_traits>
Template Class:
template <class T, class... Args>
struct is_constructible;
Syntax:
std::is_constructible::value
Parameters:
- T: It represent the data type.
- Args: It represent the list of data type T.
Return Value: This template returns a boolean variable as shown below:
- True: If the type T is constructible.
- False: If the type T is not constructible.
Below is the program to illustrates the std::is_constructible template in C/C++: Program:
CPP
#include <bits/stdc++.h>
#include <type_traits>
using namespace std;
struct A {
};
struct T {
T( int , int ){};
};
int main()
{
cout << std::boolalpha;
cout << " int : "
<< is_constructible< int >::value
<< endl;
cout << " int ( float ): "
<< is_constructible< int , float >::value
<< endl;
cout << " int ( float , float ): "
<< is_constructible< int , float , float >::value
<< endl;
cout << "T: "
<< is_constructible<T>::value
<< endl;
cout << "T( int ): "
<< is_constructible<T, int >::value
<< endl;
cout << "T( int , int ): "
<< is_constructible<T, int , int >::value
<< endl;
return 0;
}
|
Output:
int: true
int(float): true
int(float, float): false
T: false
T(int): false
T(int, int): true
Reference: http://www.cplusplus.com/reference/type_traits/is_constructible/
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...