cmAlgorithms: Relax iterator requirement for cmRemoveIndices.

Require only forward iterators from the range.
This commit is contained in:
Stephen Kelly 2015-02-20 22:07:28 +01:00 committed by Brad King
parent ba959934a6
commit 1f79679136
1 changed files with 5 additions and 2 deletions

View File

@ -237,12 +237,15 @@ typename Range::const_iterator cmRemoveIndices(Range& r, InputRange const& rem)
{ {
typename InputRange::const_iterator remIt = rem.begin(); typename InputRange::const_iterator remIt = rem.begin();
typename Range::iterator writer = r.begin() + *remIt; typename Range::iterator writer = r.begin();
std::advance(writer, *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)
{ {
writer = ContainerAlgorithms::RemoveN(writer, r.begin() + *remIt, count); typename Range::iterator pivot = r.begin();
std::advance(pivot, *remIt);
writer = ContainerAlgorithms::RemoveN(writer, pivot, count);
} }
writer = ContainerAlgorithms::RemoveN(writer, r.end(), count); writer = ContainerAlgorithms::RemoveN(writer, r.end(), count);
return writer; return writer;