00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef UTILS_DTOR_H
00023 #define UTILS_DTOR_H
00024
00025 #include <algorithm>
00026 #include <functional>
00027 #include <utility>
00028
00029 template<typename T>
00030 struct dtor : public std::unary_function <T, void>
00031 {
00032 void operator()(T &ptr) { delete ptr; }
00033 };
00034
00035 template<typename T1, typename T2>
00036 struct dtor<std::pair<T1, T2> > :
00037 public std::unary_function <std::pair<T1, T2>, void>
00038 {
00039 void operator()(std::pair<T1, T2> &pair) { delete pair.second; }
00040 };
00041
00042 template<class Cont>
00043 inline dtor<typename Cont::value_type> make_dtor(Cont const&)
00044 {
00045 return dtor<typename Cont::value_type>();
00046 }
00047
00048 template<typename Container>
00049 inline void delete_all(Container &c)
00050 {
00051 std::for_each(c.begin(), c.end(), make_dtor(c));
00052 }
00053
00054 #endif