std::flat_set::max_size(3)
π std::flat_set::max_size(3)
okay so bestie, welcome to the std::flat_set::max_size page β yes the title is the same as the thing, iconic, we love a self-titled moment π
this one lives in the C++ Standard Libary (that's the manual name, no i'm not fixing the spelling, it's part of the lore π«Ά) and it's literally all about asking your flat_set "hey girl, how much can you hold?"
β¨ Synopsis β¨
size_type max_size() const noexcept; (since C++23)
so the way this works: 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 theoretical biggest girlie. the final boss size. no cap π
also noexcept?? she doesn't throw. she doesn't do drama. main character energy fr fr β¨
π Parameters π
none babes. zero. zilch. you don't pass her anything, she just knows π
πΈ Return value πΈ
the maximum number of elements. that's it, that's the whole tea π
π¦ Complexity π¦
Constant. like, instant. she's not doing a whole loop for you, she just produces the number. ate and left no crumbs π₯
π Notes π
okay so this is the important bit, listen up:
this value typically reflects the theoretical limit on the size of the container, at most std::numeric_limits<difference_type>::max().
but likeβ¦ at runtime, the size of the container may be limited to a value smaller than max_size() by the amount of RAM available π so don't go thinking you can actually hold that many, your laptop will simply pass away π
β Example β
// Run this code
#include <iostream>
#include <flat_set>
#include <locale>
int main()
{
std::flat_set<char> q;
std::cout.imbue(std::locale("en_US.UTF-8"));
std::cout << "Maximum size of a std::flat_set is " << q.max_size() << '\n';
}
lowkey obsessed with this little demo, it's giving "hello world but make it existential" π
π Possible output π
Maximum size of a std::flat_set is 768,614,336,404,564,650
yeah. that's a big number. that's a big number. she's huge π
π See also π
sizeβ returns the number of elements (public member function) β likemax_sizebut for what you actually got, iykyk π
<div>π§ and that's the whole page bestie!! this lil gem comes to you courtesy of http://cppreference.com, version 2024.06.10 β dated 2024.06.10 (yes same day, she's punctual π
). now go flex that max_size() on somebody π«Άβ¨</div>
π¦ 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