STD::STACK(3)

πŸ’– std::stack< _Tp, _Sequence > πŸ’–

okay so bestie, we are in the Library Functions Manual, section 3, and today's main character is std::stack< _Tp, _Sequence > β€” yes, the page header literally prints it as std::stack...Sequence >(3) because the manpage generator got shy about angle brackets, but it's this one, and she ate. 🫢


πŸŽ€ NAME πŸŽ€

std::stack< _Tp, _Sequence > β€” a standard container giving FILO behavior. (first in, last out. the drama. the structure. πŸ’…)


✨ SYNOPSIS ✨

#include <stack>

🌸 Public Types 🌸

  • const_reference β€” typedef _Sequence::const_reference const_reference
  • container_type β€” typedef _Sequence container_type
  • reference β€” typedef _Sequence::reference reference
  • size_type β€” typedef _Sequence::size_type size_type
  • value_type β€” typedef _Sequence::value_type value_type

πŸ’… Public Member Functions πŸ’…

no cap, here they all are, verbatim, every single one:

template<typename _Seq = _Sequence, typename _Requires = typename
    enable_if<is_default_constructible<_Seq>::value>::type> stack ()
    Default constructor creates no elements.
template<typename _InputIterator, typename _Alloc, typename =
    _RequireInputIter<_InputIterator>, typename = _Uses<_Alloc>> stack
    (_InputIterator __first, _InputIterator __last, const _Alloc &__a)
stack (_Sequence &&__c)
template<typename _Alloc, typename _Requires = _Uses<_Alloc>> stack
    (_Sequence &&__c, const _Alloc &__a)
template<typename _Alloc, typename _Requires = _Uses<_Alloc>> stack
    (const _Alloc &__a)
stack (const _Sequence &__c)
template<typename _Alloc, typename _Requires = _Uses<_Alloc>> stack
    (const _Sequence &__c, const _Alloc &__a)
template<typename _Alloc, typename _Requires = _Uses<_Alloc>> stack
    (const stack &__q, const _Alloc &__a)
template<typename _Alloc, typename _Requires = _Uses<_Alloc>> stack
    (stack &&__q, const _Alloc &__a)
template<typename... _Args> decltype(auto) emplace (_Args &&... __args)
bool empty () const
void pop ()
    Removes first element.
void push (const value_type &__x)
    Add data to the top of the stack.
void push (value_type &&__x)
size_type size () const
void swap (stack &__s) noexcept(__is_nothrow_swappable< _Sequence
    >::value)
reference top ()
const_reference top () const

like… look at that constructor family. a whole dynasty. πŸ‘‘

πŸ”’ Protected Attributes πŸ”’

  • _Sequence c β€” yes queen, the actual container is sitting right there, protected, doing the real work. πŸ™ˆ

🫢 Friends 🫢

  • template<typename _Tp1, typename _Seq1> bool operator< (const stack< _Tp1, _Seq1 > &, const stack< _Tp1, _Seq1 > &)
  • template<typename _Tp1, three_way_comparable _Seq1> compare_three_way_result_t< _Seq1 > operator<=> (const stack< _Tp1, _Seq1 > &, const stack< _Tp1, _Seq1 > &)
  • template<typename _Tp1, typename _Seq1> bool operator== (const stack< _Tp1, _Seq1 > &, const stack< _Tp1, _Seq1 > &)

🌈 Detailed Description 🌈

template<typename _Tp, typename _Sequence = deque<_Tp>>
    class std::stack< _Tp, _Sequence >"A standard container giving FILO
    behavior.

(yeah there's a stray " in there, that's literally how the source page prints it, i'm not touching it, it's iconic now πŸ’€)

🧚 Template Parameters 🧚

  • _Tp β€” type of element.
  • _Sequence β€” type of underlying sequence, defaults to deque<_Tp>.

so here's the tea, bestie. she meets many of the requirements of a container, but she does not define anything to do with iterators. very few of the other standard container interfaces are defined either. she's selective. she's mysterious. πŸ¦‹

this is not a true container, but an adaptor. it holds another container, and provides a wrapper interface to that container. and the wrapper is the thing that enforces strict first-in-last-out stack behavior. the wrapper is the bouncer. periodt. πŸ’…

the second template parameter defines the type of the underlying sequence/container. it defaults to std::deque, but honestly it can be any type that supports back, push_back, and pop_back β€” such as std::list, std::vector, or an appropriate user-defined type of your own making. you do you, babe. ✨

members not found in normal containers are container_type (which is a typedef for the second Sequence parameter), plus push, pop, and top β€” the standard stack/FILO operations. those three are her whole personality and she's thriving. 🌸


🌟 Constructor & Destructor Documentation 🌟

template<typename _Tp, typename _Sequence = deque<_Tp>> template<typename _Seq = _Sequence, typename _Requires = typename enable_if<is_default_constructible<_Seq>::value>::type> std::stack< _Tp, _Sequence >::stack () [inline]

Default constructor creates no elements. empty stack, zero notes, clean slate energy. πŸŽ€


πŸ’œ Member Function Documentation πŸ’œ

template<typename _Tp, typename _Sequence = deque<_Tp>> bool std::stack< _Tp, _Sequence >::empty () const [inline], [nodiscard]

Returns true if the stack is empty. she's honest like that.

template<typename _Tp, typename _Sequence = deque<_Tp>> void std::stack< _Tp, _Sequence >::pop () [inline]

Removes first element. this is a typical stack operation. it shrinks the stack by one. the time complexity of the operation depends on the underlying sequence. ⏳

WARNING β€” note that no data is returned, and if the first element's data is needed, it should be retrieved before pop() is called. so grab your snack before you close the fridge, bestie. 😭

template<typename _Tp, typename _Sequence = deque<_Tp>> void std::stack< _Tp, _Sequence >::push (const value_type & __x) [inline]

Add data to the top of the stack. πŸ”₯

Parameters

  • __x β€” data to be added.

this is a typical stack operation. the function creates an element at the top of the stack and assigns the given data to it. the time complexity of the operation depends on the underlying sequence. very "new bestie just arrived at the top of the group chat" of her. πŸ’…

template<typename _Tp, typename _Sequence = deque<_Tp>> size_type std::stack< _Tp, _Sequence >::size () const [inline], [nodiscard]

Returns the number of elements in the stack. the headcount. the roster. πŸ‘‘

template<typename _Tp, typename _Sequence = deque<_Tp>> reference std::stack< _Tp, _Sequence >::top () [inline], [nodiscard]

Returns a read/write reference to the data at the first element of the stack. you can look and you can touch. 😌

template<typename _Tp, typename _Sequence = deque<_Tp>> const_reference std::stack< _Tp, _Sequence >::top () const [inline], [nodiscard]

Returns a read-only (constant) reference to the data at the first element of the stack. look, don't touch. πŸ’…


πŸ¦‹ Author πŸ¦‹

Generated automatically by Doxygen for libstdc++ from the source code.


okay that's the whole page, bestie, we made it. πŸ₯Ή this little corner of the Library Functions Manual, section 3, ships with libstdc++, and yeah the footer is just libstdc++ plus the std::stack...Sequence >(3) title again β€” no fancy date, no version number, just vibes and the C++ standard library. stan a low-maintenance footer. πŸŒˆβœ¨πŸ’–

πŸ“¦ where this page comes from
  • arch rolling: gcc 16.2.1+r23+gd564253eb6c8-1 Β· GPL-3.0-or-later WITH GCC-exception-3.1 AND GFDL-1.3-or-later
  • fedora 44: libstdc++-docs 16.2.1-2.fc44
  • fedora 44: libstdc++-docs 16.2.1-3.fc44 Β· GPL-3.0-or-later AND LGPL-3.0-or-later AND (GPL-3.0-or-later WITH GCC-exception-3.1) AND (GPL-3.0-or-later WITH Texinfo-exception) AND (LGPL-2.1-or-later WITH GCC-exception-2.0) AND (GPL-2.0-or-later WITH GCC-exception-2.0) AND (GPL-2.0-or-later WITH GNU-compiler-exception) AND BSL-1.0 AND GFDL-1.3-or-later AND Linux-man-pages-copyleft-2-para AND SunPro AND BSD-1-Clause AND BSD-2-Clause AND BSD-2-Clause-Views AND BSD-3-Clause AND BSD-4-Clause AND BSD-Source-Code AND Zlib AND MIT AND Apache-2.0 AND (Apache-2.0 WITH LLVM-Exception) AND ZPL-2.1 AND ISC AND LicenseRef-Fedora-Public-Domain AND HP-1986 AND curl AND Martin-Birgmeier AND HPND-Markus-Kuhn AND dtoa AND SMLNJ AND AMD-newlib AND OAR AND HPND-merchantability-variant AND HPND-Intel
  • πŸ’– girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms