更新时间:2023-08-23 13:33:58
17.6.4.9 函数参数 [res.on.arguments]
17.6.4.9 Function arguments [res.on.arguments]
1 以下每一项都适用于定义的函数的所有参数在 C++ 标准库中,除非另有明确说明.
1 Each of the following applies to all arguments to functions defined in the C++ standard library, unless explicitly stated otherwise.
...
所以,std::vector
的实现允许假设 other
是一个原值.如果 other
是纯右值,则无法进行自移动赋值.
So, the implementation of std::vector<T, A>::operator=(vector&& other)
is allowed to assume that other
is a prvalue. And if other
is a prvalue, self-move-assignment is not possible.
可能发生的事情:
v
将处于无资源状态(0 容量).如果 v
已经有 0 容量,那么这将是一个空操作.
v
will be left in a resource-less state (0 capacity). If v
already has 0 capacity, then this will be a no-op.
更新
最新工作草案,N4618 已被修改以明确说明在 MoveAssignable
要求中的表达式:
The latest working draft, N4618 has been modified to clearly state that in the MoveAssignable
requirements the expression:
t = rv
(其中rv
是一个右值),如果t,
t
只需在赋值前等于rv
和 rv
不引用同一个对象.无论如何,在赋值之后 rv
的状态是未指定的.还有一个额外的说明需要进一步说明:
(where rv
is an rvalue), t
need only be the equivalent value of rv
prior to the assignment if t
and rv
do not reference the same object. And regardless, rv
's state is unspecified after the assignment. There is an additional note for further clarification:
rv
仍然必须满足使用它的库组件的要求,无论 t
和 rv
是否引用同一个对象.
rv
must still meet the requirements of the library component that is using it, whether or nott
andrv
refer to the same object.