I am implementing a cache of elements (represented by unique ids), with a max number of elements to keep. Removing the last used element when I reach the max size. So it looks like a queue, but with unique elements, as I don't want to add multiple times the same id.
But the elements can be used more than once and should go back to the top of the queue when they get used again, so that the cache really deletes the element that was used the last.
I don't really know how to do this. My first guess is to use a std::list, so manage manually the uniqueness of the elements and the "move to the top" operation.
Is there any smarter way to achieve this?
Edit: I did not know the name but this is more or less Least recently used algorithms.