Temporary OSX/Clang/C++11 workaround
[ardour.git] / libs / pbd / pbd / stl_delete.h
1 /*
2     Copyright (C) 1998-99 Paul Barton-Davis 
3
4     This program is free software; you can redistribute it and/or modify
5     it under the terms of the GNU General Public License as published by
6     the Free Software Foundation; either version 2 of the License, or
7     (at your option) any later version.
8
9     This program is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12     GNU General Public License for more details.
13
14     You should have received a copy of the GNU General Public License
15     along with this program; if not, write to the Free Software
16     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
18 */
19
20 #ifndef __libmisc_stl_delete_h__
21 #define __libmisc_stl_delete_h__
22
23
24 #if __clang__ && __APPLE__ && __cplusplus >= 201103L
25 #include <vector>
26 #ifndef _CPP_VECTOR
27 #define _CPP_VECTOR
28 #endif
29 #endif
30
31 /* To actually use any of these deletion functions, you need to
32    first include the revelant container type header.
33 */
34 #if defined(_CPP_VECTOR) || defined(_GLIBCXX_VECTOR) || defined(__SGI_STL_VECTOR)
35 template<class T> void vector_delete (std::vector<T *> *vec)
36 {
37         typename std::vector<T *>::iterator i;
38         
39         for (i = vec->begin(); i != vec->end(); i++) {
40                 delete *i;
41         }
42         vec->clear ();
43 }
44 #endif // _CPP_VECTOR || _GLIBCXX_VECTOR || __SGI_STL_VECTOR
45
46 #if defined(_CPP_MAP) || defined(_GLIBCXX_MAP) || defined(__SGI_STL_MAP)
47 template<class K, class T> void map_delete (std::map<K, T *> *m) 
48 {
49         typename std::map<K, T *>::iterator i;
50
51         for (i = m->begin(); i != m->end(); i++) {
52                 delete (*i).second;
53         }
54         m->clear ();
55 }
56 #endif // _CPP_MAP || _GLIBCXX_MAP || __SGI_STL_MAP
57
58 #if defined(_CPP_LIST) || defined(_GLIBCXX_LIST) || defined(__SGI_STL_LIST)
59 template<class T> void list_delete (std::list<T *> *l) 
60 {
61         typename std::list<T *>::iterator i;
62
63         for (i = l->begin(); i != l->end(); i++) {
64                 delete (*i);
65         }
66
67         l->clear ();
68 }
69 #endif // _CPP_LIST || _GLIBCXX_LIST || __SGI_STL_LIST
70
71 #if defined(_CPP_SLIST) || defined(_GLIBCXX_SLIST) || defined(__SGI_STL_SLIST)
72 template<class T> void slist_delete (std::slist<T *> *l) 
73 {
74         typename std::slist<T *>::iterator i;
75
76         for (i = l->begin(); i != l->end(); i++) {
77                 delete (*i);
78         }
79
80         l->clear ();
81 }
82 #endif // _CPP_SLIST || _GLIBCXX_SLIST || __SGI_STL_SLIST
83
84 #if defined(_CPP_SET) || defined(_GLIBCXX_SET) || defined(__SGI_STL_SET)
85 template<class T> void set_delete (std::set<T *> *sset) 
86 {
87         typename std::set<T *>::iterator i;
88         
89         for (i = sset->begin(); i != sset->end(); i++) {
90                 delete *i;
91         }
92         sset->erase (sset->begin(), sset->end());
93 }
94 #endif // _CPP_SET || _GLIBCXX_SET || __SGI_STL_SET
95
96 #endif // __libmisc_stl_delete_h__