c++ - max_size返回一个大于或等于该类型容器所能容纳的最大元素数的值?
迷茫
迷茫 2017-04-17 12:07:46
0
1
822

这是c++ primer中讲到容器大小一节时说的一句话,什么叫大于最大值?感觉错的太离谱了吧
英文版如下:
and max_size returns a number that is greater than or equal to the number of elements a container of that type can contain.

迷茫
迷茫

业精于勤,荒于嬉;行成于思,毁于随。

全員に返信(1)
迷茫

查了 DevDocs, 它在 std::vector::max_size 条目上如此定义 max_size:

Returns the maximum number of elements the container is able to hold due to system or library implementation limitations,...

然而 Notes 却提到:

This value is typically equal to std::numeric_limits<size_type>::max(), and reflects the theoretical limit on the size of the container. At runtime, the size of the container may be limited to a value smaller than max_size() by the amount of RAM available.

所以虽说软件上的 max_size 只受限于操作系统或库实现,然而运行时容器所能容纳的元素数量却可能由于硬件上的内存空间过小,而小于 max_size.

いいねを押す +0
人気のチュートリアル
詳細>
最新のダウンロード
詳細>
ウェブエフェクト
公式サイト
サイト素材
フロントエンドテンプレート
私たちについて 免責事項 Sitemap
PHP中国語ウェブサイト:福祉オンライン PHP トレーニング,PHP 学習者の迅速な成長を支援します!