std::multimap::max_size(3)
β¨ 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
- 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