Open In App

std::is_trivially_copy_assignable class in C++ with Examples

Last Updated : 08 Jun, 2020
Improve
Improve
Like Article
Like
Save
Share
Report

The std::is_trivially_copy_assignable template of C++ STL is present in the <type_traits> header file. The std::is_trivially_copy_assignable template of C++ STL is used to check whether T is trivially copy assignable type or not. It return the boolean value true if T is trivially copy assignable type, otherwise return false.

Header File:

#include<type_traits>

Template Class:

template<class T>
struct is_trivially_copy_assignable

Syntax:

is_trivially_copy_assignable<T>::value

Parameter: The template std::is_trivially_copy_assignable accepts a single parameter T(Trait class) to check whether T is trivially copy assignable type or not.

Return Value: The template std::is_trivially_copy_assignable returns a boolean variable as shown below:

  • True: If the type T is a trivially copy assignable.
  • False: If the type T is not a trivially copy assignable.

Below is the program to demonstrate std::is_trivially_copy_assignable in C++:

Program 1:




// C++ program to illustrate
// std::is_trivially_copy_assignable
#include <bits/stdc++.h>
#include <type_traits>
using namespace std;
  
// Declare Structures
struct X {
};
  
struct Y {
    Y& operator=(const Y&)
    {
        return *this;
    }
};
  
// Driver Code
int main()
{
    cout << std::boolalpha;
  
    cout << "int? "
         << is_trivially_copy_assignable<int>::value
         << endl;
  
    cout << "X? "
         << is_trivially_copy_assignable<X>::value
         << endl;
  
    cout << "Y? "
         << is_trivially_copy_assignable<Y>::value
         << endl;
  
    cout << "int[2]? "
         << is_trivially_copy_assignable<int[2]>::value
         << endl;
    return 0;
}


Output:

int? true
X? true
Y? false
int[2]? false

Reference: http://www.cplusplus.com/reference/type_traits/is_trivially_copy_assignable/



Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads