gpt4 book ai didi

c++ - vector::erase 会减少 vector::capacity 吗?

转载 作者:太空狗 更新时间:2023-10-29 19:37:20 24 4
gpt4 key购买 nike

Cppreference 只说:

Removes specified elements from the container. 1) Removes the element at pos. 2) Removes the elements in the range [first; last).

Invalidates iterators and references at or after the point of the erase, including the end() iterator.

The iterator pos must be valid and dereferenceable. Thus the end() iterator (which is valid, but is not dereferencable) cannot be used as a value for pos.

The iterator first does not need to be dereferenceable if first==last: erasing an empty range is a no-op.

最佳答案

不一定。在阅读 C++ 标准(并且 cppreference 非常好地代理标准)时,如果没有明确提及某些内容,则假设不需要这样的内容。

这样做对于 C++ 标准库实现来说可能不是最优的。

关于c++ - vector::erase 会减少 vector::capacity 吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50599555/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com