Given
std::vector<double> a;
std::vector<int> ind;
where ind
is 1sorted in ascending order.
I want to do the equivalent of the following:
for (auto it=ind.rbegin();it!=ind.rend();it++) a.erase(a.begin() + *it);
I came up with this:
for (auto it=ind.begin();it!=ind.end();it++)
a[*it] = std::numeric_limits<double>::max();
std::erase(std::remove(a.begin(),a.end(),std::numeric_limits<double>::max()),a.end());
This is very fast, but it doesn't feel right to use the std::numeric_limits::max() as a flag in this context.
Of course feelings shouldn't play too much into the equation ... clearly comparing the doubles within the std::remove is safe, and the limit will never occur in practice in this vector in a working application, so it should be ok, no?
Any thoughts on this?
1) Ref comment by the OP. – Alf