diff options
author | Stephen Kelly <steveire@gmail.com> | 2015-03-01 20:57:16 (GMT) |
---|---|---|
committer | Stephen Kelly <steveire@gmail.com> | 2015-03-10 23:17:55 (GMT) |
commit | eec7091d76fc3db6535eec3f78fd2585b9c0c38a (patch) | |
tree | 63f856198795392bbd0d4eadc47773bcbf94715b /Source | |
parent | 7cbafa8c65751d2eda7a17753c384da1fc91f695 (diff) | |
download | CMake-eec7091d76fc3db6535eec3f78fd2585b9c0c38a.zip CMake-eec7091d76fc3db6535eec3f78fd2585b9c0c38a.tar.gz CMake-eec7091d76fc3db6535eec3f78fd2585b9c0c38a.tar.bz2 |
cmRemoveDuplicates: Type-parameterize all uniq-operations
Diffstat (limited to 'Source')
-rw-r--r-- | Source/cmAlgorithms.h | 33 |
1 files changed, 22 insertions, 11 deletions
diff --git a/Source/cmAlgorithms.h b/Source/cmAlgorithms.h index 1b7029b..5504fee 100644 --- a/Source/cmAlgorithms.h +++ b/Source/cmAlgorithms.h @@ -176,12 +176,6 @@ private: Range const& m_range; }; -struct IterLess -{ - template<typename It> - bool operator()(It const& a, It const& b) const { return *a < *b; } -}; - } template<typename Iter1, typename Iter2> @@ -267,10 +261,27 @@ typename Range::const_iterator cmRemoveMatching(Range &r, MatchRange const& m) ContainerAlgorithms::BinarySearcher<MatchRange>(m)); } +namespace ContainerAlgorithms { + +template<typename Range> +struct RemoveDuplicatesAPI +{ + typedef typename Range::const_iterator const_iterator; + typedef typename Range::const_iterator value_type; + + static bool lessThan(value_type a, value_type b) { return *a < *b; } + static value_type uniqueValue(const_iterator a) { return a; } + template<typename It> + static bool valueCompare(It it, const_iterator it2) { return **it != *it2; } +}; + +} + template<typename Range> typename Range::const_iterator cmRemoveDuplicates(Range& r) { - typedef typename Range::const_iterator T; + typedef typename ContainerAlgorithms::RemoveDuplicatesAPI<Range> API; + typedef typename API::value_type T; std::vector<T> unique; unique.reserve(r.size()); std::vector<size_t> indices; @@ -280,11 +291,11 @@ typename Range::const_iterator cmRemoveDuplicates(Range& r) it != end; ++it, ++count) { const typename std::vector<T>::iterator low = - std::lower_bound(unique.begin(), unique.end(), it, - ContainerAlgorithms::IterLess()); - if (low == unique.end() || **low != *it) + std::lower_bound(unique.begin(), unique.end(), + API::uniqueValue(it), API::lessThan); + if (low == unique.end() || API::valueCompare(low, it)) { - unique.insert(low, it); + unique.insert(low, API::uniqueValue(it)); } else { |