sincerely
Singaporean
If you have not done so, read this full tutorial on how to use SGEXTN to build an application.
(no source file, everything inside header)
template ‹typename T› class SGLStack;
part of SGEXTN module SG_Containers
stack for any type of data
list of all including inherited members
preprocessor file inclusion directive: #include ‹SGLStack.h›
CMake target for BuildLah: SGEXTN::SG_Containers
see this link for more information about BuildLah
parent class: (none)
children classes: (none)
SGLStack();
[[nodiscard]] int length() const;
void pop();
void push(const T& x);
void reserve(int newMemoryLength);
[[nodiscard]] const T& top() const;
SGLStack provides a template based stack for any data type. SGLStack is preferred over SGLVector when only stack functionality is needed as it provides more readable code. This is a template based class with no separate source file. This class is a SGEXTN container. Copy constructor, copy assignment, move constructor, move assignment, and destructor work as expected. A deep copy is performed whenever this class is copied, and the new instance will not be linked to the old instance in any way. It is assumed that the contents placed into this SGEXTN container can be copied and moved. This means that their copy constructor copy assignment, move constructor, move assignment, and destructor work as expected. If this is not the case or if you want the container to store references or constant references, store pointers instead.
SGLStack internally stores a buffer in the form of a C array. When the buffer is full, it resizes to double its previous size.
Creates an empty SGLStack.
Returns the length of the SGLStack, that is the number of elements currently stored inside it.
Removes the top element of the SGLStack.
This does not return the removed element. To access the removed element, use SGLStack::top before removal.
This runs in truly constant time complexity.
Removing from an empty SGLStack will crash.
Appends x to the top of the SGLStack.
This has a amortised constant time complexity. To make it run in truly constant time, use SGLStack::reserve to pre allocate as much memory as you need.
Pre allocates sufficient memory to store newMemoryLength elements in the SGLStack.
If there is already sufficient memory for newMemoryLength elements, this is ignored.
Returns the topmost element of the SGLStack.
Using this when the SGLStack is empty will crash.
©2025 05524F.sg (Singapore)