2014-01-17 François Dumont <fdumont@gcc.gnu.org>
[official-gcc.git] / libstdc++-v3 / include / profile / multimap.h
blob4a703ce36365b01ae2b74aada2c2faac274b032e
1 // Profiling multimap implementation -*- C++ -*-
3 // Copyright (C) 2009-2014 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.
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 // 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.
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/>.
25 /** @file profile/multimap.h
26 * This file is a GNU profile extension to the Standard C++ Library.
29 #ifndef _GLIBCXX_PROFILE_MULTIMAP_H
30 #define _GLIBCXX_PROFILE_MULTIMAP_H 1
32 #include <utility>
34 namespace std _GLIBCXX_VISIBILITY(default)
36 namespace __profile
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>
44 typedef _GLIBCXX_STD_C::multimap<_Key, _Tp, _Compare, _Allocator> _Base;
46 #if __cplusplus >= 201103L
47 typedef __gnu_cxx::__alloc_traits<_Allocator> _Alloc_traits;
48 #endif
50 public:
51 // types:
52 typedef _Key key_type;
53 typedef _Tp mapped_type;
54 typedef std::pair<const _Key, _Tp> value_type;
55 typedef _Compare key_compare;
56 typedef _Allocator allocator_type;
57 typedef typename _Base::reference reference;
58 typedef typename _Base::const_reference const_reference;
60 typedef typename _Base::iterator iterator;
61 typedef typename _Base::const_iterator const_iterator;
62 typedef typename _Base::reverse_iterator reverse_iterator;
63 typedef typename _Base::const_reverse_iterator const_reverse_iterator;
65 typedef typename _Base::size_type size_type;
66 typedef typename _Base::difference_type difference_type;
67 typedef typename _Base::pointer pointer;
68 typedef typename _Base::const_pointer const_pointer;
70 // 23.3.1.1 construct/copy/destroy:
71 explicit multimap(const _Compare& __comp = _Compare(),
72 const _Allocator& __a = _Allocator())
73 : _Base(__comp, __a) { }
75 #if __cplusplus >= 201103L
76 template<typename _InputIterator,
77 typename = std::_RequireInputIter<_InputIterator>>
78 #else
79 template<typename _InputIterator>
80 #endif
81 multimap(_InputIterator __first, _InputIterator __last,
82 const _Compare& __comp = _Compare(),
83 const _Allocator& __a = _Allocator())
84 : _Base(__first, __last, __comp, __a) { }
86 #if __cplusplus < 201103L
87 multimap(const multimap& __x)
88 : _Base(__x) { }
89 #else
90 multimap(const multimap&) = default;
91 multimap(multimap&&) = default;
93 multimap(initializer_list<value_type> __l,
94 const _Compare& __c = _Compare(),
95 const allocator_type& __a = allocator_type())
96 : _Base(__l, __c, __a) { }
98 explicit
99 multimap(const allocator_type& __a)
100 : _Base(__a) { }
102 multimap(const multimap& __x, const allocator_type& __a)
103 : _Base(__x, __a) { }
105 multimap(multimap&& __x, const allocator_type& __a)
106 noexcept(is_nothrow_copy_constructible<_Compare>::value
107 && _Alloc_traits::_S_always_equal())
108 : _Base(std::move(__x), __a) { }
110 multimap(initializer_list<value_type> __l, const allocator_type& __a)
111 : _Base(__l, __a) { }
113 template<typename _InputIterator>
114 multimap(_InputIterator __first, _InputIterator __last,
115 const allocator_type& __a)
116 : _Base(__first, __last, __a) { }
117 #endif
119 multimap(const _Base& __x)
120 : _Base(__x) { }
122 ~multimap() _GLIBCXX_NOEXCEPT { }
124 #if __cplusplus < 201103L
125 multimap&
126 operator=(const multimap& __x)
128 _M_base() = __x;
129 return *this;
131 #else
132 multimap&
133 operator=(const multimap&) = default;
135 multimap&
136 operator=(multimap&&) = default;
138 multimap&
139 operator=(initializer_list<value_type> __l)
141 _M_base() = __l;
142 return *this;
144 #endif
146 using _Base::get_allocator;
148 // iterators:
149 iterator
150 begin() _GLIBCXX_NOEXCEPT
151 { return iterator(_Base::begin()); }
153 const_iterator
154 begin() const _GLIBCXX_NOEXCEPT
155 { return const_iterator(_Base::begin()); }
157 iterator
158 end() _GLIBCXX_NOEXCEPT
159 { return iterator(_Base::end()); }
161 const_iterator
162 end() const _GLIBCXX_NOEXCEPT
163 { return const_iterator(_Base::end()); }
165 reverse_iterator
166 rbegin() _GLIBCXX_NOEXCEPT
167 { return reverse_iterator(end()); }
169 const_reverse_iterator
170 rbegin() const _GLIBCXX_NOEXCEPT
171 { return const_reverse_iterator(end()); }
173 reverse_iterator
174 rend() _GLIBCXX_NOEXCEPT
175 { return reverse_iterator(begin()); }
177 const_reverse_iterator
178 rend() const _GLIBCXX_NOEXCEPT
179 { return const_reverse_iterator(begin()); }
181 #if __cplusplus >= 201103L
182 const_iterator
183 cbegin() const noexcept
184 { return const_iterator(_Base::begin()); }
186 const_iterator
187 cend() const noexcept
188 { return const_iterator(_Base::end()); }
190 const_reverse_iterator
191 crbegin() const noexcept
192 { return const_reverse_iterator(end()); }
194 const_reverse_iterator
195 crend() const noexcept
196 { return const_reverse_iterator(begin()); }
197 #endif
199 // capacity:
200 using _Base::empty;
201 using _Base::size;
202 using _Base::max_size;
204 // modifiers:
205 #if __cplusplus >= 201103L
206 template<typename... _Args>
207 iterator
208 emplace(_Args&&... __args)
210 return iterator(_Base::emplace(std::forward<_Args>(__args)...));
213 template<typename... _Args>
214 iterator
215 emplace_hint(const_iterator __pos, _Args&&... __args)
217 return iterator(_Base::emplace_hint(__pos,
218 std::forward<_Args>(__args)...));
220 #endif
222 iterator
223 insert(const value_type& __x)
224 { return iterator(_Base::insert(__x)); }
226 #if __cplusplus >= 201103L
227 template<typename _Pair, typename = typename
228 std::enable_if<std::is_constructible<value_type,
229 _Pair&&>::value>::type>
230 iterator
231 insert(_Pair&& __x)
232 { return iterator(_Base::insert(std::forward<_Pair>(__x))); }
233 #endif
235 #if __cplusplus >= 201103L
236 void
237 insert(std::initializer_list<value_type> __list)
238 { _Base::insert(__list); }
239 #endif
241 iterator
242 #if __cplusplus >= 201103L
243 insert(const_iterator __position, const value_type& __x)
244 #else
245 insert(iterator __position, const value_type& __x)
246 #endif
247 { return iterator(_Base::insert(__position, __x)); }
249 #if __cplusplus >= 201103L
250 template<typename _Pair, typename = typename
251 std::enable_if<std::is_constructible<value_type,
252 _Pair&&>::value>::type>
253 iterator
254 insert(const_iterator __position, _Pair&& __x)
255 { return iterator(_Base::insert(__position,
256 std::forward<_Pair>(__x))); }
257 #endif
259 #if __cplusplus >= 201103L
260 template<typename _InputIterator,
261 typename = std::_RequireInputIter<_InputIterator>>
262 #else
263 template<typename _InputIterator>
264 #endif
265 void
266 insert(_InputIterator __first, _InputIterator __last)
267 { _Base::insert(__first, __last); }
269 #if __cplusplus >= 201103L
270 iterator
271 erase(const_iterator __position)
272 { return iterator(_Base::erase(__position)); }
274 iterator
275 erase(iterator __position)
276 { return iterator(_Base::erase(__position)); }
277 #else
278 void
279 erase(iterator __position)
280 { _Base::erase(__position); }
281 #endif
283 size_type
284 erase(const key_type& __x)
286 std::pair<iterator, iterator> __victims = this->equal_range(__x);
287 size_type __count = 0;
288 while (__victims.first != __victims.second)
290 iterator __victim = __victims.first++;
291 _Base::erase(__victim);
292 ++__count;
294 return __count;
297 #if __cplusplus >= 201103L
298 iterator
299 erase(const_iterator __first, const_iterator __last)
300 { return iterator(_Base::erase(__first, __last)); }
301 #else
302 void
303 erase(iterator __first, iterator __last)
304 { _Base::erase(__first, __last); }
305 #endif
307 void
308 swap(multimap& __x)
309 #if __cplusplus >= 201103L
310 noexcept(_Alloc_traits::_S_nothrow_swap())
311 #endif
312 { _Base::swap(__x); }
314 void
315 clear() _GLIBCXX_NOEXCEPT
316 { this->erase(begin(), end()); }
318 // observers:
319 using _Base::key_comp;
320 using _Base::value_comp;
322 // 23.3.1.3 multimap operations:
323 iterator
324 find(const key_type& __x)
325 { return iterator(_Base::find(__x)); }
327 const_iterator
328 find(const key_type& __x) const
329 { return const_iterator(_Base::find(__x)); }
331 using _Base::count;
333 iterator
334 lower_bound(const key_type& __x)
335 { return iterator(_Base::lower_bound(__x)); }
337 const_iterator
338 lower_bound(const key_type& __x) const
339 { return const_iterator(_Base::lower_bound(__x)); }
341 iterator
342 upper_bound(const key_type& __x)
343 { return iterator(_Base::upper_bound(__x)); }
345 const_iterator
346 upper_bound(const key_type& __x) const
347 { return const_iterator(_Base::upper_bound(__x)); }
349 std::pair<iterator,iterator>
350 equal_range(const key_type& __x)
352 typedef typename _Base::iterator _Base_iterator;
353 std::pair<_Base_iterator, _Base_iterator> __res =
354 _Base::equal_range(__x);
355 return std::make_pair(iterator(__res.first),
356 iterator(__res.second));
359 std::pair<const_iterator,const_iterator>
360 equal_range(const key_type& __x) const
362 typedef typename _Base::const_iterator _Base_const_iterator;
363 std::pair<_Base_const_iterator, _Base_const_iterator> __res =
364 _Base::equal_range(__x);
365 return std::make_pair(const_iterator(__res.first),
366 const_iterator(__res.second));
369 _Base&
370 _M_base() _GLIBCXX_NOEXCEPT { return *this; }
372 const _Base&
373 _M_base() const _GLIBCXX_NOEXCEPT { return *this; }
376 template<typename _Key, typename _Tp,
377 typename _Compare, typename _Allocator>
378 inline bool
379 operator==(const multimap<_Key, _Tp, _Compare, _Allocator>& __lhs,
380 const multimap<_Key, _Tp, _Compare, _Allocator>& __rhs)
381 { return __lhs._M_base() == __rhs._M_base(); }
383 template<typename _Key, typename _Tp,
384 typename _Compare, typename _Allocator>
385 inline bool
386 operator!=(const multimap<_Key, _Tp, _Compare, _Allocator>& __lhs,
387 const multimap<_Key, _Tp, _Compare, _Allocator>& __rhs)
388 { return __lhs._M_base() != __rhs._M_base(); }
390 template<typename _Key, typename _Tp,
391 typename _Compare, typename _Allocator>
392 inline bool
393 operator<(const multimap<_Key, _Tp, _Compare, _Allocator>& __lhs,
394 const multimap<_Key, _Tp, _Compare, _Allocator>& __rhs)
395 { return __lhs._M_base() < __rhs._M_base(); }
397 template<typename _Key, typename _Tp,
398 typename _Compare, typename _Allocator>
399 inline bool
400 operator<=(const multimap<_Key, _Tp, _Compare, _Allocator>& __lhs,
401 const multimap<_Key, _Tp, _Compare, _Allocator>& __rhs)
402 { return __lhs._M_base() <= __rhs._M_base(); }
404 template<typename _Key, typename _Tp,
405 typename _Compare, typename _Allocator>
406 inline bool
407 operator>=(const multimap<_Key, _Tp, _Compare, _Allocator>& __lhs,
408 const multimap<_Key, _Tp, _Compare, _Allocator>& __rhs)
409 { return __lhs._M_base() >= __rhs._M_base(); }
411 template<typename _Key, typename _Tp,
412 typename _Compare, typename _Allocator>
413 inline bool
414 operator>(const multimap<_Key, _Tp, _Compare, _Allocator>& __lhs,
415 const multimap<_Key, _Tp, _Compare, _Allocator>& __rhs)
416 { return __lhs._M_base() > __rhs._M_base(); }
418 template<typename _Key, typename _Tp,
419 typename _Compare, typename _Allocator>
420 inline void
421 swap(multimap<_Key, _Tp, _Compare, _Allocator>& __lhs,
422 multimap<_Key, _Tp, _Compare, _Allocator>& __rhs)
423 { __lhs.swap(__rhs); }
425 } // namespace __profile
426 } // namespace std
428 #endif