简体   繁体   English

移动 std::deque 后是否保证引用/指针有效?

[英]Are references / pointers guaranteed to be valid after moving std::deque?

Is it safe to assume that any pointers I have to elements inside of an std::deque are still valid after moving the deque to another one with the move constructor?假设在使用移动构造函数将双端队列移动到另一个双端队列后,指向std::deque内部元素的任何指针仍然有效是否安全?

For std::vector I cannot see any reason why they wouldn't be, but I'm not familiar enough with std::deque to be sure I can make the same assumption.对于std::vector我看不出它们为什么不会的任何原因,但我对std::deque不够熟悉,无法确定我可以做出相同的假设。

Pointers to elements would remain valid.指向元素的指针将保持有效。 After move construction : 搬家施工后

After container move construction (overload (8)), references, pointers, and iterators (other than the end iterator) to other remain valid, but refer to elements that are now in *this .在容器移动构造(重载 (8))之后,指向 other 的引用、指针和迭代器(结束迭代器除外)仍然有效,但引用现在在*this元素。 The current standard makes this guarantee via the blanket statement in [container.requirements.general]/12 , and a more direct guarantee is under consideration via LWG 2321 .当前标准通过[container.requirements.general]/12 中的一揽子声明做出此保证,并且正在考虑通过LWG 2321提供更直接的保证。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM