will stl deque reallocate my elements (c++)?

前端 未结 2 1276
旧巷少年郎
旧巷少年郎 2021-01-04 22:22

Hi I need an stl container which can be indexed like a vector but does not move old elements in the memory like a vector would do with resize or reserve (Unless I call reser

2条回答
  •  既然无缘
    2021-01-04 23:25

    std::deque "never invalidates pointers or references to the rest of the elements" when adding or removing elements at its back or front, so yes, when you only push_back the elements stay in place.

提交回复
热议问题