gpt4 book ai didi

c++ - vector::max_size 的实际使用

转载 作者:可可西里 更新时间:2023-11-01 18:29:43 24 4
gpt4 key购买 nike

question让我想到了 vector 类中的 max_size 方法。很明显,实际上 vector 中包含的元素数量将比 max_size 返回的元素数量少得多。所以我想知道这在哪里有用?有什么线索吗?

最佳答案

它真的不是很有用。

唯一的理论上的用法是检查您是否需要一个大于 max_size() 的容器,您就有麻烦了。但是在考虑将数据库服务器端口连接到微波炉时,您可能已经意识到这一点。

委员会曾考虑改进该功能,但发现它的用处不足以值得更改:

max_size() isn't useful for very many things, and the existing wording is sufficiently clear for the few cases that max_size() can be used for. None of the attempts to change the existing wording were an improvement.

http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-closed.html#197

关于c++ - vector::max_size 的实际使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9867206/

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