最終更新日時(UTC):
が更新

履歴 編集

function
<memory>

std::allocator_traits::max_size(C++11)

static size_type max_size(Alloc& a);                            // C++11
static size_type max_size(const Alloc& a) noexcept;             // C++14 から C++ 17 まで
static constexpr size_type max_size(const Alloc& a) noexcept;    // C++20 から

概要

一度に確保可能なメモリの最大サイズを取得する。

戻り値

a.max_size()という式が有効ならその戻り値を返し、そうでなければデフォルト実装として以下を返す:

std::numeric_limits<size_type>::max() / sizeof(value_type)

#include <iostream>
#include <memory>

int main()
{
  std::allocator<int> alloc;
  using traits = std::allocator_traits<decltype(alloc)>;

  std::cout << traits::max_size(alloc) << std::endl;
}

出力例

4611686018427387903

バージョン

言語

  • C++11

処理系

参照

参照