Will std::vectors inside another vector reallocate when the first vector reallocates?

后端 未结 2 2204
一生所求
一生所求 2021-02-18 21:47

I have a vector std::vector> m_contactPairs;

If I call m_contactPairs.push_back() or any other function t

2条回答
  •  抹茶落季
    2021-02-18 22:30

    In C++03, a std::vector reallocation will copy ("deep copy") each element. That means for your situation, each vector would be copied.

    In C++11 or later, a std::vector reallocation will move each element only if the elements have a move constructor that is noexcept.

    Visual Studio 2010 lacks noexcept support, so you would still get a deep copy.

提交回复
热议问题