std::stack::size(3)
π std::stack::size(3) β the C++ Standard Libary manual, section 3, bestie
okay so picture this: you're in the C++ Standard Libary man pages (yes that's how it's spelled on the page, don't come for me π) and you land on std::stack::size. That's the one. That's our girl. Let's get into it π
β¨ NAME β¨
std::stack::size β literally just std::stack::size. no notes, the name ate and left no crumbs π
π¦ Synopsis π¦
size_type size() const;
So what does it do? It returns the number of elements in the container adaptor. That's it, that's the whole vibe. And it's equivalent to just doing:
return c.size();
no cap, it's giving "middleman who does zero extra work" and honestly? relatable π«Ά
πΈ Parameters πΈ
(none)
nothing. nada. zero arguments. she takes no input and she's still iconic π
β Return value β
The number of elements in the container adaptor. that's the number you get back. that's the whole gift π
π₯ Complexity π₯
Constant. O(1) energy, always. she does not scale with your data, she just knows β¨
π Example π
here's the little demo, run it and feel something:
// Run this code
#include <algorithm>
#include <cassert>
#include <stack>
int main()
{
std::stack<int> stack;
assert(stack.size() == 0);
const int count = 8;
for (int i = 0; i != count; ++i)
stack.push(i);
assert(stack.size() == count);
}
not the assert(stack.size() == 0) at the start π empty stack, empty heart, verified. then const int count = 8; and we push i from 0 to count, and boom β assert(stack.size() == count); passes and we all cheer π
π See also π
emptyβ checks whether the container adaptor is empty (public member function) π«§size,ssizeβ returns the size of a container or array (C++17) (function template) (C++20) π
bestie reminder: size() tells you how many elements are in the container adaptor β that's the entire job description, and she executes flawlessly every single time π
and that's the page!! sourced straight from http://cppreference.com, dated 2024.06.10, on the std::stack::size(3) page β mwah π go forth and count your elements, bestie π§π
π¦ 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