删除复制构造函数或复制赋值运算符算作 "user declared" 吗?
Does deleting a copy constructor or copy assignment operator count as "user declared"?
根据 this presentation,如果复制构造函数或复制赋值运算符是 "user declared",则不会生成隐式移动操作。 delete
复制构造函数或复制赋值运算符算作"user declared"吗?
struct NoCopy {
NoCopy(NoCopy&) = delete;
NoCopy& operator=(const NoCopy&) = delete;
};
是否会为 NoCopy
class 生成隐式移动操作?还是删除相关复制操作算作 "user declared" 从而抑制隐式移动生成?
如果可能的话,我更喜欢参考标准相关部分的答案。
根据您演示文稿的幻灯片 14,已删除的复制构造函数是 "user declared",因此会抑制移动生成。
术语“用户声明”在标准中没有正式定义。它与特殊成员函数上下文中的“隐式声明”相反。 [dcl.fct.def.default]/4 可以更清楚地说明这个事实,但意图在那里:
Explicitly-defaulted functions and implicitly-declared functions are collectively called defaulted functions, and the implementation shall provide implicit definitions for them (12.1 12.4, 12.8), which might mean defining them as deleted. A special member function is user-provided if it is user-declared and not explicitly defaulted or deleted on its first declaration. A user-provided explicitly-defaulted function (i.e., explicitly defaulted after its first declaration) is defined at the point where it is explicitly defaulted; if such a function is implicitly defined as deleted, the program is ill-formed.
NoCopy(NoCopy&) = delete;
和NoCopy& operator=(const NoCopy&) = delete;
都是特殊成员函数的声明。由于 you 显式声明它们,而不是允许编译器隐式声明它们,因此它们是用户声明的。因此,这些声明将抑制每个 [class.copy]/9:
的移动构造函数和移动赋值运算符的隐式声明
If the definition of a class X
does not explicitly declare a move constructor, one will be implicitly declared as defaulted if and only if
— X
does not have a user-declared copy constructor,
— X
does not have a user-declared copy assignment operator,
— X
does not have a user-declared move assignment operator,
— X
does not have a user-declared destructor, and
— the move constructor would not be implicitly defined as deleted.
根据 this presentation,如果复制构造函数或复制赋值运算符是 "user declared",则不会生成隐式移动操作。 delete
复制构造函数或复制赋值运算符算作"user declared"吗?
struct NoCopy {
NoCopy(NoCopy&) = delete;
NoCopy& operator=(const NoCopy&) = delete;
};
是否会为 NoCopy
class 生成隐式移动操作?还是删除相关复制操作算作 "user declared" 从而抑制隐式移动生成?
如果可能的话,我更喜欢参考标准相关部分的答案。
根据您演示文稿的幻灯片 14,已删除的复制构造函数是 "user declared",因此会抑制移动生成。
术语“用户声明”在标准中没有正式定义。它与特殊成员函数上下文中的“隐式声明”相反。 [dcl.fct.def.default]/4 可以更清楚地说明这个事实,但意图在那里:
Explicitly-defaulted functions and implicitly-declared functions are collectively called defaulted functions, and the implementation shall provide implicit definitions for them (12.1 12.4, 12.8), which might mean defining them as deleted. A special member function is user-provided if it is user-declared and not explicitly defaulted or deleted on its first declaration. A user-provided explicitly-defaulted function (i.e., explicitly defaulted after its first declaration) is defined at the point where it is explicitly defaulted; if such a function is implicitly defined as deleted, the program is ill-formed.
NoCopy(NoCopy&) = delete;
和NoCopy& operator=(const NoCopy&) = delete;
都是特殊成员函数的声明。由于 you 显式声明它们,而不是允许编译器隐式声明它们,因此它们是用户声明的。因此,这些声明将抑制每个 [class.copy]/9:
If the definition of a class
X
does not explicitly declare a move constructor, one will be implicitly declared as defaulted if and only if—
X
does not have a user-declared copy constructor,—
X
does not have a user-declared copy assignment operator,—
X
does not have a user-declared move assignment operator,—
X
does not have a user-declared destructor, and— the move constructor would not be implicitly defined as deleted.