std::set<Key,Compare,Allocator>::max_size
来自cppreference.com
size_type max_size()const; | (C++11 起为 noexcept) (C++26 起为 constexpr) | |
返回容器根据系统或库实现限制而可保有的元素最大数量,即对于最大容器的 std::distance(begin(), end())。
目录 |
[编辑]返回值
元素数量的最大值。
[编辑]复杂度
常数。
[编辑]注解
此值通常反映容器大小上的理论极限,至多为 std::numeric_limits<difference_type>::max()。运行时,可用 RAM 总量可能会限制容器大小到小于 max_size()
的值。
[编辑]示例
运行此代码
#include <iostream>#include <locale>#include <set> int main(){std::set<char> p;std::set<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() = 461,168,601,842,738,790 = 0x666,666,666,666,666 q.max_size() = 461,168,601,842,738,790 = 0x666,666,666,666,666
参阅
返回元素数 (公开成员函数) |