cmDeleteAll: Generalize deletion specialization for map types.

Assume that a container whose value_type is a std::pair should have
its second member deleted.
This commit is contained in:
Stephen Kelly 2015-01-04 15:16:56 +01:00
parent f8c416f00c
commit 4dc0c488f9
1 changed files with 17 additions and 4 deletions

View File

@ -239,7 +239,20 @@ private:
namespace ContainerAlgorithms {
template<typename Container>
template<typename T>
struct cmIsPair
{
enum { value = false };
};
template<typename K, typename V>
struct cmIsPair<std::pair<K, V> >
{
enum { value = true };
};
template<typename Container,
bool valueTypeIsPair = cmIsPair<typename Container::value_type>::value>
struct DefaultDeleter
{
void operator()(typename Container::value_type value) {
@ -247,10 +260,10 @@ struct DefaultDeleter
}
};
template<typename K, typename V>
struct DefaultDeleter<std::map<K, V> >
template<typename Container>
struct DefaultDeleter<Container, /* valueTypeIsPair = */ true>
{
void operator()(typename std::map<K, V>::value_type value) {
void operator()(typename Container::value_type value) {
delete value.second;
}
};