std::forwar...st::max_size(3)
πΈ std::forward_list::max_size β¨
okay so this is the std::forward_list::max_size page from the C++ Standard Libary β yes bestie, that's the C++ Standard Libary, the typo is canon now, we don't fix it, we respect it π
. It lives in the std::forwar...st::max_size(3) section of the manual (the middle got ate by the manpage formatter, it's giving "my name is elided for your convenience" energy π).
π NAME π
std::forward_list::max_size β literally just std::forward_list::max_size. That's it. That's the name. Iconic minimalism π.
π¦ Synopsis π¦
size_type max_size() const noexcept; (since C++11)
okay so what does it actually do? It returns the maximum number of elements the container is able to hold due to system or library implementation limitations, i.e. std::distance(begin(), end()) for the largest container. like, the absolute theoretical ceiling, the final boss of how much this thing can carry π.
π Parameters π
(none) β she takes nothing, she gives everything, no cap β¨.
π Return value π
Maximum number of elements. that's the whole return value. a number. a big one, probably. slay π₯.
π§ Complexity π§
Constant. O(1) behavior, we love a low-effort queen π .
π Notes π
okay so listen, this is the important bit π«Ά β this value typically reflects the theoretical limit on the size of the container, at most std::numeric_limits<difference_type>::max().
β οΈ at runtime, the size of the container may be limited to a value smaller than max_size() by the amount of RAM available. so like, she could hold that much, but your laptop said "bestie no" ππ
β Example β
// Run this code β go off, run it, live your truth πΈ
#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';
}
π₯ Possible output π₯
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
look at those numbers. one quintillion and change. she ate and left absolutely zero crumbs π
β¨. and notice both char and long give the exact same answer β the implementation-level limit is what's talking here, not the element size, iykyk π¦.
π cute little sign-off π β this whole vibe check came fromhttp://cppreference.com, dated2024.06.10, filed understd::forwar...st::max_size(3). go forth and query your sizes, bestie, ily π«Άπ
π¦ where this page comes from
- nixpkgs unstable: stdman 2024.07.05
- opensuse-leap 16.0: stdman 2024.07.05-bp160.1.9 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms