Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is a trivial function?

[basic.def.odr]/3 makes a reference to the term "nontrivial function", whose definition I couldn't find in the Standard (N4140).

[basic.def.odr]/3

A variable x whose name appears as a potentially-evaluated expression ex is odr-used by ex unless applying the lvalue-to-rvalue conversion (4.1) to x yields a constant expression (5.19) that does not invoke any nontrivial functions and, if x is an object, ex is an element of the set of potential results of an expression e, where either the lvalue-to-rvalue conversion (4.1) is applied to e, or e is a discarded-value expression (Clause 5).

like image 262
Belloc Avatar asked May 10 '15 14:05

Belloc


People also ask

What are trivial functions?

The trivial solution is the zero function. while a nontrivial solution is the exponential function. The differential equation with boundary conditions is important in math and physics, as it could be used to describe a particle in a box in quantum mechanics, or a standing wave on a string.

What does trivial mean in math?

In Mathematics, triviality is a property of objects having simple structures. The word trivial is used for simple and evident concepts or things, such as – topological spaces and groups that have a simple arrangement. The antonym of trivial is non-trivial.

What are trivial factors?

The number 1 is called the trivial factor as every number is divisible by 1. m is called the improper factor as every number is also divisible by itself. A number that has a nontrivial proper factor is said to be composite.

What is trivial data type?

A trivial 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.

What is a trivial and non-trivial function?

"non-trivial function" is the complement of "trivial special member function". There are definitions for what a trivial and non-trivial default/copy/move constructor, copy/move assignment operator or destructor is - traits that only appertain to special member functions, and decide whether e.g. these need to be called under certain circumstances.

What is triviality in math?

Triviality means something with a lack of attention or lack of seriousness or significance. In Mathematics, triviality is a property of objects having simple structures. The word trivial is used for simple and evident concepts or things, such as – topological spaces and groups that have a simple arrangement. The antonym of trivial is non-trivial.

What is trivial functional dependency?

The dependency of an attribute on a set of attributes is known as trivial functional dependency if the set of attributes includes that attribute.

What is a trivial type in Java?

Trait class that identifies whether T is a trivial type. A trivial 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.


1 Answers

"non-trivial function" is the complement of "trivial special member function". There are definitions for what a trivial and non-trivial default/copy/move constructor, copy/move assignment operator or destructor is - traits that only appertain to special member functions, and decide whether e.g. these need to be called under certain circumstances.

The definitions for these can be found in chapter §12.

Default constructor, §12.1/4:

A default constructor is trivial if it is not user-provided and if:

  • its class has no virtual functions (10.3) and no virtual base classes (10.1), and
  • no non-static data member of its class has a brace-or-equal-initializer, and
  • all the direct base classes of its class have trivial default constructors, and
  • for all the non-static data members of its class that are of class type (or array thereof), each such class has a trivial default constructor.

Otherwise, the default constructor is non-trivial.

Copy/move constructors, §12.8/12:

A copy/move constructor for class X is trivial if it is not user-provided, its parameter-type-list is equivalent to the parameter-type-list of an implicit declaration, and if

  • class X has no virtual functions (10.3) and no virtual base classes (10.1), and
  • class X has no non-static data members of volatile-qualified type, and
  • the constructor selected to copy/move each direct base class subobject is trivial, and
  • for each non-static data member of X that is of class type (or array thereof), the constructor selected to copy/move that member is trivial;

otherwise the copy/move constructor is non-trivial.

Copy/move assignment operator, §12.8/26:

A copy/move assignment operator for class X is trivial if it is not user-provided, its parameter-type-list is equivalent to the parameter-type-list of an implicit declaration, and if

  • class X has no virtual functions (10.3) and no virtual base classes (10.1), and
  • class X has no non-static data members of volatile-qualified type, and
  • the assignment operator selected to copy/move each direct base class
  • for each non-static data member of X that is of class type (or array thereof), the assignment operator selected to copy/move that member is trivial;

otherwise the copy/move assignment operator is non-trivial.

Destructor, §12.4/5:

A destructor is trivial if it is not user-provided and if:

  • the destructor is not virtual,
  • all of the direct base classes of its class have trivial destructors, and
  • for all of the non-static data members of its class that are of class type (or array thereof), each such class has a trivial destructor.

Otherwise, the destructor is non-trivial

like image 61
Columbo Avatar answered Sep 18 '22 18:09

Columbo