is_trivial Declaration

template< class T >
struct is_trivial;

Parameters

  • T: The type that we want to check is if it is a trivial type class or not.

Return Type

To check if the T is a trivial type, we use std::is_trivial::value member:

  • It is true if the class is trivial type.
  • False otherwise.

Note: is_trivial inherits from integral_constant as being either true_type or false_type, depending on whether T is a trivial type.

is_trivial in C++

std::is_trivial function is used to check whether the given type T is a trivial class or not. It is a template declared in <type_traits> header file.

What is a Trivial Class in C++?

A trivial class type is a type whose storage is contiguous (trivially copyable) and which only supports static default initialization (trivially default constructible), either cv-qualified or not. It includes scalar types, trivial classes, and arrays of any such types. A trivial class is a class (defined with class, struct, or union) that is both trivially default constructible and trivially copyable, which implies that: 

  • It uses the implicitly defined default, copy and move constructors, copy and move assignments, and destructors.
  • It has no virtual members.
  • It has no non-static data members with brace- or equal- initializers.
  • Its base class and non-static data members (if any) are themselves also trivial types.

Similar Reads

is_trivial Declaration

template< class T >struct is_trivial;...

Example of is_trivial

The below C++ program illustrates the usage of the is_trivial function to determine whether each class is trivial or not....