I have a use case where I need to store some amount of uint16_t variables in no particular order (although the actual type of variables is not relevant). I have decided to turn to the STL to look for a container that best suits my needs.
The objects in the container may get taken out of it to be used and put back into the container. Sort of how mechanics might have a single box of screwdrivers instead of putting screwdrivers in their pockets. The container need not perform any sorting on the stored objects and it does not matter what was taken out - the only requirement is to know whether there is anything left in the container.
My eyes turn to std::stack
and std::forward_list
. They both provide O(1) insertion (just alter the front element) and O(1) pop operation (again, just alter the front element and return the previous front). Problem is - I have no idea how they differ from each other conceptually.
I know that std::stack
is an adapter that just wraps an actual STL container (std::deque
by default), thus it might have some unintended overhead, depending on the container being wrapped.
I am inclined to use std::forward_list
, but I'm looking for input from colleagues. If you have thoughts on the matter, please share them.