std::unorde...t::max_size(3)
π NAME
std::unordered_set::max_size β literally what it says on the tin, bestie: the max size. That's the whole vibe. π
Oh and just so we're clear, we're moving through the C++ Standard Libary today, mwah.
β¨ Synopsis
size_type max_size() const noexcept; (since C++11)
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. That's the biggest one. The final boss container. π
πΈ Parameters
None. Nada. Zero. Nothing to pass in β she works alone, main character energy fr fr. π
π Return value
The maximum number of elements. That's it, that's the return. π«Ά
β‘ Complexity
Constant. Like, O(1) constant, no cap β she's not out here doing loops. Iconic behaviour honestly.
π¦ Notes
Okay so this value typically reflects the theoretical limit on the size of the container β at most std::numeric_limits<difference_type>::max(). Key word: theoretical. π
At runtime though, the size of the container may be limited to a value smaller than max_size() by the amount of RAM available. So like, your dreams may be bigger than your memory. Story of my life. π
π Example
// Run this code
#include <iostream>
#include <locale>
#include <unordered_set>
int main()
{
std::unordered_set<char> p;
std::unordered_set<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. Comma-separated. Hex on the side. It's giving flex, honestly. π₯
π See also
sizeβ returns the number of elements (public member function)
<div style="text-align:center">β π§ β</div>
Okay bestie that's the whole page! This came straight from http://cppreference.com and it's dated 2024.06.10, so if anything looks different later, don't come for me. Go forth and check your max_size(), you got this πβ¨
π¦ 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