ソースを参照

cmRemoveDuplicates: Partially specialize the API for pointer types.

If de-duplicating a container of pointers, there is no need to
store iterators to them, as that is just more 'pointer chasing'.

Store the pointers themselves and use API which compares the pointers
in the specialization.
Stephen Kelly 10 年 前
コミット
8701a3f468
1 ファイル変更13 行追加1 行削除
  1. 13 1
      Source/cmAlgorithms.h

+ 13 - 1
Source/cmAlgorithms.h

@@ -263,7 +263,7 @@ typename Range::const_iterator cmRemoveMatching(Range &r, MatchRange const& m)
 
 
 namespace ContainerAlgorithms {
 namespace ContainerAlgorithms {
 
 
-template<typename Range>
+template<typename Range, typename T = typename Range::value_type>
 struct RemoveDuplicatesAPI
 struct RemoveDuplicatesAPI
 {
 {
   typedef typename Range::const_iterator const_iterator;
   typedef typename Range::const_iterator const_iterator;
@@ -275,6 +275,18 @@ struct RemoveDuplicatesAPI
   static bool valueCompare(It it, const_iterator it2) { return **it != *it2; }
   static bool valueCompare(It it, const_iterator it2) { return **it != *it2; }
 };
 };
 
 
+template<typename Range, typename T>
+struct RemoveDuplicatesAPI<Range, T*>
+{
+  typedef typename Range::const_iterator const_iterator;
+  typedef T* 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>
 template<typename Range>