Install gcc-4.4.0-tdm-1-core-2.tar.gz
[msysgit.git] / mingw / lib / gcc / mingw32 / 4.3.3 / include / c++ / debug / safe_association.h
blob42c050050b85a1eb9b0b476f8ed80f5168f85cc2
1 // Safe associated container base class implementation -*- C++ -*-
3 // Copyright (C) 2007 Free Software Foundation, Inc.
4 //
5 // This file is part of the GNU ISO C++ Library. This library is free
6 // software; you can redistribute it and/or modify it under the
7 // terms of the GNU General Public License as published by the
8 // Free Software Foundation; either version 2, or (at your option)
9 // any later version.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License along
17 // with this library; see the file COPYING. If not, write to the Free
18 // Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
19 // USA.
21 // As a special exception, you may use this file as part of a free software
22 // library without restriction. Specifically, if other files instantiate
23 // templates or use macros or inline functions from this file, or you compile
24 // this file and link it with other files to produce an executable, this
25 // file does not by itself cause the resulting executable to be covered by
26 // the GNU General Public License. This exception does not however
27 // invalidate any other reasons why the executable file might be covered by
28 // the GNU General Public License.
30 /** @file debug/safe_association.h
31 * This file is a GNU debug extension to the Standard C++ Library.
34 #ifndef _GLIBCXX_DEBUG_SAFE_ASSOCIATION_H
35 #define _GLIBCXX_DEBUG_SAFE_ASSOCIATION_H 1
37 #include <debug/debug.h>
38 #include <debug/macros.h>
39 #include <debug/functions.h>
40 #include <debug/formatter.h>
41 #include <debug/safe_sequence.h>
43 namespace __gnu_debug
45 /**
46 * @brief Base class for constructing a "safe" associated container type.
48 * The class template %_Safe_association simplifies the construction of
49 * "safe" associated containers.
51 template<typename _Base>
52 class _Safe_association
53 : public _Base
55 public:
56 typedef typename _Base::size_type size_type;
57 typedef typename _Base::hasher hasher;
58 typedef typename _Base::key_equal key_equal;
59 typedef typename _Base::allocator_type allocator_type;
61 typedef typename _Base::key_type key_type;
62 typedef typename _Base::value_type value_type;
63 typedef typename _Base::difference_type difference_type;
64 typedef typename _Base::reference reference;
65 typedef typename _Base::const_reference const_reference;
67 typedef __gnu_debug::_Safe_iterator<typename _Base::iterator,
68 _Safe_association>
69 iterator;
70 typedef __gnu_debug::_Safe_iterator<typename _Base::const_iterator,
71 _Safe_association>
72 const_iterator;
74 _Safe_association() { }
76 explicit _Safe_association(size_type __n) : _Base(__n) { }
78 _Safe_association(size_type __n, const hasher& __hf)
79 : _Base(__n, __hf) { }
81 _Safe_association(size_type __n, const hasher& __hf,
82 const key_equal& __eql,
83 const allocator_type& __a = allocator_type())
84 : _Base(__n, __hf, __eql, __a) { }
86 template<typename _InputIter>
87 _Safe_association(_InputIter __f, _InputIter __l)
88 : _Base(__gnu_debug::__check_valid_range(__f, __l), __l) { }
90 template<typename _InputIter>
91 _Safe_association(_InputIter __f, _InputIter __l, size_type __n)
92 : _Base(__gnu_debug::__check_valid_range(__f, __l), __l, __n) { }
94 template<typename _InputIter>
95 _Safe_association(_InputIter __f, _InputIter __l, size_type __n,
96 const hasher& __hf)
97 : _Base(__gnu_debug::__check_valid_range(__f, __l), __l, __n, __hf)
98 { }
100 template<typename _InputIter>
101 _Safe_association(_InputIter __f, _InputIter __l, size_type __n,
102 const hasher& __hf, const key_equal& __eql,
103 const allocator_type& __a = allocator_type())
104 : _Base(__gnu_debug::__check_valid_range(__f, __l),
105 __l, __n, __hf, __eql, __a)
108 _Safe_association(const _Base& __x) : _Base(__x) { }
110 _Safe_association(_Safe_association&& __x)
111 : _Base(std::forward<_Base>(__x)) { }
113 using _Base::size;
114 using _Base::max_size;
115 using _Base::empty;
116 using _Base::get_allocator;
117 using _Base::key_eq;
119 using _Base::count;
120 using _Base::bucket_count;
121 using _Base::max_bucket_count;
122 using _Base::bucket;
123 using _Base::bucket_size;
124 using _Base::load_factor;
126 const_iterator
127 begin() const { return const_iterator(_Base::begin(), this); }
129 const_iterator
130 end() const { return const_iterator(_Base::end(), this); }
132 std::pair<iterator, bool>
133 insert(const value_type& __obj)
135 typedef std::pair<typename _Base::iterator, bool> __pair_type;
136 __pair_type __res = _Base::insert(__obj);
137 return std::make_pair(iterator(__res.first, this), __res.second);
140 void
141 insert(const value_type* __first, const value_type* __last)
143 __glibcxx_check_valid_range(__first, __last);
144 _Base::insert(__first, __last);
147 template<typename _InputIter>
148 void
149 insert(_InputIter __first, _InputIter __last)
151 __glibcxx_check_valid_range(__first, __last);
152 _Base::insert(__first.base(), __last.base());
155 const_iterator
156 find(const key_type& __key) const
157 { return const_iterator(_Base::find(__key), this); }
159 std::pair<const_iterator, const_iterator>
160 equal_range(const key_type& __key) const
162 typedef typename _Base::const_iterator _Base_iterator;
163 typedef std::pair<_Base_iterator, _Base_iterator> __pair_type;
164 __pair_type __res = _Base::equal_range(__key);
165 return std::make_pair(const_iterator(__res.first, this),
166 const_iterator(__res.second, this));
169 size_type
170 erase(const key_type& __key)
172 size_type __ret(0);
173 iterator __victim(_Base::find(__key), this);
174 if (__victim != end())
176 this->erase(__victim);
177 __ret = 1;
179 return __ret;
182 iterator
183 erase(iterator __it)
185 __glibcxx_check_erase(__it);
186 __it._M_invalidate();
187 return iterator(_Base::erase(__it.base()));
190 iterator
191 erase(iterator __first, iterator __last)
193 __glibcxx_check_erase_range(__first, __last);
194 for (iterator __tmp = __first; __tmp != __last;)
196 iterator __victim = __tmp++;
197 __victim._M_invalidate();
199 return iterator(_Base::erase(__first.base(), __last.base()));
202 _Base&
203 _M_base() { return *this; }
205 const _Base&
206 _M_base() const { return *this; }
208 } // namespace __gnu_debug
210 #endif