diff options
author | Stephen Kelly <steveire@gmail.com> | 2015-01-04 13:53:24 (GMT) |
---|---|---|
committer | Stephen Kelly <steveire@gmail.com> | 2015-01-13 22:00:16 (GMT) |
commit | abb4a6781f96b28e4c30014915f566dee9130db7 (patch) | |
tree | 2a6752b970ff817f06ec57c742227c31c2191e57 /Source | |
parent | e4fd66b1922c10e6487362c8921669925742309a (diff) | |
download | CMake-abb4a6781f96b28e4c30014915f566dee9130db7.zip CMake-abb4a6781f96b28e4c30014915f566dee9130db7.tar.gz CMake-abb4a6781f96b28e4c30014915f566dee9130db7.tar.bz2 |
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.
Diffstat (limited to 'Source')
-rw-r--r-- | Source/cmStandardIncludes.h | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/Source/cmStandardIncludes.h b/Source/cmStandardIncludes.h index 2d988c9..251a043 100644 --- a/Source/cmStandardIncludes.h +++ b/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 |