What does the standard say about transition-assignment to itself in the case of MoveAssignable?

Here's C ++ 17 current description of MoveAssignable:

t = rv;

If t and rv do not belong to the same object, t is equivalent to rv before the assignment state rv is undefined. [Note: rv must still satisfy the requirements of the library component, which using this, regardless of whether t and rv belong to the same object. The operations listed in these requirements should work, as indicated, rv has been moved with or not. - final note]

What does it mean that "rv still satisfies the requirements of the library component that uses it" are referenced?

What to do if tthey rvrelate to the same object? What can / should have a type with MoveAssignable in this case?

Does this description mean:

  • the library will not cause redirection with itself, so the type can do whatever it wants in this case (even crash)

  • or the type must somehow handle this case (the failure is not resolved), but its result does not matter

  • or something else?

Note: there are similar questions in SO, but there are conflicting / old (C ++ 14 has different rules) answers, comments, so I would like to clarify this.

+4
source share
1 answer

What does it mean that "rv still satisfies the requirements of the library component that uses it" are referenced?

, rv , . , , " !" state throws , , .

, t rv ?

: "rv ". , t .

:

  1. - ( ), .

, , .

+2

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


All Articles