std::forwar...st::max_size(3)

πŸ“¦ version 2024.07.05, in nixpkgs unstable, opensuse-leap 16.0

🌸 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 from http://cppreference.com, dated 2024.06.10, filed under std::forwar...st::max_size(3). go forth and query your sizes, bestie, ily πŸ«ΆπŸŽ€
πŸ“¦ where this page comes from