I have a 2D vector containing 96 blocks of 600 values, which is what I want.
I need to remove (blocks) that do not contain sufficient energy. I have managed to calculate the energy but do not know which way would be better in removing the (blocks) that do not contain enough energy.
In your opinions would it be better to create a temporary 2D vector, that pushed back the blocks that do contain enough energy and then delete the original vector from memory or…
Should I remove the blocks from the vector at that particular position?
I’m assuming you have this:
and you have a function like this:
and you want to remove the Blocks that do not have sufficient energy.
By remove, do you mean you want there to be fewer than 96 Blocks afterwards? I will assume so.
Then the right way to do this is:
the above can be done in one line, but by doing it in two what is going on should be more clear.
remove_iffinds everything that passes the 3rd argument condition, and filters it out of the range. It returns the point where the “trash” at the end of thevectorlives. We then erase the trash. This is called the remove-erase idiom.