std :: array是否可以移动?
在Bjarne Native 2012演示幻灯片(幻灯片41)中,它std::array列为唯一不可移动的容器之一.
快速浏览gcc 4.8库源代码似乎证实std::array不可移动:
的std ::向量:
/* @brief %Vector move constructor.
... */
vector(vector&& __x) noexcept
: _Base(std::move(__x)) { }
Run Code Online (Sandbox Code Playgroud)
在std :: array中,接收rvalue引用参数的唯一方法是随机元素访问,这避免了通过复制返回:
get(array<_Tp, _Nm>&& __arr) noexcept
{ /*...*/ return std::move(get<_Int>(__arr)); }
Run Code Online (Sandbox Code Playgroud)
是否std::array创建了默认的move-constructor和move-assignment ,或者是std::array不可移动的?如果它是不可移动的,为什么std::array不能移动std::vector呢?