Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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)

like image 608
Ben Voigt Avatar asked Nov 12 '13 22:11

Ben Voigt


1 Answers

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.

enter image description here

 

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

like image 143
masoud Avatar answered Sep 29 '22 03:09

masoud