std::flat_set::max_size(3)

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

πŸ’… 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) β€” like max_size but 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