Remove from the beginning of std::vector
Given
std::vector<Rule>& topPriorityRules;
The correct way to remove the first element of the referenced vector is
topPriorityRules.erase(topPriorityRules.begin());
which is exactly what you suggested.
Looks like i need to do iterator overloading.
There is no need to overload an iterator in order to erase first element of std::vector
.
P.S. Vector (dynamic array) is probably a wrong choice of data structure if you intend to erase from the front.
Two suggestions:
- Use
std::deque
instead ofstd::vector
for better performance in your specific case and use the methodstd::deque::pop_front()
. - Rethink (I mean: delete) the
&
instd::vector<ScanRule>& topPriorityRules;