package genstack

// stack is a wrapper around an array implementing a stack.
//
// We cannot use slice to represent the stack because append might change the
// pointer value of the slice. That would be an issue in GenStack
// implementation.
type stack[ any] struct {
	arr []
}

// push pushes a new element at the top of a stack.
func ( *stack[]) ( ...) { .arr = append(.arr, ...) }

// pop pops the stack top-most element.
//
// If stack length is zero, this method panics.
func ( *stack[]) ()  {
	 := .len() - 1
	 := .arr[]

	// Avoid memory leak
	var  
	.arr[] = 

	.arr = .arr[:]
	return 
}

// takeAll returns all elements in the stack in order as they are stored - i.e.
// the top-most stack element is the last one.
func ( *stack[]) () [] {
	 := .arr
	.arr = nil
	return 
}

// len returns number of elements in the stack.
func ( *stack[]) () int { return len(.arr) }