Complexity requirements for std::deque::push_back/front

对着背影说爱祢 提交于 2019-11-30 12:34:52

In the C++11 FDIS, we can read:

23.2.3 Sequence containers [sequence.reqmts]

16/ Table 101 lists operations that are provided for some types of sequence containers but not others. An implementation shall provide these operations for all container types shown in the “container” column, and shall implement them so as to take amortized constant time.

Where Table 101 is named Optional sequence container operations and lists deque for the push_back and push_front operations.

Therefore, it seems more like a slight omission in the paragraph you cited. Perhaps worth a Defect Report ?

Note that the single call to a constructor still holds.

I suspect that the reallocation of the block pointers is done with a geometrically increasing size - this is a common trick for std::vector. I think this is technically O(log m) but as you point out m << n, so as a practical matter it doesn't affect the real-world results.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!