std::deque::max_size(3)

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

πŸ’… std::deque::max_size(3) β€” C++ Standard Libary ✨

okay bestie, so this one is from the C++ Standard Libary (yes that's how it's spelled in the header, don't come for me 🫢) and it's literally just a little page about asking your deque "hey, how much stuff could you hold, theoretically?"


🌸 NAME 🌸

std::deque::max_size β€” which is, and I cannot stress this enough, std::deque::max_size πŸ’–


✨ Synopsis ✨

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

so what it does is it returns the maximum number of elements the container is able to hold due to system or library implementation limitations β€” like, that's std::distance(begin(), end()) for the largest container that could ever exist. it's giving "theoretical maximum" energy πŸ‘‘


πŸŽ€ Parameters πŸŽ€

  • (none) β€” literally nothing, it takes zero arguments, an absolute icon of minimalism πŸ™ˆ

πŸ¦‹ Return value πŸ¦‹

Maximum number of elements. that's it, that's the whole vibe ✨


🌈 Complexity 🌈

Constant. no loops, no searching, no nonsense β€” she's fast, periodt πŸ’…


πŸ’œ Notes πŸ’œ

okay this is the important part, listen up 🧚

This value typically reflects the theoretical limit on the size of the container, at most std::numeric_limits<difference_type>::max(). So like, the ceiling of the ceiling.

But ngl β€” at runtime, the size of the container may be limited to a value smaller than max_size() by the amount of RAM available. so the theoretical number is cute and all, but your actual RAM said "bestie, no" 😭

πŸ”₯ Example πŸ”₯

run this code, trust:

#include <iostream>
#include <locale>
#include <deque>

int main()
{
    std::deque<char> p;
    std::deque<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() = 9,223,372,036,854,775,807 = 0x7,FFF,FFF,FFF,FFF,FFF
q.max_size() = 2,305,843,009,213,693,951 = 0x1,FFF,FFF,FFF,FFF,FFF

look at those big numbers, she ate and left absolutely no crumbs πŸ‘‘πŸ”₯


πŸ“ See also πŸ“

  • size β€” returns the number of elements (public member function) β€” the actual count, not the dream count, iykyk πŸ’«

✨ cute sign-off time ✨

this lil masterpiece came from http://cppreference.com, dated 2024.06.10, and it's the std::deque::max_size(3) page β€” go forth and flex your deque knowledge, bestie, you're the main character now πŸŒΈπŸ«ΆπŸ’–

πŸ“¦ where this page comes from