If occurrences are unique, then you should be using std::set<T>
, not std::vector<T>
.
This has the added benefit of an erase
member function, which does what you want.
See how using the correct container for the job provides you with more expressive tools?
#include <set>
#include <iostream>
int main()
{
std::set<int> notAList{1,2,3,4,5};
for (auto el : notAList)
std::cout << el << ' ';
std::cout << '\n';
notAList.erase(4);
for (auto el : notAList)
std::cout << el << ' ';
std::cout << '\n';
}
// 1 2 3 4 5
// 1 2 3 5
vector
container islist
.. It could be confusing, a lot (for someone, that reads your code) – Lelyvector
is. And both are pretty different :) – Lely