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:
parent
1f79679136
commit
7fd8557f4c
|
@ -239,12 +239,14 @@ typename Range::const_iterator cmRemoveIndices(Range& r, InputRange const& rem)
|
||||||
|
|
||||||
typename Range::iterator writer = r.begin();
|
typename Range::iterator writer = r.begin();
|
||||||
std::advance(writer, *remIt);
|
std::advance(writer, *remIt);
|
||||||
|
typename Range::iterator pivot = writer;
|
||||||
|
typename InputRange::value_type prevRem = *remIt;
|
||||||
++remIt;
|
++remIt;
|
||||||
size_t count = 1;
|
size_t count = 1;
|
||||||
for ( ; writer != r.end() && remIt != rem.end(); ++count, ++remIt)
|
for ( ; writer != r.end() && remIt != rem.end(); ++count, ++remIt)
|
||||||
{
|
{
|
||||||
typename Range::iterator pivot = r.begin();
|
std::advance(pivot, *remIt - prevRem);
|
||||||
std::advance(pivot, *remIt);
|
prevRem = *remIt;
|
||||||
writer = ContainerAlgorithms::RemoveN(writer, pivot, count);
|
writer = ContainerAlgorithms::RemoveN(writer, pivot, count);
|
||||||
}
|
}
|
||||||
writer = ContainerAlgorithms::RemoveN(writer, r.end(), count);
|
writer = ContainerAlgorithms::RemoveN(writer, r.end(), count);
|
||||||
|
|
Loading…
Reference in New Issue