sincerely Singaporean

If you have not done so, read this full tutorial on how to use SGEXTN to build an application.

SGLQueue

see header file

(no source file, everything inside header)

template ‹typename T› class SGLQueue;

part of SGEXTN module SG_Containers

queue for any type of data

detailed description

list of all including inherited members

implementation details

preprocessor file inclusion directive: #include ‹SGLQueue.h›

CMake target for BuildLah: SGEXTN::SG_Containers

see this link for more information about BuildLah

parent class: (none)

children classes: (none)

instance member functions

SGLQueue();

[[nodiscard]] const T& back() const;

[[nodiscard]] const T& front() const;

[[nodiscard]] int length() const;

void pop();

void push(const T& x);

void reserve(int newMemoryLength);

Detailed Description

SGLQueue provides a template based queue for any data type. 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.

Implementation Details

SGLQueue internally stores a buffer in the form of a C array. When no more elements can be appended into the buffer, it resizes to double its previous size and aligns all elements to the front of the queue.

SGLQueue();

Creates an empty SGLQueue.

[[nodiscard]] const T& back() const;

Returns the element at the back of the SGLQueue.

This will crash if the SGLQueue is empty.

[[nodiscard]] const T& front() const;

Returns the element at the front of the SGLQueue.

This will crash if the SGLQueue is empty.

[[nodiscard]] int length() const;

Returns the length of the SGLQueue.

void pop();

Removes the front element of the SGLQueue.

This has truly constant time complexity.

This does not return the removed element. To access the removed element, use SGLQueue::front before removal.

This will crash if the SGLQueue is empty.

void push(const T& x);

Appends x at the back of the SGLQueue.

This has a amortised constant time complexity. To achieve true constant time complexity, pre allocate memory equal to the amount you need using SGLQueue::reserve.

void reserve(int newMemoryLength);

Pre allocates sufficient memory to store newMemoryLength elements in the SGLQueue.

If there is already sufficient memory to store newMemoryLength elements, this is ignored.

©2025 05524F.sg (Singapore)

contact 05524F / report a bug / make a suggestion

about 05524F SINGAPORE values

list of 05524F projects