]>
Commit | Line | Data |
---|---|---|
1218d701 SR |
1 | // Profiling multimap implementation -*- C++ -*- |
2 | ||
6b592ab3 | 3 | // Copyright (C) 2009, 2010 Free Software Foundation, Inc. |
1218d701 SR |
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 3, or (at your option) | |
9 | // any later version. | |
10 | ||
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. | |
15 | ||
16 | // Under Section 7 of GPL version 3, you are granted additional | |
17 | // permissions described in the GCC Runtime Library Exception, version | |
18 | // 3.1, as published by the Free Software Foundation. | |
19 | ||
20 | // You should have received a copy of the GNU General Public License and | |
21 | // a copy of the GCC Runtime Library Exception along with this program; | |
22 | // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see | |
23 | // <http://www.gnu.org/licenses/>. | |
24 | ||
25 | /** @file profile/multimap.h | |
26 | * This file is a GNU profile extension to the Standard C++ Library. | |
27 | */ | |
28 | ||
29 | #ifndef _GLIBCXX_PROFILE_MULTIMAP_H | |
30 | #define _GLIBCXX_PROFILE_MULTIMAP_H 1 | |
31 | ||
32 | #include <utility> | |
33 | ||
12ffa228 | 34 | namespace std _GLIBCXX_VISIBILITY(default) |
1218d701 SR |
35 | { |
36 | namespace __profile | |
37 | { | |
9ee6a740 | 38 | /// Class std::multimap wrapper with performance instrumentation. |
1218d701 SR |
39 | template<typename _Key, typename _Tp, typename _Compare = std::less<_Key>, |
40 | typename _Allocator = std::allocator<std::pair<const _Key, _Tp> > > | |
41 | class multimap | |
12ffa228 | 42 | : public _GLIBCXX_STD_C::multimap<_Key, _Tp, _Compare, _Allocator> |
1218d701 | 43 | { |
12ffa228 | 44 | typedef _GLIBCXX_STD_C::multimap<_Key, _Tp, _Compare, _Allocator> _Base; |
1218d701 SR |
45 | |
46 | public: | |
47 | // types: | |
48 | typedef _Key key_type; | |
49 | typedef _Tp mapped_type; | |
50 | typedef std::pair<const _Key, _Tp> value_type; | |
51 | typedef _Compare key_compare; | |
52 | typedef _Allocator allocator_type; | |
53 | typedef typename _Base::reference reference; | |
54 | typedef typename _Base::const_reference const_reference; | |
55 | ||
56 | typedef typename _Base::iterator iterator; | |
57 | typedef typename _Base::const_iterator const_iterator; | |
58 | typedef typename _Base::reverse_iterator reverse_iterator; | |
59 | typedef typename _Base::const_reverse_iterator const_reverse_iterator; | |
60 | ||
61 | typedef typename _Base::size_type size_type; | |
62 | typedef typename _Base::difference_type difference_type; | |
63 | typedef typename _Base::pointer pointer; | |
64 | typedef typename _Base::const_pointer const_pointer; | |
65 | ||
66 | using _Base::value_compare; | |
67 | ||
68 | // 23.3.1.1 construct/copy/destroy: | |
69 | explicit multimap(const _Compare& __comp = _Compare(), | |
70 | const _Allocator& __a = _Allocator()) | |
71 | : _Base(__comp, __a) { } | |
72 | ||
73 | template<typename _InputIterator> | |
74 | multimap(_InputIterator __first, _InputIterator __last, | |
75 | const _Compare& __comp = _Compare(), | |
76 | const _Allocator& __a = _Allocator()) | |
77 | : _Base(__first, __last, __comp, __a) { } | |
78 | ||
79 | multimap(const multimap& __x) | |
80 | : _Base(__x) { } | |
81 | ||
82 | multimap(const _Base& __x) | |
83 | : _Base(__x) { } | |
84 | ||
85 | #ifdef __GXX_EXPERIMENTAL_CXX0X__ | |
86 | multimap(multimap&& __x) | |
5f1fd346 | 87 | : _Base(std::move(__x)) |
1218d701 SR |
88 | { } |
89 | ||
90 | multimap(initializer_list<value_type> __l, | |
91 | const _Compare& __c = _Compare(), | |
92 | const allocator_type& __a = allocator_type()) | |
93 | : _Base(__l, __c, __a) { } | |
94 | #endif | |
95 | ||
96 | ~multimap() { } | |
97 | ||
98 | multimap& | |
99 | operator=(const multimap& __x) | |
100 | { | |
101 | *static_cast<_Base*>(this) = __x; | |
102 | return *this; | |
103 | } | |
104 | ||
105 | #ifdef __GXX_EXPERIMENTAL_CXX0X__ | |
106 | multimap& | |
107 | operator=(multimap&& __x) | |
108 | { | |
0462fd5e PC |
109 | // NB: DR 1204. |
110 | // NB: DR 675. | |
111 | this->clear(); | |
112 | this->swap(__x); | |
1218d701 SR |
113 | return *this; |
114 | } | |
115 | ||
116 | multimap& | |
117 | operator=(initializer_list<value_type> __l) | |
118 | { | |
119 | this->clear(); | |
120 | this->insert(__l); | |
121 | return *this; | |
122 | } | |
123 | #endif | |
124 | ||
125 | using _Base::get_allocator; | |
126 | ||
127 | // iterators: | |
128 | iterator | |
129 | begin() | |
130 | { return iterator(_Base::begin()); } | |
131 | ||
132 | const_iterator | |
133 | begin() const | |
134 | { return const_iterator(_Base::begin()); } | |
135 | ||
136 | iterator | |
137 | end() | |
138 | { return iterator(_Base::end()); } | |
139 | ||
140 | const_iterator | |
141 | end() const | |
142 | { return const_iterator(_Base::end()); } | |
143 | ||
144 | reverse_iterator | |
145 | rbegin() | |
146 | { return reverse_iterator(end()); } | |
147 | ||
148 | const_reverse_iterator | |
149 | rbegin() const | |
150 | { return const_reverse_iterator(end()); } | |
151 | ||
152 | reverse_iterator | |
153 | rend() | |
154 | { return reverse_iterator(begin()); } | |
155 | ||
156 | const_reverse_iterator | |
157 | rend() const | |
158 | { return const_reverse_iterator(begin()); } | |
159 | ||
160 | #ifdef __GXX_EXPERIMENTAL_CXX0X__ | |
161 | const_iterator | |
162 | cbegin() const | |
163 | { return const_iterator(_Base::begin()); } | |
164 | ||
165 | const_iterator | |
166 | cend() const | |
167 | { return const_iterator(_Base::end()); } | |
168 | ||
169 | const_reverse_iterator | |
170 | crbegin() const | |
171 | { return const_reverse_iterator(end()); } | |
172 | ||
173 | const_reverse_iterator | |
174 | crend() const | |
175 | { return const_reverse_iterator(begin()); } | |
176 | #endif | |
177 | ||
178 | // capacity: | |
179 | using _Base::empty; | |
180 | using _Base::size; | |
181 | using _Base::max_size; | |
182 | ||
183 | // modifiers: | |
184 | iterator | |
185 | insert(const value_type& __x) | |
186 | { return iterator(_Base::insert(__x)); } | |
187 | ||
e6a05448 PC |
188 | #ifdef __GXX_EXPERIMENTAL_CXX0X__ |
189 | template<typename _Pair, typename = typename | |
190 | std::enable_if<std::is_convertible<_Pair, | |
191 | value_type>::value>::type> | |
192 | iterator | |
193 | insert(_Pair&& __x) | |
194 | { return iterator(_Base::insert(std::forward<_Pair>(__x))); } | |
195 | #endif | |
196 | ||
1218d701 SR |
197 | #ifdef __GXX_EXPERIMENTAL_CXX0X__ |
198 | void | |
199 | insert(std::initializer_list<value_type> __list) | |
200 | { _Base::insert(__list); } | |
201 | #endif | |
202 | ||
203 | iterator | |
7606bd11 PC |
204 | #ifdef __GXX_EXPERIMENTAL_CXX0X__ |
205 | insert(const_iterator __position, const value_type& __x) | |
206 | #else | |
1218d701 | 207 | insert(iterator __position, const value_type& __x) |
7606bd11 PC |
208 | #endif |
209 | { return iterator(_Base::insert(__position, __x)); } | |
1218d701 | 210 | |
e6a05448 PC |
211 | #ifdef __GXX_EXPERIMENTAL_CXX0X__ |
212 | template<typename _Pair, typename = typename | |
213 | std::enable_if<std::is_convertible<_Pair, | |
214 | value_type>::value>::type> | |
215 | iterator | |
216 | insert(const_iterator __position, _Pair&& __x) | |
217 | { return iterator(_Base::insert(__position, | |
218 | std::forward<_Pair>(__x))); } | |
219 | #endif | |
220 | ||
1218d701 SR |
221 | template<typename _InputIterator> |
222 | void | |
223 | insert(_InputIterator __first, _InputIterator __last) | |
7606bd11 | 224 | { _Base::insert(__first, __last); } |
1218d701 SR |
225 | |
226 | #ifdef __GXX_EXPERIMENTAL_CXX0X__ | |
227 | iterator | |
7606bd11 PC |
228 | erase(const_iterator __position) |
229 | { return iterator(_Base::erase(__position)); } | |
1218d701 SR |
230 | #else |
231 | void | |
232 | erase(iterator __position) | |
5ab06c6d | 233 | { _Base::erase(__position); } |
1218d701 SR |
234 | #endif |
235 | ||
236 | size_type | |
237 | erase(const key_type& __x) | |
238 | { | |
239 | std::pair<iterator, iterator> __victims = this->equal_range(__x); | |
240 | size_type __count = 0; | |
241 | while (__victims.first != __victims.second) | |
242 | { | |
243 | iterator __victim = __victims.first++; | |
244 | _Base::erase(__victim); | |
245 | ++__count; | |
246 | } | |
247 | return __count; | |
248 | } | |
249 | ||
5ab06c6d PC |
250 | #ifdef __GXX_EXPERIMENTAL_CXX0X__ |
251 | iterator | |
7606bd11 PC |
252 | erase(const_iterator __first, const_iterator __last) |
253 | { return iterator(_Base::erase(__first, __last)); } | |
5ab06c6d | 254 | #else |
1218d701 SR |
255 | void |
256 | erase(iterator __first, iterator __last) | |
7606bd11 | 257 | { _Base::erase(__first, __last); } |
5ab06c6d | 258 | #endif |
1218d701 SR |
259 | |
260 | void | |
261 | swap(multimap& __x) | |
7606bd11 | 262 | { _Base::swap(__x); } |
1218d701 SR |
263 | |
264 | void | |
265 | clear() | |
266 | { this->erase(begin(), end()); } | |
267 | ||
268 | // observers: | |
269 | using _Base::key_comp; | |
270 | using _Base::value_comp; | |
271 | ||
272 | // 23.3.1.3 multimap operations: | |
273 | iterator | |
274 | find(const key_type& __x) | |
275 | { return iterator(_Base::find(__x)); } | |
276 | ||
277 | const_iterator | |
278 | find(const key_type& __x) const | |
279 | { return const_iterator(_Base::find(__x)); } | |
280 | ||
281 | using _Base::count; | |
282 | ||
283 | iterator | |
284 | lower_bound(const key_type& __x) | |
285 | { return iterator(_Base::lower_bound(__x)); } | |
286 | ||
287 | const_iterator | |
288 | lower_bound(const key_type& __x) const | |
289 | { return const_iterator(_Base::lower_bound(__x)); } | |
290 | ||
291 | iterator | |
292 | upper_bound(const key_type& __x) | |
293 | { return iterator(_Base::upper_bound(__x)); } | |
294 | ||
295 | const_iterator | |
296 | upper_bound(const key_type& __x) const | |
297 | { return const_iterator(_Base::upper_bound(__x)); } | |
298 | ||
299 | std::pair<iterator,iterator> | |
300 | equal_range(const key_type& __x) | |
301 | { | |
302 | typedef typename _Base::iterator _Base_iterator; | |
303 | std::pair<_Base_iterator, _Base_iterator> __res = | |
304 | _Base::equal_range(__x); | |
305 | return std::make_pair(iterator(__res.first), | |
306 | iterator(__res.second)); | |
307 | } | |
308 | ||
309 | std::pair<const_iterator,const_iterator> | |
310 | equal_range(const key_type& __x) const | |
311 | { | |
312 | typedef typename _Base::const_iterator _Base_const_iterator; | |
313 | std::pair<_Base_const_iterator, _Base_const_iterator> __res = | |
314 | _Base::equal_range(__x); | |
315 | return std::make_pair(const_iterator(__res.first), | |
316 | const_iterator(__res.second)); | |
317 | } | |
318 | ||
319 | _Base& | |
320 | _M_base() { return *this; } | |
321 | ||
322 | const _Base& | |
323 | _M_base() const { return *this; } | |
324 | }; | |
325 | ||
326 | template<typename _Key, typename _Tp, | |
327 | typename _Compare, typename _Allocator> | |
328 | inline bool | |
329 | operator==(const multimap<_Key, _Tp, _Compare, _Allocator>& __lhs, | |
330 | const multimap<_Key, _Tp, _Compare, _Allocator>& __rhs) | |
331 | { return __lhs._M_base() == __rhs._M_base(); } | |
332 | ||
333 | template<typename _Key, typename _Tp, | |
334 | typename _Compare, typename _Allocator> | |
335 | inline bool | |
336 | operator!=(const multimap<_Key, _Tp, _Compare, _Allocator>& __lhs, | |
337 | const multimap<_Key, _Tp, _Compare, _Allocator>& __rhs) | |
338 | { return __lhs._M_base() != __rhs._M_base(); } | |
339 | ||
340 | template<typename _Key, typename _Tp, | |
341 | typename _Compare, typename _Allocator> | |
342 | inline bool | |
343 | operator<(const multimap<_Key, _Tp, _Compare, _Allocator>& __lhs, | |
344 | const multimap<_Key, _Tp, _Compare, _Allocator>& __rhs) | |
345 | { return __lhs._M_base() < __rhs._M_base(); } | |
346 | ||
347 | template<typename _Key, typename _Tp, | |
348 | typename _Compare, typename _Allocator> | |
349 | inline bool | |
350 | operator<=(const multimap<_Key, _Tp, _Compare, _Allocator>& __lhs, | |
351 | const multimap<_Key, _Tp, _Compare, _Allocator>& __rhs) | |
352 | { return __lhs._M_base() <= __rhs._M_base(); } | |
353 | ||
354 | template<typename _Key, typename _Tp, | |
355 | typename _Compare, typename _Allocator> | |
356 | inline bool | |
357 | operator>=(const multimap<_Key, _Tp, _Compare, _Allocator>& __lhs, | |
358 | const multimap<_Key, _Tp, _Compare, _Allocator>& __rhs) | |
359 | { return __lhs._M_base() >= __rhs._M_base(); } | |
360 | ||
361 | template<typename _Key, typename _Tp, | |
362 | typename _Compare, typename _Allocator> | |
363 | inline bool | |
364 | operator>(const multimap<_Key, _Tp, _Compare, _Allocator>& __lhs, | |
365 | const multimap<_Key, _Tp, _Compare, _Allocator>& __rhs) | |
366 | { return __lhs._M_base() > __rhs._M_base(); } | |
367 | ||
368 | template<typename _Key, typename _Tp, | |
369 | typename _Compare, typename _Allocator> | |
370 | inline void | |
371 | swap(multimap<_Key, _Tp, _Compare, _Allocator>& __lhs, | |
372 | multimap<_Key, _Tp, _Compare, _Allocator>& __rhs) | |
373 | { __lhs.swap(__rhs); } | |
374 | ||
375 | } // namespace __profile | |
376 | } // namespace std | |
377 | ||
378 | #endif |