Dead
[official-gcc.git] / gomp-20050608-branch / libstdc++-v3 / include / debug / set.h
blobf9a21c6b5a1beb141858784a5bf5e2c8c25c8fdd
1 // Debugging set implementation -*- C++ -*-
3 // Copyright (C) 2003, 2004, 2005
4 // Free Software Foundation, Inc.
5 //
6 // This file is part of the GNU ISO C++ Library. This library is free
7 // software; you can redistribute it and/or modify it under the
8 // terms of the GNU General Public License as published by the
9 // Free Software Foundation; either version 2, or (at your option)
10 // any later version.
12 // This library is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
17 // You should have received a copy of the GNU General Public License along
18 // with this library; see the file COPYING. If not, write to the Free
19 // Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
20 // USA.
22 // As a special exception, you may use this file as part of a free software
23 // library without restriction. Specifically, if other files instantiate
24 // templates or use macros or inline functions from this file, or you compile
25 // this file and link it with other files to produce an executable, this
26 // file does not by itself cause the resulting executable to be covered by
27 // the GNU General Public License. This exception does not however
28 // invalidate any other reasons why the executable file might be covered by
29 // the GNU General Public License.
31 #ifndef _GLIBCXX_DEBUG_SET_H
32 #define _GLIBCXX_DEBUG_SET_H 1
34 #include <debug/safe_sequence.h>
35 #include <debug/safe_iterator.h>
36 #include <utility>
38 namespace std
40 namespace __gnu_debug_def
42 template<typename _Key, typename _Compare = std::less<_Key>,
43 typename _Allocator = std::allocator<_Key> >
44 class set
45 : public _GLIBCXX_STD::set<_Key,_Compare,_Allocator>,
46 public __gnu_debug::_Safe_sequence<set<_Key, _Compare, _Allocator> >
48 typedef _GLIBCXX_STD::set<_Key,_Compare,_Allocator> _Base;
49 typedef __gnu_debug::_Safe_sequence<set> _Safe_base;
51 public:
52 // types:
53 typedef _Key key_type;
54 typedef _Key value_type;
55 typedef _Compare key_compare;
56 typedef _Compare value_compare;
57 typedef _Allocator allocator_type;
58 typedef typename _Base::reference reference;
59 typedef typename _Base::const_reference const_reference;
61 typedef __gnu_debug::_Safe_iterator<typename _Base::iterator, set>
62 iterator;
63 typedef __gnu_debug::_Safe_iterator<typename _Base::const_iterator, set>
64 const_iterator;
66 typedef typename _Base::size_type size_type;
67 typedef typename _Base::difference_type difference_type;
68 typedef typename _Base::pointer pointer;
69 typedef typename _Base::const_pointer const_pointer;
70 typedef std::reverse_iterator<iterator> reverse_iterator;
71 typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
73 // 23.3.3.1 construct/copy/destroy:
74 explicit set(const _Compare& __comp = _Compare(),
75 const _Allocator& __a = _Allocator())
76 : _Base(__comp, __a) { }
78 template<typename _InputIterator>
79 set(_InputIterator __first, _InputIterator __last,
80 const _Compare& __comp = _Compare(),
81 const _Allocator& __a = _Allocator())
82 : _Base(__gnu_debug::__check_valid_range(__first, __last), __last,
83 __comp, __a) { }
85 set(const set<_Key,_Compare,_Allocator>& __x)
86 : _Base(__x), _Safe_base() { }
88 set(const _Base& __x) : _Base(__x), _Safe_base() { }
90 ~set() { }
92 set<_Key,_Compare,_Allocator>&
93 operator=(const set<_Key,_Compare,_Allocator>& __x)
95 *static_cast<_Base*>(this) = __x;
96 this->_M_invalidate_all();
97 return *this;
100 using _Base::get_allocator;
102 // iterators:
103 iterator
104 begin()
105 { return iterator(_Base::begin(), this); }
107 const_iterator
108 begin() const
109 { return const_iterator(_Base::begin(), this); }
111 iterator
112 end()
113 { return iterator(_Base::end(), this); }
115 const_iterator
116 end() const
117 { return const_iterator(_Base::end(), this); }
119 reverse_iterator
120 rbegin()
121 { return reverse_iterator(end()); }
123 const_reverse_iterator
124 rbegin() const
125 { return const_reverse_iterator(end()); }
127 reverse_iterator
128 rend()
129 { return reverse_iterator(begin()); }
131 const_reverse_iterator
132 rend() const
133 { return const_reverse_iterator(begin()); }
135 // capacity:
136 using _Base::empty;
137 using _Base::size;
138 using _Base::max_size;
140 // modifiers:
141 std::pair<iterator, bool>
142 insert(const value_type& __x)
144 typedef typename _Base::iterator _Base_iterator;
145 std::pair<_Base_iterator, bool> __res = _Base::insert(__x);
146 return std::pair<iterator, bool>(iterator(__res.first, this),
147 __res.second);
150 iterator
151 insert(iterator __position, const value_type& __x)
153 __glibcxx_check_insert(__position);
154 return iterator(_Base::insert(__position.base(), __x), this);
157 template <typename _InputIterator>
158 void
159 insert(_InputIterator __first, _InputIterator __last)
161 __glibcxx_check_valid_range(__first, __last);
162 _Base::insert(__first, __last);
165 void
166 erase(iterator __position)
168 __glibcxx_check_erase(__position);
169 __position._M_invalidate();
170 _Base::erase(__position.base());
173 size_type
174 erase(const key_type& __x)
176 iterator __victim = find(__x);
177 if (__victim == end())
178 return 0;
179 else
181 __victim._M_invalidate();
182 _Base::erase(__victim.base());
183 return 1;
187 void
188 erase(iterator __first, iterator __last)
190 // _GLIBCXX_RESOLVE_LIB_DEFECTS
191 // 151. can't currently clear() empty container
192 __glibcxx_check_erase_range(__first, __last);
194 while (__first != __last)
195 this->erase(__first++);
198 void
199 swap(set<_Key,_Compare,_Allocator>& __x)
201 _Base::swap(__x);
202 this->_M_swap(__x);
205 void
206 clear()
207 { this->erase(begin(), end()); }
209 // observers:
210 using _Base::key_comp;
211 using _Base::value_comp;
213 // set operations:
214 iterator
215 find(const key_type& __x)
216 { return iterator(_Base::find(__x), this); }
218 // _GLIBCXX_RESOLVE_LIB_DEFECTS
219 // 214. set::find() missing const overload
220 const_iterator
221 find(const key_type& __x) const
222 { return const_iterator(_Base::find(__x), this); }
224 using _Base::count;
226 iterator
227 lower_bound(const key_type& __x)
228 { return iterator(_Base::lower_bound(__x), this); }
230 // _GLIBCXX_RESOLVE_LIB_DEFECTS
231 // 214. set::find() missing const overload
232 const_iterator
233 lower_bound(const key_type& __x) const
234 { return const_iterator(_Base::lower_bound(__x), this); }
236 iterator
237 upper_bound(const key_type& __x)
238 { return iterator(_Base::upper_bound(__x), this); }
240 // _GLIBCXX_RESOLVE_LIB_DEFECTS
241 // 214. set::find() missing const overload
242 const_iterator
243 upper_bound(const key_type& __x) const
244 { return const_iterator(_Base::upper_bound(__x), this); }
246 std::pair<iterator,iterator>
247 equal_range(const key_type& __x)
249 typedef typename _Base::iterator _Base_iterator;
250 std::pair<_Base_iterator, _Base_iterator> __res =
251 _Base::equal_range(__x);
252 return std::make_pair(iterator(__res.first, this),
253 iterator(__res.second, this));
256 // _GLIBCXX_RESOLVE_LIB_DEFECTS
257 // 214. set::find() missing const overload
258 std::pair<const_iterator,const_iterator>
259 equal_range(const key_type& __x) const
261 typedef typename _Base::const_iterator _Base_iterator;
262 std::pair<_Base_iterator, _Base_iterator> __res =
263 _Base::equal_range(__x);
264 return std::make_pair(const_iterator(__res.first, this),
265 const_iterator(__res.second, this));
268 _Base&
269 _M_base() { return *this; }
271 const _Base&
272 _M_base() const { return *this; }
274 private:
275 void
276 _M_invalidate_all()
278 typedef typename _Base::const_iterator _Base_const_iterator;
279 typedef __gnu_debug::_Not_equal_to<_Base_const_iterator> _Not_equal;
280 this->_M_invalidate_if(_Not_equal(_M_base().end()));
284 template<typename _Key, typename _Compare, typename _Allocator>
285 inline bool
286 operator==(const set<_Key,_Compare,_Allocator>& __lhs,
287 const set<_Key,_Compare,_Allocator>& __rhs)
288 { return __lhs._M_base() == __rhs._M_base(); }
290 template<typename _Key, typename _Compare, typename _Allocator>
291 inline bool
292 operator!=(const set<_Key,_Compare,_Allocator>& __lhs,
293 const set<_Key,_Compare,_Allocator>& __rhs)
294 { return __lhs._M_base() != __rhs._M_base(); }
296 template<typename _Key, typename _Compare, typename _Allocator>
297 inline bool
298 operator<(const set<_Key,_Compare,_Allocator>& __lhs,
299 const set<_Key,_Compare,_Allocator>& __rhs)
300 { return __lhs._M_base() < __rhs._M_base(); }
302 template<typename _Key, typename _Compare, typename _Allocator>
303 inline bool
304 operator<=(const set<_Key,_Compare,_Allocator>& __lhs,
305 const set<_Key,_Compare,_Allocator>& __rhs)
306 { return __lhs._M_base() <= __rhs._M_base(); }
308 template<typename _Key, typename _Compare, typename _Allocator>
309 inline bool
310 operator>=(const set<_Key,_Compare,_Allocator>& __lhs,
311 const set<_Key,_Compare,_Allocator>& __rhs)
312 { return __lhs._M_base() >= __rhs._M_base(); }
314 template<typename _Key, typename _Compare, typename _Allocator>
315 inline bool
316 operator>(const set<_Key,_Compare,_Allocator>& __lhs,
317 const set<_Key,_Compare,_Allocator>& __rhs)
318 { return __lhs._M_base() > __rhs._M_base(); }
320 template<typename _Key, typename _Compare, typename _Allocator>
321 void
322 swap(set<_Key,_Compare,_Allocator>& __x,
323 set<_Key,_Compare,_Allocator>& __y)
324 { return __x.swap(__y); }
325 } // namespace __gnu_debug_def
326 } // namespace std
328 #endif