cmAlgorithms: Maintain the pivot iterator in cmRemoveIndices.

Avoid the algorithm of 'Schlemiel the painter' in the case of
iterators which are not RandomAccess.
This commit is contained in:
Stephen Kelly 2015-02-20 22:10:41 +01:00 committed by Brad King
parent 1f79679136
commit 7fd8557f4c
1 changed files with 4 additions and 2 deletions

View File

@ -239,12 +239,14 @@ typename Range::const_iterator cmRemoveIndices(Range& r, InputRange const& rem)
typename Range::iterator writer = r.begin();
std::advance(writer, *remIt);
typename Range::iterator pivot = writer;
typename InputRange::value_type prevRem = *remIt;
++remIt;
size_t count = 1;
for ( ; writer != r.end() && remIt != rem.end(); ++count, ++remIt)
{
typename Range::iterator pivot = r.begin();
std::advance(pivot, *remIt);
std::advance(pivot, *remIt - prevRem);
prevRem = *remIt;
writer = ContainerAlgorithms::RemoveN(writer, pivot, count);
}
writer = ContainerAlgorithms::RemoveN(writer, r.end(), count);