Formal specification of std::vector<T>::pop_back

时光总嘲笑我的痴心妄想 提交于 2019-12-21 10:47:30

问题


I'm looking in the C++ Standard (draft n3797), and I can't find any documentation of pop_back as it applies to std::vector, only for std::list. Is it really missing?

Specifically I was looking for the guarantee that pop_back doesn't change the capacity. Or is there such a guarantee at all? (I expect that iterators and references to other elements will remain valid, but I can't find that guarantee, and it wouldn't restrict the case of removing the last element, anyway)


回答1:


No it doesn't missed. In a table in 101 §23.2.3, you can see pop_back exists for vector.

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.

 

Paragraph 16 mentioned they should implement to take amortized constant time.



来源:https://stackoverflow.com/questions/19941601/formal-specification-of-stdvectortpop-back

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