std::is_copy_constructible in C++ with Examples
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:
// C++ program to illustrate // std::is_copy_constructible example #include <bits/stdc++.h> #include <type_traits> using namespace std; // Declare structures struct B { }; struct A { A& operator=(A&) = delete ; }; // Driver Code int main() { cout << boolalpha; // Check that if char is copy // constructible or not cout << "char: " << is_copy_constructible< char >::value << endl; // Check that if int is copy // constructible or not cout << "int: " << is_copy_constructible< int >::value << endl; // Check that if int[2] is copy // constructible or not cout << "int[2]: " << is_copy_constructible< int [2]>::value << endl; // Check that if struct A is copy // constructible or not cout << "struct A: " << is_copy_constructible<A>::value << endl; // Check that if struct B is copy // constructible or not 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/
Please Login to comment...