STD::STACK(3cxx)

πŸ’– std::stack< _Tp, _Sequence > β€” the FILO queen πŸ‘‘

Okay bestie, so std::stack< _Tp, _Sequence > is literally the moment you need FILO behavior β€” first in, last out, no cap. It's giving iconic container adapter energy. πŸ’…


✨ NAME ✨

std::stack< _Tp, _Sequence > β€” a standard container giving FILO behavior. Periodt.


πŸŽ€ SYNOPSIS πŸŽ€

#include <stack>

🌸 Public Types 🌸

  • typedef _Sequence::const_reference const_reference β€” a read-only reference to an element, lowkey useful.
  • typedef _Sequence container_type β€” the type of the underlying sequence, the vibe underneath.
  • typedef _Sequence::reference reference β€” a read/write reference to an element, main character energy.
  • typedef _Sequence::size_type size_type β€” the type used for sizes, fr fr.
  • typedef _Sequence::value_type value_type β€” the type of the elements, the whole point.

πŸ¦‹ Public Member Functions πŸ¦‹

  • template<typename _Seq = _Sequence, typename _Requires = typename enable_if<is_default_constructible<_Seq>::value>::type> stack () β€” default constructor creates no elements. It's giving empty stack, iconic.
  • stack (_Sequence &&__c) β€” move-constructs from a sequence, slay.
  • template<typename _Alloc , typename _Requires = _Uses<_Alloc>> stack (_Sequence &&__c, const _Alloc &__a) β€” move-constructs from a sequence with an allocator, cute.
  • template<typename _Alloc , typename _Requires = _Uses<_Alloc>> stack (const _Alloc &__a) β€” constructs with an allocator, no elements yet.
  • stack (const _Sequence &__c) β€” copy-constructs from a sequence, highkey useful.
  • template<typename _Alloc , typename _Requires = _Uses<_Alloc>> stack (const _Sequence &__c, const _Alloc &__a) β€” copy-constructs from a sequence with an allocator.
  • template<typename _Alloc , typename _Requires = _Uses<_Alloc>> stack (const stack &__q, const _Alloc &__a) β€” copy-constructs from another stack with an allocator, bestie behavior.
  • template<typename _Alloc , typename _Requires = _Uses<_Alloc>> stack (stack &&__q, const _Alloc &__a) β€” move-constructs from another stack with an allocator.
  • template<typename... _Args> decltype(auto) emplace (_Args &&... __args) β€” constructs an element in-place at the top, fancy.
  • bool empty () const β€” returns true if the stack is empty, literally.
  • void pop () β€” removes the first element. More on this below, bestie. πŸ‘‡
  • void push (const value_type &__x) β€” add data to the top of the stack. The classic.
  • void push (value_type &&__x) β€” add data to the top of the stack, but move it. Efficient.
  • size_type size () const β€” returns the number of elements in the stack, ofc.
  • void swap (stack &__s) noexcept(__is_nothrow_swappable< _Sequence >::value) β€” swaps the contents, no cap.
  • reference top () β€” returns a read/write reference to the data at the first element of the stack.
  • const_reference top () const β€” returns a read-only (constant) reference to the data at the first element of the stack.

πŸ’œ Protected Attributes πŸ’œ

  • _Sequence c β€” the underlying container, the real MVP.

🌈 Friends 🌈

  • template<typename _Tp1 , typename _Seq1 > bool operator< (const stack< _Tp1, _Seq1 > &, const stack< _Tp1, _Seq1 > &) β€” less-than comparison, lowkey.
  • template<typename _Tp1 , three_way_comparable _Seq1> compare_three_way_result_t< _Seq1 > operator<=> (const stack< _Tp1, _Seq1 > &, const stack< _Tp1, _Seq1 > &) β€” three-way comparison, spaceship operator vibes. πŸš€
  • template<typename _Tp1 , typename _Seq1 > bool operator== (const stack< _Tp1, _Seq1 > &, const stack< _Tp1, _Seq1 > &) β€” equality comparison, fr fr.

πŸ”₯ Detailed Description πŸ”₯

Okay so here's the tea: template<typename _Tp, typename _Sequence = deque<_Tp>> class std::stack< _Tp, _Sequence > is a standard container giving FILO behavior. It's not a true container, it's an adaptor β€” it holds another container and provides a wrapper interface to that container. The wrapper is what enforces strict first-in-last-out stack behavior. Periodt.

🧚 Template Parameters 🧚

  • _Tp β€” type of element. The whole point, bestie. πŸ’–
  • _Sequence β€” type of underlying sequence, defaults to deque<_Tp>. You can swap it out, iykyk.

It meets many of the requirements of a container, but does not define anything to do with iterators. Very few of the other standard container interfaces are defined. It's giving minimal, and honestly? Obsessed.

The second template parameter defines the type of the underlying sequence/container. It defaults to std::deque, but 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. So versatile, slay.

Members not found in normal containers are container_type, which is a typedef for the second Sequence parameter, and push, pop, and top, which are standard stack/FILO operations. They ate that. πŸ’…


🫢 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. It's literally an empty stack, and it's iconic.


πŸ’€ Member Function Documentation πŸ’€

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

Returns true if the stack is empty. No cap, simple as 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.

⚠️ Bestie, listen: no data is returned! If the first element's data is needed, it should be retrieved before pop() is called. Do not come for me when you lose your data, fr fr. 😭

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. 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.

Parameters

  • __x β€” Data to be added. The whole point.

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

Returns the number of elements in the stack. Lowkey useful.

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

Returns a read/write reference to the data at the first element of the stack. Main character access. πŸ’…

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

Returns a read-only (constant) reference to the data at the first element of the stack. Peek but don't touch, cute.


πŸ‘‘ Author πŸ‘‘

Generated automatically by Doxygen for libstdc++ from the source code. Not me writing it by hand, but I respect the hustle.


That's the whole vibe, bestie. This page is from libstdc++ and it's giving std::stack< _Tp, _Sequence >(3cxx) energy, dated the same as the original. Stay slay, stay stacked, and remember: FILO is the only way. πŸ¦‹βœ¨

πŸ“¦ where this page comes from