C++ Logo

std-discussion

Advanced search

[Potential defect] std::vector::push_back reallocation wording

From: Florian Mayer <florian.mayer_at_[hidden]>
Date: Tue, 30 Jun 2020 13:52:43 +0200
Hi everyone!

I noticed something while reading the standard.

The Remarks for push_back / emplace_back [1] in all the standards from
C++11 to the current draft say

> Remarks: Causes reallocation if the new size is greater than the old
capacity

Logically, this means 'size > capacity IMPLIES rellocation'. By ex falso
quodlibet, this means that rellocations can happen even if size <=
capacity, but it also means that a reallocation HAS to happen if size >
capacity.

I am pretty sure that is not the intention, and it should say "Causes
reallocation *only* if the new size is greater than the old capacity."

Is that correct?

Thanks,
Florian

[1]: http://eel.is/c++draft/vector#modifiers-1.sentence-1

Received on 2020-06-30 06:56:06