size_type max_size() const; // (1) C++03
size_type max_size() const noexcept; // (1) C++11
constexpr size_type max_size() const noexcept; // (1) C++20
概要
コンテナに格納可能な最大数を取得する。
戻り値
コンテナに格納可能な最大数
例外
投げない
計算量
定数時間
例
#include <iostream>
#include <vector>
int main()
{
std::vector<int> v;
std::size_t s = v.max_size();
std::cout << s << std::endl;
}
出力例
4611686018427387903