Install gcc-4.4.0-tdm-1-core-2.tar.gz
[msysgit.git] / mingw / lib / gcc / mingw32 / 4.3.3 / include / c++ / debug / set.h
blob3115610d1e12dd8557c1d138cb4baf5eb60b2acb
1 // Debugging set implementation -*- C++ -*-
3 // Copyright (C) 2003, 2004, 2005, 2006, 2007
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 /** @file debug/set.h
32 * This file is a GNU debug extension to the Standard C++ Library.
35 #ifndef _GLIBCXX_DEBUG_SET_H
36 #define _GLIBCXX_DEBUG_SET_H 1
38 #include <debug/safe_sequence.h>
39 #include <debug/safe_iterator.h>
40 #include <utility>
42 namespace std
44 namespace __debug
46 template<typename _Key, typename _Compare = std::less<_Key>,
47 typename _Allocator = std::allocator<_Key> >
48 class set
49 : public _GLIBCXX_STD_D::set<_Key,_Compare,_Allocator>,
50 public __gnu_debug::_Safe_sequence<set<_Key, _Compare, _Allocator> >
52 typedef _GLIBCXX_STD_D::set<_Key, _Compare, _Allocator> _Base;
53 typedef __gnu_debug::_Safe_sequence<set> _Safe_base;
55 public:
56 // types:
57 typedef _Key key_type;
58 typedef _Key value_type;
59 typedef _Compare key_compare;
60 typedef _Compare value_compare;
61 typedef _Allocator allocator_type;
62 typedef typename _Base::reference reference;
63 typedef typename _Base::const_reference const_reference;
65 typedef __gnu_debug::_Safe_iterator<typename _Base::iterator, set>
66 iterator;
67 typedef __gnu_debug::_Safe_iterator<typename _Base::const_iterator, set>
68 const_iterator;
70 typedef typename _Base::size_type size_type;
71 typedef typename _Base::difference_type difference_type;
72 typedef typename _Base::pointer pointer;
73 typedef typename _Base::const_pointer const_pointer;
74 typedef std::reverse_iterator<iterator> reverse_iterator;
75 typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
77 // 23.3.3.1 construct/copy/destroy:
78 explicit set(const _Compare& __comp = _Compare(),
79 const _Allocator& __a = _Allocator())
80 : _Base(__comp, __a) { }
82 template<typename _InputIterator>
83 set(_InputIterator __first, _InputIterator __last,
84 const _Compare& __comp = _Compare(),
85 const _Allocator& __a = _Allocator())
86 : _Base(__gnu_debug::__check_valid_range(__first, __last), __last,
87 __comp, __a) { }
89 set(const set& __x)
90 : _Base(__x), _Safe_base() { }
92 set(const _Base& __x)
93 : _Base(__x), _Safe_base() { }
95 #ifdef __GXX_EXPERIMENTAL_CXX0X__
96 set(set&& __x)
97 : _Base(std::forward<set>(__x)), _Safe_base()
98 { this->_M_swap(__x); }
99 #endif
101 ~set() { }
103 set&
104 operator=(const set& __x)
106 *static_cast<_Base*>(this) = __x;
107 this->_M_invalidate_all();
108 return *this;
111 #ifdef __GXX_EXPERIMENTAL_CXX0X__
112 set&
113 operator=(set&& __x)
115 // NB: DR 675.
116 clear();
117 swap(__x);
118 return *this;
120 #endif
122 using _Base::get_allocator;
124 // iterators:
125 iterator
126 begin()
127 { return iterator(_Base::begin(), this); }
129 const_iterator
130 begin() const
131 { return const_iterator(_Base::begin(), this); }
133 iterator
134 end()
135 { return iterator(_Base::end(), this); }
137 const_iterator
138 end() const
139 { return const_iterator(_Base::end(), this); }
141 reverse_iterator
142 rbegin()
143 { return reverse_iterator(end()); }
145 const_reverse_iterator
146 rbegin() const
147 { return const_reverse_iterator(end()); }
149 reverse_iterator
150 rend()
151 { return reverse_iterator(begin()); }
153 const_reverse_iterator
154 rend() const
155 { return const_reverse_iterator(begin()); }
157 #ifdef __GXX_EXPERIMENTAL_CXX0X__
158 const_iterator
159 cbegin() const
160 { return const_iterator(_Base::begin(), this); }
162 const_iterator
163 cend() const
164 { return const_iterator(_Base::end(), this); }
166 const_reverse_iterator
167 crbegin() const
168 { return const_reverse_iterator(end()); }
170 const_reverse_iterator
171 crend() const
172 { return const_reverse_iterator(begin()); }
173 #endif
175 // capacity:
176 using _Base::empty;
177 using _Base::size;
178 using _Base::max_size;
180 // modifiers:
181 std::pair<iterator, bool>
182 insert(const value_type& __x)
184 typedef typename _Base::iterator _Base_iterator;
185 std::pair<_Base_iterator, bool> __res = _Base::insert(__x);
186 return std::pair<iterator, bool>(iterator(__res.first, this),
187 __res.second);
190 iterator
191 insert(iterator __position, const value_type& __x)
193 __glibcxx_check_insert(__position);
194 return iterator(_Base::insert(__position.base(), __x), this);
197 template <typename _InputIterator>
198 void
199 insert(_InputIterator __first, _InputIterator __last)
201 __glibcxx_check_valid_range(__first, __last);
202 _Base::insert(__first, __last);
205 void
206 erase(iterator __position)
208 __glibcxx_check_erase(__position);
209 __position._M_invalidate();
210 _Base::erase(__position.base());
213 size_type
214 erase(const key_type& __x)
216 iterator __victim = find(__x);
217 if (__victim == end())
218 return 0;
219 else
221 __victim._M_invalidate();
222 _Base::erase(__victim.base());
223 return 1;
227 void
228 erase(iterator __first, iterator __last)
230 // _GLIBCXX_RESOLVE_LIB_DEFECTS
231 // 151. can't currently clear() empty container
232 __glibcxx_check_erase_range(__first, __last);
234 while (__first != __last)
235 this->erase(__first++);
238 void
239 #ifdef __GXX_EXPERIMENTAL_CXX0X__
240 swap(set&& __x)
241 #else
242 swap(set& __x)
243 #endif
245 _Base::swap(__x);
246 this->_M_swap(__x);
249 void
250 clear()
251 { this->erase(begin(), end()); }
253 // observers:
254 using _Base::key_comp;
255 using _Base::value_comp;
257 // set operations:
258 iterator
259 find(const key_type& __x)
260 { return iterator(_Base::find(__x), this); }
262 // _GLIBCXX_RESOLVE_LIB_DEFECTS
263 // 214. set::find() missing const overload
264 const_iterator
265 find(const key_type& __x) const
266 { return const_iterator(_Base::find(__x), this); }
268 using _Base::count;
270 iterator
271 lower_bound(const key_type& __x)
272 { return iterator(_Base::lower_bound(__x), this); }
274 // _GLIBCXX_RESOLVE_LIB_DEFECTS
275 // 214. set::find() missing const overload
276 const_iterator
277 lower_bound(const key_type& __x) const
278 { return const_iterator(_Base::lower_bound(__x), this); }
280 iterator
281 upper_bound(const key_type& __x)
282 { return iterator(_Base::upper_bound(__x), this); }
284 // _GLIBCXX_RESOLVE_LIB_DEFECTS
285 // 214. set::find() missing const overload
286 const_iterator
287 upper_bound(const key_type& __x) const
288 { return const_iterator(_Base::upper_bound(__x), this); }
290 std::pair<iterator,iterator>
291 equal_range(const key_type& __x)
293 typedef typename _Base::iterator _Base_iterator;
294 std::pair<_Base_iterator, _Base_iterator> __res =
295 _Base::equal_range(__x);
296 return std::make_pair(iterator(__res.first, this),
297 iterator(__res.second, this));
300 // _GLIBCXX_RESOLVE_LIB_DEFECTS
301 // 214. set::find() missing const overload
302 std::pair<const_iterator,const_iterator>
303 equal_range(const key_type& __x) const
305 typedef typename _Base::const_iterator _Base_iterator;
306 std::pair<_Base_iterator, _Base_iterator> __res =
307 _Base::equal_range(__x);
308 return std::make_pair(const_iterator(__res.first, this),
309 const_iterator(__res.second, this));
312 _Base&
313 _M_base() { return *this; }
315 const _Base&
316 _M_base() const { return *this; }
318 private:
319 void
320 _M_invalidate_all()
322 typedef typename _Base::const_iterator _Base_const_iterator;
323 typedef __gnu_debug::_Not_equal_to<_Base_const_iterator> _Not_equal;
324 this->_M_invalidate_if(_Not_equal(_M_base().end()));
328 template<typename _Key, typename _Compare, typename _Allocator>
329 inline bool
330 operator==(const set<_Key, _Compare, _Allocator>& __lhs,
331 const set<_Key, _Compare, _Allocator>& __rhs)
332 { return __lhs._M_base() == __rhs._M_base(); }
334 template<typename _Key, typename _Compare, typename _Allocator>
335 inline bool
336 operator!=(const set<_Key, _Compare, _Allocator>& __lhs,
337 const set<_Key, _Compare, _Allocator>& __rhs)
338 { return __lhs._M_base() != __rhs._M_base(); }
340 template<typename _Key, typename _Compare, typename _Allocator>
341 inline bool
342 operator<(const set<_Key, _Compare, _Allocator>& __lhs,
343 const set<_Key, _Compare, _Allocator>& __rhs)
344 { return __lhs._M_base() < __rhs._M_base(); }
346 template<typename _Key, typename _Compare, typename _Allocator>
347 inline bool
348 operator<=(const set<_Key, _Compare, _Allocator>& __lhs,
349 const set<_Key, _Compare, _Allocator>& __rhs)
350 { return __lhs._M_base() <= __rhs._M_base(); }
352 template<typename _Key, typename _Compare, typename _Allocator>
353 inline bool
354 operator>=(const set<_Key, _Compare, _Allocator>& __lhs,
355 const set<_Key, _Compare, _Allocator>& __rhs)
356 { return __lhs._M_base() >= __rhs._M_base(); }
358 template<typename _Key, typename _Compare, typename _Allocator>
359 inline bool
360 operator>(const set<_Key, _Compare, _Allocator>& __lhs,
361 const set<_Key, _Compare, _Allocator>& __rhs)
362 { return __lhs._M_base() > __rhs._M_base(); }
364 template<typename _Key, typename _Compare, typename _Allocator>
365 void
366 swap(set<_Key, _Compare, _Allocator>& __x,
367 set<_Key, _Compare, _Allocator>& __y)
368 { return __x.swap(__y); }
370 #ifdef __GXX_EXPERIMENTAL_CXX0X__
371 template<typename _Key, typename _Compare, typename _Allocator>
372 void
373 swap(set<_Key, _Compare, _Allocator>&& __x,
374 set<_Key, _Compare, _Allocator>& __y)
375 { return __x.swap(__y); }
377 template<typename _Key, typename _Compare, typename _Allocator>
378 void
379 swap(set<_Key, _Compare, _Allocator>& __x,
380 set<_Key, _Compare, _Allocator>&& __y)
381 { return __x.swap(__y); }
382 #endif
384 } // namespace __debug
385 } // namespace std
387 #endif