std/stack
March 17, 2026 ยท View on GitHub
Generic stack (LIFO) data structure with dynamic resizing.
Types
std::stack
Generic stack structure.
Conditions: T must not be void.
Fields:
T* data- Stack data arrayusize capacity- Allocated capacity in bytesusize length- Number of elements
Methods
Constructor
std::stack<T> this()
std::stack<T> this(T* data, usize size)
Creates empty stack or initializes from array.
push
void push(T value)
Pushes value onto stack. Automatically resizes when full.
pop
T pop()
Removes and returns top element. Returns null if empty.
top
T top()
Returns top element without removing. Returns null if empty.
clear
void clear()
Removes all elements and shrinks capacity if large.
copy
std::stack<T> copy()
Creates a copy of the stack.
assign
void assign(std::stack<T> of)
Appends all elements from another stack.
ptr
T* ptr()
Returns pointer to internal data array.
hash
uint hash()
Returns hash value of the stack.
Operators
std::stack<T> + std::stack<T>- Concatenates two stacks
Example
import <std/stack>
std::stack<int> s = std::stack<int>();
s.push(10);
s.push(20);
s.push(30);
int top = s.top();
int popped = s.pop();
s.clear();