summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/stdalgo.h10
-rw-r--r--src/coremods/core_whowas.cpp6
-rw-r--r--src/modmanager_static.cpp3
-rw-r--r--src/modules/m_customprefix.cpp3
-rw-r--r--src/modules/m_showfile.cpp10
5 files changed, 16 insertions, 16 deletions
diff --git a/include/stdalgo.h b/include/stdalgo.h
index 1ae5b8ae1..afbd763fb 100644
--- a/include/stdalgo.h
+++ b/include/stdalgo.h
@@ -84,4 +84,14 @@ namespace stdalgo
{
void operator()(classbase* item);
};
+
+ /**
+ * Deletes all elements in a container using operator delete
+ * @param cont The container containing the elements to delete
+ */
+ template <template<typename, typename> class Cont, typename T, typename Alloc>
+ inline void delete_all(const Cont<T*, Alloc>& cont)
+ {
+ std::for_each(cont.begin(), cont.end(), defaultdeleter<T>());
+ }
}
diff --git a/src/coremods/core_whowas.cpp b/src/coremods/core_whowas.cpp
index 0a3a994a8..0227fdb51 100644
--- a/src/coremods/core_whowas.cpp
+++ b/src/coremods/core_whowas.cpp
@@ -119,8 +119,7 @@ void CommandWhowas::AddToWhoWas(User* user)
if (it != whowas.end())
{
whowas_set* set = it->second;
- for (whowas_set::iterator i = set->begin(); i != set->end(); ++i)
- delete *i;
+ stdalgo::delete_all(*set);
delete set;
whowas.erase(it);
@@ -164,8 +163,7 @@ void CommandWhowas::Prune()
}
whowas_set* set = iter->second;
- for (whowas_set::iterator i = set->begin(); i != set->end(); ++i)
- delete *i;
+ stdalgo::delete_all(*set);
delete set;
whowas.erase(iter);
diff --git a/src/modmanager_static.cpp b/src/modmanager_static.cpp
index 76f16fa92..ac127b703 100644
--- a/src/modmanager_static.cpp
+++ b/src/modmanager_static.cpp
@@ -69,8 +69,7 @@ class AllModule : public Module
~AllModule()
{
- for(std::vector<Command*>::iterator i = cmds.begin(); i != cmds.end(); ++i)
- delete *i;
+ stdalgo::delete_all(cmds);
}
Version GetVersion()
diff --git a/src/modules/m_customprefix.cpp b/src/modules/m_customprefix.cpp
index 107c6d684..65c2cbd31 100644
--- a/src/modules/m_customprefix.cpp
+++ b/src/modules/m_customprefix.cpp
@@ -76,8 +76,7 @@ class ModuleCustomPrefix : public Module
~ModuleCustomPrefix()
{
- for (std::vector<CustomPrefixMode*>::iterator i = modes.begin(); i != modes.end(); i++)
- delete *i;
+ stdalgo::delete_all(modes);
}
Version GetVersion() CXX11_OVERRIDE
diff --git a/src/modules/m_showfile.cpp b/src/modules/m_showfile.cpp
index 0f5d3ed1a..c42877eef 100644
--- a/src/modules/m_showfile.cpp
+++ b/src/modules/m_showfile.cpp
@@ -127,12 +127,6 @@ class ModuleShowFile : public Module
newcmds.push_back(sfcmd);
}
- static void DelAll(const std::vector<CommandShowFile*>& list)
- {
- for (std::vector<CommandShowFile*>::const_iterator i = list.begin(); i != list.end(); ++i)
- delete *i;
- }
-
public:
void ReadConfig(ConfigStatus& status) CXX11_OVERRIDE
{
@@ -157,13 +151,13 @@ class ModuleShowFile : public Module
std::sort(newcmds.begin(), newcmds.end());
std::set_difference(cmds.begin(), cmds.end(), newcmds.begin(), newcmds.end(), removed.begin());
- DelAll(removed);
+ stdalgo::delete_all(removed);
cmds.swap(newcmds);
}
~ModuleShowFile()
{
- DelAll(cmds);
+ stdalgo::delete_all(cmds);
}
Version GetVersion() CXX11_OVERRIDE