什么是微不足道的功能? [英] What is a trivial function?

查看:64
本文介绍了什么是微不足道的功能?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

[basic.def.odr]/3引用了术语非平凡函数",我在标准(N4140)中找不到该定义.

[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

[basic.def.odr]/3

变量x的名称显示为可能评估的表达式ex会被ex使用,除非应用左值到右值转换(4.1)到x产生不调用的常量表达式(5.19)任何非平凡函数,如果x是对象,则ex是以下元素的元素表达式e的潜在结果集,其中左值到右值转换(4.1)应用于e,或者e是一个丢弃值表达式(第5条).

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).

推荐答案

非平凡函数"是平凡特殊成员函数"的补充.对于普通/非普通的default/copy/move构造函数,copy/move赋值运算符或析构函数是什么有定义-仅与特殊成员函数相关的特征,并确定例如在某些情况下需要调用这些.

"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.

这些的定义可以在第12章中找到.

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

默认构造函数,第12.1/4节:

Default constructor, §12.1/4:

如果不是用户提供的,并且满足以下条件,则默认构造函数是琐碎的:

  • 其类没有虚函数(10.3)和虚拟基类(10.1),并且
  • 此类的非静态数据成员没有括号或相等的初始化程序,并且
  • 该类的所有直接基类均具有简单的默认构造函数,并且
  • 对于其类的所有非静态数据成员,这些成员都是类类型(或其数组),每个此类都有一个琐碎的默认值构造函数.

否则,默认构造函数为非平凡.

Otherwise, the default constructor is non-trivial.

复制/移动构造函数,第12.8/12节:

Copy/move constructors, §12.8/12:

如果不是,则类X的复制/移动构造函数是平凡的用户提供的 parameter-type-list 等效于隐式声明的 parameter-type-list 以及if

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 没有虚拟函数(10.3)和虚拟基类(10.1),并且
  • class X 没有挥发性限定类型的非静态数据成员,并且
  • 选择复制/移动每个直接基类子对象的构造函数很简单,并且
  • 对于每个 X 的类类型(或其数组)的每个非静态数据成员,选择复制/移动该成员的构造方法是琐碎的;
  • 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.

复制/移动分配运算符,§12.8/26:

Copy/move assignment operator, §12.8/26:

X 的复制/移动赋值运算符不重要(如果是)不是用户提供的,其 parameter-type-list 等效于隐式声明的 parameter-type-list 以及if

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 没有虚拟函数(10.3)和虚拟基类(10.1),并且
  • class X 没有挥发性限定类型的非静态数据成员,并且
  • 已选择复制/移动每个直接基类的赋值运算符
  • 对于每个 X 的类类型(或其数组)的每个非静态数据成员,
  • 都选择了赋值运算符来复制/移动该成员是微不足道的;
  • 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.

析构函数,§12.4/5:

如果析构函数不是用户提供的,并且是:

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

  • 析构函数不是虚拟的
  • 该类的所有直接基类均具有琐碎的析构函数,并且
  • 对于所有属于该类类型(或其数组)的该类的所有非静态数据成员,每个此类都具有一个琐碎的破坏者.

否则,析构函数不平凡

这篇关于什么是微不足道的功能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆