相关疑难解决方法(0)

移动的向量是否总是空的?

我知道通常标准对已经移动的值的要求很少:

N3485 17.6.5.15 [lib.types.movedfrom]/1:

可以从(12.8)移动C++标准库中定义的类型的对象.可以显式指定或隐式生成移动操作.除非另有规定,否则此类移动物体应置于有效但未指定的状态.

我找不到任何与vector此明确排除的内容.但是,我无法想出一个理智的实现,导致向量不为空.

是否有一些标准需要我缺少或者类似于在C++ 03中作为连续缓冲区处理basic_string

c++ vector language-lawyer move-semantics c++11

36
推荐指数
2
解决办法
6697
查看次数

C++:用整数移动语义

int c = 2;
int d = std::move(c);
std::cout << "c is: " << c << std::endl;
std::cout << "d is: " << d << std::endl;
Run Code Online (Sandbox Code Playgroud)

此代码输出:

c是:2

d 是:2

我认为在 move(c) 到 d 之后,c 将是空的,为什么它的值仍然是 2?你能帮我解释一下吗?谢谢你。

c++ move-semantics c++11

1
推荐指数
1
解决办法
321
查看次数

标签 统计

c++ ×2

c++11 ×2

move-semantics ×2

language-lawyer ×1

vector ×1