diff options
author | Brad King <brad.king@kitware.com> | 2021-09-03 13:36:40 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2021-09-03 13:40:57 (GMT) |
commit | 6e2f4029c0e850a7420fba2ab953c0b6323e13fb (patch) | |
tree | ed5e1d5ab074ac1026832ef0ec080beaf387c608 /Source/cmAlgorithms.h | |
parent | 881e76e7c51c2aa8958252c4bc1166a8b00f24a7 (diff) | |
download | CMake-6e2f4029c0e850a7420fba2ab953c0b6323e13fb.zip CMake-6e2f4029c0e850a7420fba2ab953c0b6323e13fb.tar.gz CMake-6e2f4029c0e850a7420fba2ab953c0b6323e13fb.tar.bz2 |
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.
Diffstat (limited to 'Source/cmAlgorithms.h')
-rw-r--r-- | Source/cmAlgorithms.h | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/Source/cmAlgorithms.h b/Source/cmAlgorithms.h index c192e2a..e0ba83d 100644 --- a/Source/cmAlgorithms.h +++ b/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()); } |