std::multimap::max_size(3)

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

✨ std::multimap::max_size ✨

okay so this is a page straight out of the C++ Standard Library bestie, and today's main character is std::multimap::max_size. yes it's a whole mouthful, no we're not skipping it, let's go πŸ’…


🌸 SYNOPSIS 🌸

size_type max_size() const;  (noexcept since C++11)

bestie. it returns the maximum number of elements the container is able to hold, and that cap comes from system or library implementation limitations β€” like, it's not the container being picky, it's the world it lives in. think of it as std::distance(begin(), end()) for the largest container imaginable πŸ¦‹

πŸ’– PARAMETERS πŸ’–

  • (none) β€” literally nothing, she takes zero arguments, icon behavior

πŸŽ€ RETURN VALUE πŸŽ€

Maximum number of elements. that's it, that's the whole vibe check πŸ’«

🧚 COMPLEXITY 🧚

Constant. as in O(1) constant, she's not out here looping, she just knows πŸ’…

✨ NOTES ✨

ngl this is the fun part. this value typically reflects the theoretical limit on the size of the container, at most std::numeric_limits<difference_type>::max(). so yeah, theoretically huge.

but at runtime, the actual size of the container may be limited to a value smaller than max_size() by the amount of RAM available 😭 so like… theory says yes, your RAM says absolutely not. reality check fr fr πŸ’€

πŸ“ EXAMPLE πŸ“

run this code bestie:

#include <iostream>
#include <locale>
#include <map>

int main()
{
    std::multimap<char, char> p;
    std::multimap<long, char> 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() = 461,168,601,842,738,790 = 0x666,666,666,666,666
q.max_size() = 384,307,168,202,282,325 = 0x555,555,555,555,555

look at those numbers. 0x666,666,666,666,666 and 0x555,555,555,555,555 β€” the hexadecimal ate, honestly πŸ”₯ those digits are giving cursed-but-beautiful, iykyk πŸ‘‘

πŸ’œ SEE ALSO πŸ’œ

  • size β€” returns the number of elements (public member function). like her chill cousin who tells you how many elements you actually have, not how many you could have 🫢

and that's the page, bestie πŸ’– huge thank you to cppreference.com, dated 2024.06.10, for serving us std::multimap::max_size(3) with zero crumbs left behind β€” she's iconic, she's constant-time, she's the theoretical queen of container capacity πŸ‘‘βœ¨πŸŒˆ

πŸ“¦ where this page comes from