ManaPlus
dtor.h
Go to the documentation of this file.
1 /*
2  * The ManaPlus Client
3  * Copyright (C) 2004-2009 The Mana World Development Team
4  * Copyright (C) 2009-2010 The Mana Developers
5  * Copyright (C) 2011-2017 The ManaPlus Developers
6  *
7  * This file is part of The ManaPlus Client.
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program. If not, see <http://www.gnu.org/licenses/>.
21  */
22 
23 #ifndef UTILS_DTOR_H
24 #define UTILS_DTOR_H
25 
26 #include <algorithm>
27 #include <functional>
28 
29 #include "localconsts.h"
30 
31 template<typename T>
32 struct dtor final : public std::unary_function <T, void>
33 {
35 
36  void operator()(T &ptr)
37  { delete ptr; }
38 };
39 
40 template<typename T1, typename T2>
41 struct dtor<std::pair<T1, T2> > :
42 public std::unary_function <std::pair<T1, T2>, void>
43 {
44  void operator()(std::pair<T1, T2> &pair)
45  { delete pair.second; }
46 };
47 
48 template<class Cont>
50 {
52 }
53 
54 template<typename Container>
55 inline void delete_all(Container &c)
56 {
57  std::for_each(c.begin(), c.end(), make_dtor(c));
58 }
59 
60 #endif // UTILS_DTOR_H
#define final
Definition: localconsts.h:45
#define A_DEFAULT_COPY(func)
Definition: localconsts.h:40
void delete_all(Container &c)
Definition: dtor.h:55
#define A_UNUSED
Definition: localconsts.h:171
dtor< typename Cont::value_type > make_dtor(Cont const &d)
Definition: dtor.h:49
Definition: dtor.h:32
void operator()(std::pair< T1, T2 > &pair)
Definition: dtor.h:44