summaryrefslogtreecommitdiffstats
path: root/Source/cmAlgorithms.h
diff options
context:
space:
mode:
authorStephen Kelly <steveire@gmail.com>2015-02-20 21:10:41 (GMT)
committerBrad King <brad.king@kitware.com>2015-02-24 14:16:02 (GMT)
commit7fd8557f4c3d761c8ec0e7c29c9fa74a3ff45295 (patch)
treea4388bbecab2f3fbc2bd7c96917d068f057464df /Source/cmAlgorithms.h
parent1f7967913662429adcc509528086d6525acff317 (diff)
downloadCMake-7fd8557f4c3d761c8ec0e7c29c9fa74a3ff45295.zip
CMake-7fd8557f4c3d761c8ec0e7c29c9fa74a3ff45295.tar.gz
CMake-7fd8557f4c3d761c8ec0e7c29c9fa74a3ff45295.tar.bz2
cmAlgorithms: Maintain the pivot iterator in cmRemoveIndices.
Avoid the algorithm of 'Schlemiel the painter' in the case of iterators which are not RandomAccess.
Diffstat (limited to 'Source/cmAlgorithms.h')
-rw-r--r--Source/cmAlgorithms.h6
1 files changed, 4 insertions, 2 deletions
diff --git a/Source/cmAlgorithms.h b/Source/cmAlgorithms.h
index 3dd5f95..f00e1c0 100644
--- a/Source/cmAlgorithms.h
+++ b/Source/cmAlgorithms.h
@@ -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);