std::list 是否保证项目永远不会被移动到不同的内存位置? [英] Does std::list guarantee that items will never be moved to a different memory location?

查看:26
本文介绍了std::list 是否保证项目永远不会被移动到不同的内存位置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否保证一旦std::liststd::forward_list 项被分配,它会一直保持在相同的内存位置(地址)直到被销毁?当然,除了列表本身被复制.

Is it guaranteed that once std::list or std::forward_list item is allocated, it will remain at the same memory location (address) until destroyed? Except, of course, for the list itself being copied.

推荐答案

如果您查看所有不破坏元素的函数的文档, (插入emplacepush_back 等...),你会看到他们有一个注释,"没有引用无效",这相当于您所要求的(对象停留在相同的内存位置).所以,是的.

If you look at the documentation for all the functions which don't destroy elements, (insert, emplace, push_back, etc...), you will see that they have a note that "no references are invalidated", which is equivalent to what you are asking (objects staying at the same memory location). So, yes.

这篇关于std::list 是否保证项目永远不会被移动到不同的内存位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆