-1

I am currently using an std::set<uintptr_t> list to store unique pointers in it. This list gets bigger with the time and when this list reaches x amount of entries it should delete the first entry, the other entries should move down one and make room for a new entry.

For example:

if (list.count >= 20)
{
    list.remove[0]; //remove the first entry from the list?
}

I know this code doesn't work but just for the logic so you know what I mean. Also the first entry would be empty then, would it be possible to move all other entries one down so the [0] entry isn't empty anymore?

9
  • std::set::erase Commented Dec 10, 2021 at 10:04
  • 2
    Why are you using uintptr_t for pointers? Pointers to what? Why aren't you using actual pointers instead of an integer type (uintptr_t is an integer type, large enough to also hold pointer values)? That has a definite bad smell about it. Commented Dec 10, 2021 at 10:07
  • @Someprogrammerdude uintptr_t is an unsigned integer type that is capable of storing a data pointer. Which typically means that it's the same size as a pointer which is perfect for what I am doing. Regarding this question it doesn't matter what type it is. Commented Dec 10, 2021 at 10:16
  • a set is not an array, hence it is not quite clear what you mean with "should move down one and make room for a new entry." Commented Dec 10, 2021 at 10:22
  • also "the first entry would be empty then", no the first entry would be removed, and the second element is the new first Commented Dec 10, 2021 at 10:23

1 Answer 1

0

You can get the iterator of your first element in your list with list.begin()

if (list.count >= 20)
{
    list.erase(list.begin()); //remove the first entry from the list
}
Sign up to request clarification or add additional context in comments.

3 Comments

Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.
this won't compile. [] -> ()
edit in code list.erase(list.begin()) thx @463035818_is_not_a_number

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.