Does the copy constructor or copy assignment operator delete as an "advertised user"?

Per this presentation , if either the copy constructor or the copy assignment operator is "declared by the user", then implicit move operations will not be performed. Does delete convert to a copy constructor or copy assignment operator as an "declared user"?

 struct NoCopy { NoCopy(NoCopy&) = delete; NoCopy& operator=(const NoCopy&) = delete; }; 

Will implicit move operations be created for the NoCopy class? Or is deletion of the corresponding copy operations considered “declared by the user” and thus blocks the implicit generational movement?

If possible, I would prefer an answer that refers to the relevant parts of the standard.

+6
source share
2 answers

According to slide 14 of your presentation, the deleted copy of the copy is "declared by the user", which prevents the generation of motion.

+6
source

The term "user-declared" does not have a formal definition in the standard. It must be the opposite of “implicitly declared” in the context of special member functions. [dcl.fct.def.default] / 4 may be a little clearer about this fact, but there is an intention:

Explicit default functions and implicitly declared functions are collectively called default functions, and the implementation must contain implicit definitions for them (12.1, 12.4, 12.8), which may mean their removal. A special member function is provided to the user if it is declared by the user and is clearly not defaulted or deleted by its first declaration. The user-provided function of explicitly default value (i.e., explicitly defaulted after the first declaration) is defined in the place where it is clearly defaulted; if such a function is implicitly defined as remote, the program is poorly formed.

Both NoCopy(NoCopy&) = delete; and NoCopy& operator=(const NoCopy&) = delete; are declarations of special member functions. Because you explicitly declare them, rather than letting the compiler declare them implicitly, they are declared by the user. Thus, these declarations will suppress the implicit declarations of the move constructor and the redirection assignment operator on [class.copy] / 9:

If the definition of class X does not explicitly declare the move constructor, it will be declared as implicit as default, if and only if

- X does not have a copy constructor declared by the user,

- X does not have a user-declared copy destination operator,

- X does not have a user-defined move destination operator,

- X does not have a user-declared destructor and

- the move constructor will not be explicitly defined as remote.

+8
source

Source: https://habr.com/ru/post/983591/


All Articles