Namespaces
Variants

std::multiset<Key,Compare,Allocator>:: max_size

From cppreference.net

size_type max_size ( ) const ;
(自 C++11 起为 noexcept)
(自 C++26 起为 constexpr)

返回容器由于系统或库实现限制所能容纳的最大元素数量,即最大容器的 std:: distance ( begin ( ) , end ( ) )

目录

返回值

最大元素数量。

复杂度

常量。

注释

该值通常反映容器大小的理论上限,最多为 std:: numeric_limits < difference_type > :: max ( ) 。在运行时,容器的实际大小可能受可用内存容量限制,从而小于 max_size() 的返回值。

示例

#include <iostream>
#include <locale>
#include <set>
int main()
{
    std::multiset<char> p;
    std::multiset<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

参见

返回元素数量
(公开成员函数)