std::is_copy_constructible in C++ with Examples
Last Updated :
12 Jun, 2020
The std::is_copy_constructible template of C++ STL is present in the <type_traits> header file. The std::is_copy_constructible template of C++ STL is used to check whether the T is copy constructible or not. It return the boolean value true if T is copy constructible type, Otherwise return false.
Header File:
#include<type_traits>
Template Class:
template <class T> struct is_copy_constructible;
Syntax:
std::is_copy_constructible <int> ::value
std::is_copy_constructible>class T> ::value
Parameters: This template accepts a single parameter T(Trait class) to check if T is copy constructible or not.
Return Value: This template returns a boolean variable as shown below:
- True: If the type T is copy constructible.
- False: If the type T is not a copy constructible./li>
Below programs illustrates the std::is_copy_constructiblev template in C/C++:
Program:
#include <bits/stdc++.h>
#include <type_traits>
using namespace std;
struct B {
};
struct A {
A& operator=(A&) = delete ;
};
int main()
{
cout << boolalpha;
cout << "char: "
<< is_copy_constructible< char >::value
<< endl;
cout << "int: "
<< is_copy_constructible< int >::value
<< endl;
cout << "int[2]: "
<< is_copy_constructible< int [2]>::value
<< endl;
cout << "struct A: "
<< is_copy_constructible<A>::value
<< endl;
cout << "struct B: "
<< is_copy_constructible<B>::value
<< endl;
return 0;
}
|
Output:
char: true
int: true
int[2]: false
struct A: true
struct B: true
Reference: http://www.cplusplus.com/reference/type_traits/is_copy_constructible/
Share your thoughts in the comments
Please Login to comment...