调整外部向量大小是否会复制内部向量? [英] Does resizing an outer vector copies the inner vector?

查看:193
本文介绍了调整外部向量大小是否会复制内部向量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设您有向量向量:

vector<vector<string> > v;



到不同的地址),例如通过做很多 v.push_back(),内部向量的内部数组也被复制(因为向量的拷贝构造器通常拷贝内部数组),或者C ++有一个方法来调整外部向量而不复制一切递归?

when the internal array of the outer vector is resized (and suppose the internal array also have to be reallocated to a different address), for example by doing lots of v.push_back(), does the internal array of the inner vectors get copied as well (because vector's copy constructor usually copies the internal array), or does C++ have a way to resize the outer vector without copying everything recursively?

C ++ 11移动构造函数是否会影响这?这是否取决于STL实现?

Does C++11 move constructor affect this? Does this depend on the STL implementation?

推荐答案

是的,在C ++ 03中,需要外部向量。在C ++ 11中,它们被移动。这取决于实现,只要实现是正确的。如果实现正确,这是行为。

Yes, in C++03, the inner vectors are copied when a reallocation is needed for the outer vector. In C++11, they are moved. It depends on the implementation only so far as the implementation being correct. If the implementation is correct, this is the behavior.

这篇关于调整外部向量大小是否会复制内部向量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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