std::forward_list<T,Allocator>::max_size
來自 cppreference.com
< cpp | 容器 | forward_list
size_type max_size() const noexcept; |
(C++11 起) | |
返回容器能容納的最大元素數量,該限制由系統或庫實現決定。即,對於最大的容器,該值為 std::distance(begin(), end())。
目錄 |
[編輯] 返回值
最大元素數量。
[編輯] 複雜度
常數時間。
[編輯] 注意
這個值通常反映容器大小的理論上限,至多為 std::numeric_limits<difference_type>::max()。在執行時,容器的大小可能會因可用記憶體量的限制而小於 max_size()
。
[編輯] 示例
執行此程式碼
#include <iostream> #include <locale> #include <forward_list> int main() { std::forward_list<char> p; std::forward_list<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() = 1,152,921,504,606,846,975 = 0xFFF,FFF,FFF,FFF,FFF q.max_size() = 1,152,921,504,606,846,975 = 0xFFF,FFF,FFF,FFF,FFF