]> git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/include/profile/multimap.h
re PR libstdc++/44436 ([C++0x] Implement emplace* in associative containers)
[thirdparty/gcc.git] / libstdc++-v3 / include / profile / multimap.h
1 // Profiling multimap implementation -*- C++ -*-
2
3 // Copyright (C) 2009, 2010, 2011, 2012 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 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
34 namespace std _GLIBCXX_VISIBILITY(default)
35 {
36 namespace __profile
37 {
38 /// Class std::multimap wrapper with performance instrumentation.
39 template<typename _Key, typename _Tp, typename _Compare = std::less<_Key>,
40 typename _Allocator = std::allocator<std::pair<const _Key, _Tp> > >
41 class multimap
42 : public _GLIBCXX_STD_C::multimap<_Key, _Tp, _Compare, _Allocator>
43 {
44 typedef _GLIBCXX_STD_C::multimap<_Key, _Tp, _Compare, _Allocator> _Base;
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 // 23.3.1.1 construct/copy/destroy:
67 explicit multimap(const _Compare& __comp = _Compare(),
68 const _Allocator& __a = _Allocator())
69 : _Base(__comp, __a) { }
70
71 template<typename _InputIterator>
72 multimap(_InputIterator __first, _InputIterator __last,
73 const _Compare& __comp = _Compare(),
74 const _Allocator& __a = _Allocator())
75 : _Base(__first, __last, __comp, __a) { }
76
77 multimap(const multimap& __x)
78 : _Base(__x) { }
79
80 multimap(const _Base& __x)
81 : _Base(__x) { }
82
83 #ifdef __GXX_EXPERIMENTAL_CXX0X__
84 multimap(multimap&& __x)
85 noexcept(is_nothrow_copy_constructible<_Compare>::value)
86 : _Base(std::move(__x))
87 { }
88
89 multimap(initializer_list<value_type> __l,
90 const _Compare& __c = _Compare(),
91 const allocator_type& __a = allocator_type())
92 : _Base(__l, __c, __a) { }
93 #endif
94
95 ~multimap() _GLIBCXX_NOEXCEPT { }
96
97 multimap&
98 operator=(const multimap& __x)
99 {
100 *static_cast<_Base*>(this) = __x;
101 return *this;
102 }
103
104 #ifdef __GXX_EXPERIMENTAL_CXX0X__
105 multimap&
106 operator=(multimap&& __x)
107 {
108 // NB: DR 1204.
109 // NB: DR 675.
110 this->clear();
111 this->swap(__x);
112 return *this;
113 }
114
115 multimap&
116 operator=(initializer_list<value_type> __l)
117 {
118 this->clear();
119 this->insert(__l);
120 return *this;
121 }
122 #endif
123
124 using _Base::get_allocator;
125
126 // iterators:
127 iterator
128 begin() _GLIBCXX_NOEXCEPT
129 { return iterator(_Base::begin()); }
130
131 const_iterator
132 begin() const _GLIBCXX_NOEXCEPT
133 { return const_iterator(_Base::begin()); }
134
135 iterator
136 end() _GLIBCXX_NOEXCEPT
137 { return iterator(_Base::end()); }
138
139 const_iterator
140 end() const _GLIBCXX_NOEXCEPT
141 { return const_iterator(_Base::end()); }
142
143 reverse_iterator
144 rbegin() _GLIBCXX_NOEXCEPT
145 { return reverse_iterator(end()); }
146
147 const_reverse_iterator
148 rbegin() const _GLIBCXX_NOEXCEPT
149 { return const_reverse_iterator(end()); }
150
151 reverse_iterator
152 rend() _GLIBCXX_NOEXCEPT
153 { return reverse_iterator(begin()); }
154
155 const_reverse_iterator
156 rend() const _GLIBCXX_NOEXCEPT
157 { return const_reverse_iterator(begin()); }
158
159 #ifdef __GXX_EXPERIMENTAL_CXX0X__
160 const_iterator
161 cbegin() const noexcept
162 { return const_iterator(_Base::begin()); }
163
164 const_iterator
165 cend() const noexcept
166 { return const_iterator(_Base::end()); }
167
168 const_reverse_iterator
169 crbegin() const noexcept
170 { return const_reverse_iterator(end()); }
171
172 const_reverse_iterator
173 crend() const noexcept
174 { return const_reverse_iterator(begin()); }
175 #endif
176
177 // capacity:
178 using _Base::empty;
179 using _Base::size;
180 using _Base::max_size;
181
182 // modifiers:
183 #ifdef __GXX_EXPERIMENTAL_CXX0X__
184 template<typename... _Args>
185 iterator
186 emplace(_Args&&... __args)
187 {
188 return iterator(_Base::emplace(std::forward<_Args>(__args)...));
189 }
190
191 template<typename... _Args>
192 iterator
193 emplace_hint(const_iterator __pos, _Args&&... __args)
194 {
195 return iterator(_Base::emplace_hint(__pos,
196 std::forward<_Args>(__args)...));
197 }
198 #endif
199
200 iterator
201 insert(const value_type& __x)
202 { return iterator(_Base::insert(__x)); }
203
204 #ifdef __GXX_EXPERIMENTAL_CXX0X__
205 template<typename _Pair, typename = typename
206 std::enable_if<std::is_constructible<value_type,
207 _Pair&&>::value>::type>
208 iterator
209 insert(_Pair&& __x)
210 { return iterator(_Base::insert(std::forward<_Pair>(__x))); }
211 #endif
212
213 #ifdef __GXX_EXPERIMENTAL_CXX0X__
214 void
215 insert(std::initializer_list<value_type> __list)
216 { _Base::insert(__list); }
217 #endif
218
219 iterator
220 #ifdef __GXX_EXPERIMENTAL_CXX0X__
221 insert(const_iterator __position, const value_type& __x)
222 #else
223 insert(iterator __position, const value_type& __x)
224 #endif
225 { return iterator(_Base::insert(__position, __x)); }
226
227 #ifdef __GXX_EXPERIMENTAL_CXX0X__
228 template<typename _Pair, typename = typename
229 std::enable_if<std::is_constructible<value_type,
230 _Pair&&>::value>::type>
231 iterator
232 insert(const_iterator __position, _Pair&& __x)
233 { return iterator(_Base::insert(__position,
234 std::forward<_Pair>(__x))); }
235 #endif
236
237 template<typename _InputIterator>
238 void
239 insert(_InputIterator __first, _InputIterator __last)
240 { _Base::insert(__first, __last); }
241
242 #ifdef __GXX_EXPERIMENTAL_CXX0X__
243 iterator
244 erase(const_iterator __position)
245 { return iterator(_Base::erase(__position)); }
246
247 iterator
248 erase(iterator __position)
249 { return iterator(_Base::erase(__position)); }
250 #else
251 void
252 erase(iterator __position)
253 { _Base::erase(__position); }
254 #endif
255
256 size_type
257 erase(const key_type& __x)
258 {
259 std::pair<iterator, iterator> __victims = this->equal_range(__x);
260 size_type __count = 0;
261 while (__victims.first != __victims.second)
262 {
263 iterator __victim = __victims.first++;
264 _Base::erase(__victim);
265 ++__count;
266 }
267 return __count;
268 }
269
270 #ifdef __GXX_EXPERIMENTAL_CXX0X__
271 iterator
272 erase(const_iterator __first, const_iterator __last)
273 { return iterator(_Base::erase(__first, __last)); }
274 #else
275 void
276 erase(iterator __first, iterator __last)
277 { _Base::erase(__first, __last); }
278 #endif
279
280 void
281 swap(multimap& __x)
282 { _Base::swap(__x); }
283
284 void
285 clear() _GLIBCXX_NOEXCEPT
286 { this->erase(begin(), end()); }
287
288 // observers:
289 using _Base::key_comp;
290 using _Base::value_comp;
291
292 // 23.3.1.3 multimap operations:
293 iterator
294 find(const key_type& __x)
295 { return iterator(_Base::find(__x)); }
296
297 const_iterator
298 find(const key_type& __x) const
299 { return const_iterator(_Base::find(__x)); }
300
301 using _Base::count;
302
303 iterator
304 lower_bound(const key_type& __x)
305 { return iterator(_Base::lower_bound(__x)); }
306
307 const_iterator
308 lower_bound(const key_type& __x) const
309 { return const_iterator(_Base::lower_bound(__x)); }
310
311 iterator
312 upper_bound(const key_type& __x)
313 { return iterator(_Base::upper_bound(__x)); }
314
315 const_iterator
316 upper_bound(const key_type& __x) const
317 { return const_iterator(_Base::upper_bound(__x)); }
318
319 std::pair<iterator,iterator>
320 equal_range(const key_type& __x)
321 {
322 typedef typename _Base::iterator _Base_iterator;
323 std::pair<_Base_iterator, _Base_iterator> __res =
324 _Base::equal_range(__x);
325 return std::make_pair(iterator(__res.first),
326 iterator(__res.second));
327 }
328
329 std::pair<const_iterator,const_iterator>
330 equal_range(const key_type& __x) const
331 {
332 typedef typename _Base::const_iterator _Base_const_iterator;
333 std::pair<_Base_const_iterator, _Base_const_iterator> __res =
334 _Base::equal_range(__x);
335 return std::make_pair(const_iterator(__res.first),
336 const_iterator(__res.second));
337 }
338
339 _Base&
340 _M_base() _GLIBCXX_NOEXCEPT { return *this; }
341
342 const _Base&
343 _M_base() const _GLIBCXX_NOEXCEPT { return *this; }
344 };
345
346 template<typename _Key, typename _Tp,
347 typename _Compare, typename _Allocator>
348 inline bool
349 operator==(const multimap<_Key, _Tp, _Compare, _Allocator>& __lhs,
350 const multimap<_Key, _Tp, _Compare, _Allocator>& __rhs)
351 { return __lhs._M_base() == __rhs._M_base(); }
352
353 template<typename _Key, typename _Tp,
354 typename _Compare, typename _Allocator>
355 inline bool
356 operator!=(const multimap<_Key, _Tp, _Compare, _Allocator>& __lhs,
357 const multimap<_Key, _Tp, _Compare, _Allocator>& __rhs)
358 { return __lhs._M_base() != __rhs._M_base(); }
359
360 template<typename _Key, typename _Tp,
361 typename _Compare, typename _Allocator>
362 inline bool
363 operator<(const multimap<_Key, _Tp, _Compare, _Allocator>& __lhs,
364 const multimap<_Key, _Tp, _Compare, _Allocator>& __rhs)
365 { return __lhs._M_base() < __rhs._M_base(); }
366
367 template<typename _Key, typename _Tp,
368 typename _Compare, typename _Allocator>
369 inline bool
370 operator<=(const multimap<_Key, _Tp, _Compare, _Allocator>& __lhs,
371 const multimap<_Key, _Tp, _Compare, _Allocator>& __rhs)
372 { return __lhs._M_base() <= __rhs._M_base(); }
373
374 template<typename _Key, typename _Tp,
375 typename _Compare, typename _Allocator>
376 inline bool
377 operator>=(const multimap<_Key, _Tp, _Compare, _Allocator>& __lhs,
378 const multimap<_Key, _Tp, _Compare, _Allocator>& __rhs)
379 { return __lhs._M_base() >= __rhs._M_base(); }
380
381 template<typename _Key, typename _Tp,
382 typename _Compare, typename _Allocator>
383 inline bool
384 operator>(const multimap<_Key, _Tp, _Compare, _Allocator>& __lhs,
385 const multimap<_Key, _Tp, _Compare, _Allocator>& __rhs)
386 { return __lhs._M_base() > __rhs._M_base(); }
387
388 template<typename _Key, typename _Tp,
389 typename _Compare, typename _Allocator>
390 inline void
391 swap(multimap<_Key, _Tp, _Compare, _Allocator>& __lhs,
392 multimap<_Key, _Tp, _Compare, _Allocator>& __rhs)
393 { __lhs.swap(__rhs); }
394
395 } // namespace __profile
396 } // namespace std
397
398 #endif