Browse Source

cmAlgorithms: Preserve const-ness in cmRemoveDuplicates range signature

The pattern `vec.erase(cmRemoveDuplicates(vec), vec.end())` fails to
compile with GCC 4.8's libstdc++ if `cmRemoveDuplicates` returns a
`const_iterator` because `end()` returns an `iterator`.  Overload
`cmRemoveDuplicates` to return an iterator type matching the const-ness
of its argument.
Brad King 4 years ago
parent
commit
6e2f4029c0
1 changed files with 7 additions and 1 deletions
  1. 7 1
      Source/cmAlgorithms.h

+ 7 - 1
Source/cmAlgorithms.h

@@ -133,7 +133,13 @@ ForwardIterator cmRemoveDuplicates(ForwardIterator first, ForwardIterator last)
 }
 
 template <typename Range>
-typename Range::const_iterator cmRemoveDuplicates(Range& r)
+typename Range::iterator cmRemoveDuplicates(Range& r)
+{
+  return cmRemoveDuplicates(r.begin(), r.end());
+}
+
+template <typename Range>
+typename Range::const_iterator cmRemoveDuplicates(Range const& r)
 {
   return cmRemoveDuplicates(r.begin(), r.end());
 }