C++ forward_list 庫 - max_size() 函式



描述

C++ 函式std::forward_list::max_size() 返回 forward_list 可以容納的最大元素數量。此值取決於系統或庫的實現。

宣告

以下是來自 std::forward_list 標頭檔案的 std::forward_list::max_size() 函式的宣告。

C++11

size_type max_size () const noexcept;

引數

返回值

返回可以放入 forward_list 的最大數量。

異常

此成員函式從不丟擲異常。

時間複雜度

常數,即 O(1)

示例

以下示例顯示了 std::forward_list::max_size() 函式的使用方法。

#include <iostream>
#include <forward_list>

using namespace std;

int main(void) {
   forward_list<int> fl;

   cout << "max_size of list = " << fl.max_size() << endl;

   return 0;
}

讓我們編譯並執行上述程式,這將產生以下結果:

max_size of list = 1152921504606846975
forward_list.htm
廣告

© . All rights reserved.