std::vector<T,Allocator>::max_size
来自 cppreference.cn
size_type max_size() const; |
(noexcept since C++11) (constexpr since C++20) |
|
Returns the maximum number of elements the container is able to hold due to system or library implementation limitations, i.e. std::distance(begin(), end()) for the largest container.
目录 |
[edit] 返回值
元素的最大数量。
[edit] 复杂度
常数。
[edit] 注意
此值通常反映容器大小的理论限制,最多为 std::numeric_limits<difference_type>::max()。 在运行时,容器的大小可能受可用 RAM 数量的限制,而小于 max_size()
。
[edit] 示例
运行此代码
#include <iostream> #include <locale> #include <vector> int main() { std::vector<char> p; std::vector<long> q; std::cout.imbue(std::locale("en_US.UTF-8")); std::cout << std::uppercase << "p.max_size() = " << std::dec << p.max_size() << " = 0x" << std::hex << p.max_size() << '\n' << "q.max_size() = " << std::dec << q.max_size() << " = 0x" << std::hex << q.max_size() << '\n'; }
可能的输出
p.max_size() = 9,223,372,036,854,775,807 = 0x7,FFF,FFF,FFF,FFF,FFF q.max_size() = 1,152,921,504,606,846,975 = 0xFFF,FFF,FFF,FFF,FFF
参见
返回元素数量 (公共成员函数) | |
返回当前已分配存储中可以容纳的元素数量 (公共成员函数) |