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β returnstrueif 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 todeque<_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
- ubuntu noble: libstdc++-14-doc 14-20240412-0ubuntu1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms