VOOZH about

URL: https://www.geeksforgeeks.org/cpp/stdis_trivially_copy_constructible-in-c-c/

⇱ std::is_trivially_copy_constructible in C/C++ - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

std::is_trivially_copy_constructible in C/C++

Last Updated : 30 Mar, 2020
The std::is_trivially_copy_constructible template is a type that can be trivially constructed from a value or reference of the same type. This includes scalar types, trivially copy constructible classes and arrays of such types. This algorithm is about to test whether a type is trivially copied constructible or not. It returns the boolean value showing the same. Header File:
#include <type_traits>
Template Class:
template <class T> 
struct is_trivially_copy_constructible;
If T is_trivially_copy_constructible, then it inherits from true_type else inherits from false_type. Syntax:
std::is_trivially_copy_constructible<int>::value
std::is_trivially_copy_constructible<class T>::value
Parameter: This template accepts a single parameter T(Trait class) to check if T is trivially copy constructible or not. Return Value: This template return a boolean variable as shown below:
  • True: If the type is trivially copy constructible.
  • False: If the type is not trivially copy constructible.
Below programs illustrates the std::is_trivially_copy_constructible template in C/C++: Program 1:
Output:
is_trivially_copy_constructible: 
int: true
A: true
B: false
C: false
Program 2:
Output:
Ex1 is copy-constructible? true
Ex1 is trivially copy-constructible? false
Ex2 is trivially copy-constructible? true
Ex2 is nothrow copy-constructible? true
Comment
Article Tags: