Переглянути джерело

Add a generic algorithm for deleting items in a container.

Specialize for std::map types to delete the second element from
the iterator.  This is not quite general enough that it can
be used everywhere, because CMake inherits from std::map and
creates typedefs with custom comparison functors etc, which
can not use this algorithm.
Stephen Kelly 10 роки тому
батько
коміт
abb4a6781f
1 змінених файлів з 27 додано та 0 видалено
  1. 27 0
      Source/cmStandardIncludes.h

+ 27 - 0
Source/cmStandardIncludes.h

@@ -237,4 +237,31 @@ private:
   const std::string m_test;
 };
 
+namespace ContainerAlgorithms {
+
+template<typename Container>
+struct DefaultDeleter
+{
+  void operator()(typename Container::value_type value) {
+    delete value;
+  }
+};
+
+template<typename K, typename V>
+struct DefaultDeleter<std::map<K, V> >
+{
+  void operator()(typename std::map<K, V>::value_type value) {
+    delete value.second;
+  }
+};
+
+}
+
+template<typename Container>
+void cmDeleteAll(Container const& c)
+{
+  std::for_each(c.begin(), c.end(),
+                ContainerAlgorithms::DefaultDeleter<Container>());
+}
+
 #endif