]>
Commit | Line | Data |
---|---|---|
1d61409b | 1 | // Multimap implementation -*- C++ -*- |
2 | ||
fbd26352 | 3 | // Copyright (C) 2001-2019 Free Software Foundation, Inc. |
1d61409b | 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 | |
6bc9506f | 8 | // Free Software Foundation; either version 3, or (at your option) |
1d61409b | 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 | ||
6bc9506f | 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. | |
1d61409b | 19 | |
6bc9506f | 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/>. | |
1d61409b | 24 | |
1d487aca | 25 | /* |
26 | * | |
27 | * Copyright (c) 1994 | |
28 | * Hewlett-Packard Company | |
29 | * | |
30 | * Permission to use, copy, modify, distribute and sell this software | |
31 | * and its documentation for any purpose is hereby granted without fee, | |
32 | * provided that the above copyright notice appear in all copies and | |
33 | * that both that copyright notice and this permission notice appear | |
34 | * in supporting documentation. Hewlett-Packard Company makes no | |
35 | * representations about the suitability of this software for any | |
36 | * purpose. It is provided "as is" without express or implied warranty. | |
37 | * | |
38 | * | |
39 | * Copyright (c) 1996,1997 | |
40 | * Silicon Graphics Computer Systems, Inc. | |
41 | * | |
42 | * Permission to use, copy, modify, distribute and sell this software | |
43 | * and its documentation for any purpose is hereby granted without fee, | |
44 | * provided that the above copyright notice appear in all copies and | |
45 | * that both that copyright notice and this permission notice appear | |
46 | * in supporting documentation. Silicon Graphics makes no | |
47 | * representations about the suitability of this software for any | |
48 | * purpose. It is provided "as is" without express or implied warranty. | |
49 | */ | |
50 | ||
5846aeac | 51 | /** @file bits/stl_multimap.h |
7a472ef1 | 52 | * This is an internal header file, included by other library headers. |
5846aeac | 53 | * Do not attempt to use it directly. @headername{map} |
1d487aca | 54 | */ |
55 | ||
f142a34a | 56 | #ifndef _STL_MULTIMAP_H |
57 | #define _STL_MULTIMAP_H 1 | |
1d487aca | 58 | |
40b55285 | 59 | #include <bits/concept_check.h> |
0c8766b1 | 60 | #if __cplusplus >= 201103L |
b23fdac1 | 61 | #include <initializer_list> |
fbb4cdfc | 62 | #endif |
1d487aca | 63 | |
2948dd21 | 64 | namespace std _GLIBCXX_VISIBILITY(default) |
65 | { | |
ae6a4ce9 | 66 | _GLIBCXX_BEGIN_NAMESPACE_VERSION |
2948dd21 | 67 | _GLIBCXX_BEGIN_NAMESPACE_CONTAINER |
1069247d | 68 | |
67218f06 | 69 | template <typename _Key, typename _Tp, typename _Compare, typename _Alloc> |
70 | class map; | |
71 | ||
32bb2cd7 | 72 | /** |
73 | * @brief A standard container made up of (key,value) pairs, which can be | |
74 | * retrieved based on a key, in logarithmic time. | |
f344810f | 75 | * |
48e3f567 | 76 | * @ingroup associative_containers |
f344810f | 77 | * |
7184845c | 78 | * @tparam _Key Type of key objects. |
79 | * @tparam _Tp Type of mapped objects. | |
80 | * @tparam _Compare Comparison function object type, defaults to less<_Key>. | |
b49b5511 | 81 | * @tparam _Alloc Allocator type, defaults to |
7184845c | 82 | * allocator<pair<const _Key, _Tp>. |
83 | * | |
32bb2cd7 | 84 | * Meets the requirements of a <a href="tables.html#65">container</a>, a |
85 | * <a href="tables.html#66">reversible container</a>, and an | |
86 | * <a href="tables.html#69">associative container</a> (using equivalent | |
87 | * keys). For a @c multimap<Key,T> the key_type is Key, the mapped_type | |
88 | * is T, and the value_type is std::pair<const Key,T>. | |
f344810f | 89 | * |
32bb2cd7 | 90 | * Multimaps support bidirectional iterators. |
f344810f | 91 | * |
32bb2cd7 | 92 | * The private tree data is declared exactly the same way for map and |
93 | * multimap; the distinction is made entirely in how the tree functions are | |
94 | * called (*_unique versus *_equal, same as the standard). | |
32bb2cd7 | 95 | */ |
2263cabb | 96 | template <typename _Key, typename _Tp, |
97 | typename _Compare = std::less<_Key>, | |
98 | typename _Alloc = std::allocator<std::pair<const _Key, _Tp> > > | |
32bb2cd7 | 99 | class multimap |
b9156b5c | 100 | { |
b9156b5c | 101 | public: |
b49b5511 | 102 | typedef _Key key_type; |
103 | typedef _Tp mapped_type; | |
104 | typedef std::pair<const _Key, _Tp> value_type; | |
105 | typedef _Compare key_compare; | |
106 | typedef _Alloc allocator_type; | |
bae9b8af | 107 | |
171a395a | 108 | private: |
b49b5511 | 109 | #ifdef _GLIBCXX_CONCEPT_CHECKS |
171a395a | 110 | // concept requirements |
b49b5511 | 111 | typedef typename _Alloc::value_type _Alloc_value_type; |
112 | # if __cplusplus < 201103L | |
171a395a | 113 | __glibcxx_class_requires(_Tp, _SGIAssignableConcept) |
b49b5511 | 114 | # endif |
171a395a | 115 | __glibcxx_class_requires4(_Compare, bool, _Key, _Key, |
116 | _BinaryFunctionConcept) | |
6b9314a8 | 117 | __glibcxx_class_requires2(value_type, _Alloc_value_type, _SameTypeConcept) |
b49b5511 | 118 | #endif |
171a395a | 119 | |
7086d631 | 120 | #if __cplusplus >= 201103L && defined(__STRICT_ANSI__) |
121 | static_assert(is_same<typename _Alloc::value_type, value_type>::value, | |
122 | "std::multimap must have the same value_type as its allocator"); | |
123 | #endif | |
124 | ||
171a395a | 125 | public: |
b9156b5c | 126 | class value_compare |
be7e699b | 127 | : public std::binary_function<value_type, value_type, bool> |
32bb2cd7 | 128 | { |
171a395a | 129 | friend class multimap<_Key, _Tp, _Compare, _Alloc>; |
32bb2cd7 | 130 | protected: |
b9156b5c | 131 | _Compare comp; |
bae9b8af | 132 | |
b9156b5c | 133 | value_compare(_Compare __c) |
62ba3194 | 134 | : comp(__c) { } |
bae9b8af | 135 | |
32bb2cd7 | 136 | public: |
b9156b5c | 137 | bool operator()(const value_type& __x, const value_type& __y) const |
138 | { return comp(__x.first, __y.first); } | |
139 | }; | |
bae9b8af | 140 | |
b9156b5c | 141 | private: |
0aeadebf | 142 | /// This turns a red-black tree into a [multi]map. |
709dc991 | 143 | typedef typename __gnu_cxx::__alloc_traits<_Alloc>::template |
144 | rebind<value_type>::other _Pair_alloc_type; | |
171a395a | 145 | |
146 | typedef _Rb_tree<key_type, value_type, _Select1st<value_type>, | |
147 | key_compare, _Pair_alloc_type> _Rep_type; | |
0aeadebf | 148 | /// The actual tree structure. |
b9156b5c | 149 | _Rep_type _M_t; |
bae9b8af | 150 | |
709dc991 | 151 | typedef __gnu_cxx::__alloc_traits<_Pair_alloc_type> _Alloc_traits; |
152 | ||
b9156b5c | 153 | public: |
154 | // many of these are specified differently in ISO, but the following are | |
155 | // "functionally equivalent" | |
b49b5511 | 156 | typedef typename _Alloc_traits::pointer pointer; |
157 | typedef typename _Alloc_traits::const_pointer const_pointer; | |
158 | typedef typename _Alloc_traits::reference reference; | |
159 | typedef typename _Alloc_traits::const_reference const_reference; | |
160 | typedef typename _Rep_type::iterator iterator; | |
161 | typedef typename _Rep_type::const_iterator const_iterator; | |
162 | typedef typename _Rep_type::size_type size_type; | |
163 | typedef typename _Rep_type::difference_type difference_type; | |
164 | typedef typename _Rep_type::reverse_iterator reverse_iterator; | |
b9156b5c | 165 | typedef typename _Rep_type::const_reverse_iterator const_reverse_iterator; |
bae9b8af | 166 | |
67218f06 | 167 | #if __cplusplus > 201402L |
168 | using node_type = typename _Rep_type::node_type; | |
169 | #endif | |
170 | ||
b9156b5c | 171 | // [23.3.2] construct/copy/destroy |
172 | // (get_allocator() is also listed in this section) | |
fc04fffc | 173 | |
b9156b5c | 174 | /** |
175 | * @brief Default constructor creates no elements. | |
176 | */ | |
32dd4654 | 177 | #if __cplusplus < 201103L |
178 | multimap() : _M_t() { } | |
179 | #else | |
180 | multimap() = default; | |
181 | #endif | |
bae9b8af | 182 | |
b9156b5c | 183 | /** |
707bff49 | 184 | * @brief Creates a %multimap with no elements. |
e12e4f3b | 185 | * @param __comp A comparison object. |
186 | * @param __a An allocator object. | |
b9156b5c | 187 | */ |
188 | explicit | |
189 | multimap(const _Compare& __comp, | |
190 | const allocator_type& __a = allocator_type()) | |
852b4cc2 | 191 | : _M_t(__comp, _Pair_alloc_type(__a)) { } |
bae9b8af | 192 | |
b9156b5c | 193 | /** |
194 | * @brief %Multimap copy constructor. | |
b9156b5c | 195 | * |
9f6c7b30 | 196 | * Whether the allocator is copied depends on the allocator traits. |
b9156b5c | 197 | */ |
9f6c7b30 | 198 | #if __cplusplus < 201103L |
b9156b5c | 199 | multimap(const multimap& __x) |
32bb2cd7 | 200 | : _M_t(__x._M_t) { } |
9f6c7b30 | 201 | #else |
202 | multimap(const multimap&) = default; | |
bae9b8af | 203 | |
707bff49 | 204 | /** |
205 | * @brief %Multimap move constructor. | |
707bff49 | 206 | * |
9f6c7b30 | 207 | * The newly-created %multimap contains the exact contents of the |
208 | * moved instance. The moved instance is a valid, but unspecified | |
209 | * %multimap. | |
707bff49 | 210 | */ |
9f6c7b30 | 211 | multimap(multimap&&) = default; |
b23fdac1 | 212 | |
213 | /** | |
214 | * @brief Builds a %multimap from an initializer_list. | |
e12e4f3b | 215 | * @param __l An initializer_list. |
216 | * @param __comp A comparison functor. | |
217 | * @param __a An allocator object. | |
b23fdac1 | 218 | * |
219 | * Create a %multimap consisting of copies of the elements from | |
220 | * the initializer_list. This is linear in N if the list is already | |
221 | * sorted, and NlogN otherwise (where N is @a __l.size()). | |
222 | */ | |
223 | multimap(initializer_list<value_type> __l, | |
224 | const _Compare& __comp = _Compare(), | |
225 | const allocator_type& __a = allocator_type()) | |
852b4cc2 | 226 | : _M_t(__comp, _Pair_alloc_type(__a)) |
dc0e5150 | 227 | { _M_t._M_insert_range_equal(__l.begin(), __l.end()); } |
709dc991 | 228 | |
229 | /// Allocator-extended default constructor. | |
230 | explicit | |
231 | multimap(const allocator_type& __a) | |
78875b4c | 232 | : _M_t(_Pair_alloc_type(__a)) { } |
709dc991 | 233 | |
234 | /// Allocator-extended copy constructor. | |
235 | multimap(const multimap& __m, const allocator_type& __a) | |
236 | : _M_t(__m._M_t, _Pair_alloc_type(__a)) { } | |
237 | ||
238 | /// Allocator-extended move constructor. | |
239 | multimap(multimap&& __m, const allocator_type& __a) | |
240 | noexcept(is_nothrow_copy_constructible<_Compare>::value | |
241 | && _Alloc_traits::_S_always_equal()) | |
242 | : _M_t(std::move(__m._M_t), _Pair_alloc_type(__a)) { } | |
243 | ||
244 | /// Allocator-extended initialier-list constructor. | |
245 | multimap(initializer_list<value_type> __l, const allocator_type& __a) | |
78875b4c | 246 | : _M_t(_Pair_alloc_type(__a)) |
dc0e5150 | 247 | { _M_t._M_insert_range_equal(__l.begin(), __l.end()); } |
709dc991 | 248 | |
249 | /// Allocator-extended range constructor. | |
250 | template<typename _InputIterator> | |
b49b5511 | 251 | multimap(_InputIterator __first, _InputIterator __last, |
709dc991 | 252 | const allocator_type& __a) |
78875b4c | 253 | : _M_t(_Pair_alloc_type(__a)) |
dc0e5150 | 254 | { _M_t._M_insert_range_equal(__first, __last); } |
707bff49 | 255 | #endif |
256 | ||
b9156b5c | 257 | /** |
258 | * @brief Builds a %multimap from a range. | |
e12e4f3b | 259 | * @param __first An input iterator. |
260 | * @param __last An input iterator. | |
b9156b5c | 261 | * |
262 | * Create a %multimap consisting of copies of the elements from | |
e12e4f3b | 263 | * [__first,__last). This is linear in N if the range is already sorted, |
264 | * and NlogN otherwise (where N is distance(__first,__last)). | |
b9156b5c | 265 | */ |
707bff49 | 266 | template<typename _InputIterator> |
b49b5511 | 267 | multimap(_InputIterator __first, _InputIterator __last) |
707bff49 | 268 | : _M_t() |
dc0e5150 | 269 | { _M_t._M_insert_range_equal(__first, __last); } |
bae9b8af | 270 | |
b9156b5c | 271 | /** |
272 | * @brief Builds a %multimap from a range. | |
e12e4f3b | 273 | * @param __first An input iterator. |
274 | * @param __last An input iterator. | |
275 | * @param __comp A comparison functor. | |
276 | * @param __a An allocator object. | |
b9156b5c | 277 | * |
278 | * Create a %multimap consisting of copies of the elements from | |
e12e4f3b | 279 | * [__first,__last). This is linear in N if the range is already sorted, |
280 | * and NlogN otherwise (where N is distance(__first,__last)). | |
b9156b5c | 281 | */ |
707bff49 | 282 | template<typename _InputIterator> |
b49b5511 | 283 | multimap(_InputIterator __first, _InputIterator __last, |
b9156b5c | 284 | const _Compare& __comp, |
285 | const allocator_type& __a = allocator_type()) | |
852b4cc2 | 286 | : _M_t(__comp, _Pair_alloc_type(__a)) |
dc0e5150 | 287 | { _M_t._M_insert_range_equal(__first, __last); } |
bae9b8af | 288 | |
9f6c7b30 | 289 | #if __cplusplus >= 201103L |
b9156b5c | 290 | /** |
291 | * The dtor only erases the elements, and note that if the elements | |
292 | * themselves are pointers, the pointed-to memory is not touched in any | |
9f6c7b30 | 293 | * way. Managing the pointer is the user's responsibility. |
b9156b5c | 294 | */ |
9f6c7b30 | 295 | ~multimap() = default; |
296 | #endif | |
bae9b8af | 297 | |
b9156b5c | 298 | /** |
299 | * @brief %Multimap assignment operator. | |
d481d9a2 | 300 | * |
301 | * Whether the allocator is copied depends on the allocator traits. | |
b9156b5c | 302 | */ |
9f6c7b30 | 303 | #if __cplusplus < 201103L |
b9156b5c | 304 | multimap& |
305 | operator=(const multimap& __x) | |
306 | { | |
307 | _M_t = __x._M_t; | |
308 | return *this; | |
309 | } | |
9f6c7b30 | 310 | #else |
311 | multimap& | |
312 | operator=(const multimap&) = default; | |
bae9b8af | 313 | |
39e522ee | 314 | /// Move assignment operator. |
707bff49 | 315 | multimap& |
39e522ee | 316 | operator=(multimap&&) = default; |
b23fdac1 | 317 | |
318 | /** | |
319 | * @brief %Multimap list assignment operator. | |
e12e4f3b | 320 | * @param __l An initializer_list. |
b23fdac1 | 321 | * |
322 | * This function fills a %multimap with copies of the elements | |
e12e4f3b | 323 | * in the initializer list @a __l. |
b23fdac1 | 324 | * |
325 | * Note that the assignment completely changes the %multimap and | |
326 | * that the resulting %multimap's size is the same as the number | |
d481d9a2 | 327 | * of elements assigned. |
b23fdac1 | 328 | */ |
329 | multimap& | |
330 | operator=(initializer_list<value_type> __l) | |
331 | { | |
39e522ee | 332 | _M_t._M_assign_equal(__l.begin(), __l.end()); |
b23fdac1 | 333 | return *this; |
334 | } | |
707bff49 | 335 | #endif |
336 | ||
b9156b5c | 337 | /// Get a copy of the memory allocation object. |
338 | allocator_type | |
b49b5511 | 339 | get_allocator() const _GLIBCXX_NOEXCEPT |
852b4cc2 | 340 | { return allocator_type(_M_t.get_allocator()); } |
bae9b8af | 341 | |
b9156b5c | 342 | // iterators |
343 | /** | |
344 | * Returns a read/write iterator that points to the first pair in the | |
345 | * %multimap. Iteration is done in ascending order according to the | |
346 | * keys. | |
347 | */ | |
348 | iterator | |
7cd718fd | 349 | begin() _GLIBCXX_NOEXCEPT |
b9156b5c | 350 | { return _M_t.begin(); } |
bae9b8af | 351 | |
b9156b5c | 352 | /** |
353 | * Returns a read-only (constant) iterator that points to the first pair | |
354 | * in the %multimap. Iteration is done in ascending order according to | |
355 | * the keys. | |
356 | */ | |
357 | const_iterator | |
7cd718fd | 358 | begin() const _GLIBCXX_NOEXCEPT |
b9156b5c | 359 | { return _M_t.begin(); } |
bae9b8af | 360 | |
b9156b5c | 361 | /** |
362 | * Returns a read/write iterator that points one past the last pair in | |
363 | * the %multimap. Iteration is done in ascending order according to the | |
364 | * keys. | |
365 | */ | |
366 | iterator | |
7cd718fd | 367 | end() _GLIBCXX_NOEXCEPT |
b9156b5c | 368 | { return _M_t.end(); } |
bae9b8af | 369 | |
b9156b5c | 370 | /** |
371 | * Returns a read-only (constant) iterator that points one past the last | |
372 | * pair in the %multimap. Iteration is done in ascending order according | |
373 | * to the keys. | |
374 | */ | |
375 | const_iterator | |
7cd718fd | 376 | end() const _GLIBCXX_NOEXCEPT |
b9156b5c | 377 | { return _M_t.end(); } |
bae9b8af | 378 | |
b9156b5c | 379 | /** |
380 | * Returns a read/write reverse iterator that points to the last pair in | |
381 | * the %multimap. Iteration is done in descending order according to the | |
382 | * keys. | |
383 | */ | |
384 | reverse_iterator | |
7cd718fd | 385 | rbegin() _GLIBCXX_NOEXCEPT |
b9156b5c | 386 | { return _M_t.rbegin(); } |
bae9b8af | 387 | |
b9156b5c | 388 | /** |
389 | * Returns a read-only (constant) reverse iterator that points to the | |
390 | * last pair in the %multimap. Iteration is done in descending order | |
391 | * according to the keys. | |
392 | */ | |
393 | const_reverse_iterator | |
7cd718fd | 394 | rbegin() const _GLIBCXX_NOEXCEPT |
b9156b5c | 395 | { return _M_t.rbegin(); } |
bae9b8af | 396 | |
b9156b5c | 397 | /** |
398 | * Returns a read/write reverse iterator that points to one before the | |
399 | * first pair in the %multimap. Iteration is done in descending order | |
400 | * according to the keys. | |
401 | */ | |
402 | reverse_iterator | |
7cd718fd | 403 | rend() _GLIBCXX_NOEXCEPT |
b9156b5c | 404 | { return _M_t.rend(); } |
bae9b8af | 405 | |
b9156b5c | 406 | /** |
407 | * Returns a read-only (constant) reverse iterator that points to one | |
408 | * before the first pair in the %multimap. Iteration is done in | |
409 | * descending order according to the keys. | |
410 | */ | |
411 | const_reverse_iterator | |
7cd718fd | 412 | rend() const _GLIBCXX_NOEXCEPT |
b9156b5c | 413 | { return _M_t.rend(); } |
bae9b8af | 414 | |
0c8766b1 | 415 | #if __cplusplus >= 201103L |
c40b2e37 | 416 | /** |
417 | * Returns a read-only (constant) iterator that points to the first pair | |
418 | * in the %multimap. Iteration is done in ascending order according to | |
419 | * the keys. | |
420 | */ | |
421 | const_iterator | |
7cd718fd | 422 | cbegin() const noexcept |
c40b2e37 | 423 | { return _M_t.begin(); } |
424 | ||
425 | /** | |
426 | * Returns a read-only (constant) iterator that points one past the last | |
427 | * pair in the %multimap. Iteration is done in ascending order according | |
428 | * to the keys. | |
429 | */ | |
430 | const_iterator | |
7cd718fd | 431 | cend() const noexcept |
c40b2e37 | 432 | { return _M_t.end(); } |
433 | ||
434 | /** | |
435 | * Returns a read-only (constant) reverse iterator that points to the | |
436 | * last pair in the %multimap. Iteration is done in descending order | |
437 | * according to the keys. | |
438 | */ | |
439 | const_reverse_iterator | |
7cd718fd | 440 | crbegin() const noexcept |
c40b2e37 | 441 | { return _M_t.rbegin(); } |
442 | ||
443 | /** | |
444 | * Returns a read-only (constant) reverse iterator that points to one | |
445 | * before the first pair in the %multimap. Iteration is done in | |
446 | * descending order according to the keys. | |
447 | */ | |
448 | const_reverse_iterator | |
7cd718fd | 449 | crend() const noexcept |
c40b2e37 | 450 | { return _M_t.rend(); } |
451 | #endif | |
452 | ||
b9156b5c | 453 | // capacity |
454 | /** Returns true if the %multimap is empty. */ | |
455 | bool | |
7cd718fd | 456 | empty() const _GLIBCXX_NOEXCEPT |
b9156b5c | 457 | { return _M_t.empty(); } |
bae9b8af | 458 | |
b9156b5c | 459 | /** Returns the size of the %multimap. */ |
460 | size_type | |
7cd718fd | 461 | size() const _GLIBCXX_NOEXCEPT |
b9156b5c | 462 | { return _M_t.size(); } |
bae9b8af | 463 | |
b9156b5c | 464 | /** Returns the maximum size of the %multimap. */ |
465 | size_type | |
7cd718fd | 466 | max_size() const _GLIBCXX_NOEXCEPT |
b9156b5c | 467 | { return _M_t.max_size(); } |
bae9b8af | 468 | |
b9156b5c | 469 | // modifiers |
0c8766b1 | 470 | #if __cplusplus >= 201103L |
6b9314a8 | 471 | /** |
472 | * @brief Build and insert a std::pair into the %multimap. | |
473 | * | |
474 | * @param __args Arguments used to generate a new pair instance (see | |
475 | * std::piecewise_contruct for passing arguments to each | |
476 | * part of the pair constructor). | |
477 | * | |
478 | * @return An iterator that points to the inserted (key,value) pair. | |
479 | * | |
480 | * This function builds and inserts a (key, value) %pair into the | |
481 | * %multimap. | |
482 | * Contrary to a std::map the %multimap does not rely on unique keys and | |
483 | * thus multiple pairs with the same key can be inserted. | |
484 | * | |
485 | * Insertion requires logarithmic time. | |
486 | */ | |
487 | template<typename... _Args> | |
488 | iterator | |
489 | emplace(_Args&&... __args) | |
490 | { return _M_t._M_emplace_equal(std::forward<_Args>(__args)...); } | |
491 | ||
492 | /** | |
493 | * @brief Builds and inserts a std::pair into the %multimap. | |
494 | * | |
495 | * @param __pos An iterator that serves as a hint as to where the pair | |
496 | * should be inserted. | |
497 | * @param __args Arguments used to generate a new pair instance (see | |
498 | * std::piecewise_contruct for passing arguments to each | |
499 | * part of the pair constructor). | |
500 | * @return An iterator that points to the inserted (key,value) pair. | |
501 | * | |
502 | * This function inserts a (key, value) pair into the %multimap. | |
503 | * Contrary to a std::map the %multimap does not rely on unique keys and | |
504 | * thus multiple pairs with the same key can be inserted. | |
505 | * Note that the first parameter is only a hint and can potentially | |
506 | * improve the performance of the insertion process. A bad hint would | |
507 | * cause no gains in efficiency. | |
508 | * | |
509 | * For more on @a hinting, see: | |
0698cdf1 | 510 | * https://gcc.gnu.org/onlinedocs/libstdc++/manual/associative.html#containers.associative.insert_hints |
6b9314a8 | 511 | * |
512 | * Insertion requires logarithmic time (if the hint is not taken). | |
513 | */ | |
514 | template<typename... _Args> | |
515 | iterator | |
516 | emplace_hint(const_iterator __pos, _Args&&... __args) | |
517 | { | |
518 | return _M_t._M_emplace_hint_equal(__pos, | |
519 | std::forward<_Args>(__args)...); | |
520 | } | |
521 | #endif | |
522 | ||
b9156b5c | 523 | /** |
524 | * @brief Inserts a std::pair into the %multimap. | |
e12e4f3b | 525 | * @param __x Pair to be inserted (see std::make_pair for easy creation |
b9156b5c | 526 | * of pairs). |
527 | * @return An iterator that points to the inserted (key,value) pair. | |
528 | * | |
bae9b8af | 529 | * This function inserts a (key, value) pair into the %multimap. |
b9156b5c | 530 | * Contrary to a std::map the %multimap does not rely on unique keys and |
531 | * thus multiple pairs with the same key can be inserted. | |
532 | * | |
533 | * Insertion requires logarithmic time. | |
32973e22 | 534 | * @{ |
b9156b5c | 535 | */ |
536 | iterator | |
537 | insert(const value_type& __x) | |
8474dcf5 | 538 | { return _M_t._M_insert_equal(__x); } |
bae9b8af | 539 | |
0c8766b1 | 540 | #if __cplusplus >= 201103L |
32973e22 | 541 | // _GLIBCXX_RESOLVE_LIB_DEFECTS |
542 | // 2354. Unnecessary copying when inserting into maps with braced-init | |
543 | iterator | |
544 | insert(value_type&& __x) | |
545 | { return _M_t._M_insert_equal(std::move(__x)); } | |
546 | ||
01b2b7a5 | 547 | template<typename _Pair> |
548 | __enable_if_t<is_constructible<value_type, _Pair>::value, iterator> | |
b49b5511 | 549 | insert(_Pair&& __x) |
01b2b7a5 | 550 | { return _M_t._M_emplace_equal(std::forward<_Pair>(__x)); } |
3e469200 | 551 | #endif |
32973e22 | 552 | // @} |
3e469200 | 553 | |
b9156b5c | 554 | /** |
555 | * @brief Inserts a std::pair into the %multimap. | |
e12e4f3b | 556 | * @param __position An iterator that serves as a hint as to where the |
557 | * pair should be inserted. | |
558 | * @param __x Pair to be inserted (see std::make_pair for easy creation | |
559 | * of pairs). | |
b9156b5c | 560 | * @return An iterator that points to the inserted (key,value) pair. |
561 | * | |
bae9b8af | 562 | * This function inserts a (key, value) pair into the %multimap. |
b9156b5c | 563 | * Contrary to a std::map the %multimap does not rely on unique keys and |
564 | * thus multiple pairs with the same key can be inserted. | |
565 | * Note that the first parameter is only a hint and can potentially | |
566 | * improve the performance of the insertion process. A bad hint would | |
567 | * cause no gains in efficiency. | |
568 | * | |
72117d76 | 569 | * For more on @a hinting, see: |
0698cdf1 | 570 | * https://gcc.gnu.org/onlinedocs/libstdc++/manual/associative.html#containers.associative.insert_hints |
b9156b5c | 571 | * |
572 | * Insertion requires logarithmic time (if the hint is not taken). | |
32973e22 | 573 | * @{ |
b9156b5c | 574 | */ |
575 | iterator | |
0c8766b1 | 576 | #if __cplusplus >= 201103L |
3b607c40 | 577 | insert(const_iterator __position, const value_type& __x) |
578 | #else | |
b9156b5c | 579 | insert(iterator __position, const value_type& __x) |
3b607c40 | 580 | #endif |
0447af6c | 581 | { return _M_t._M_insert_equal_(__position, __x); } |
bae9b8af | 582 | |
0c8766b1 | 583 | #if __cplusplus >= 201103L |
32973e22 | 584 | // _GLIBCXX_RESOLVE_LIB_DEFECTS |
585 | // 2354. Unnecessary copying when inserting into maps with braced-init | |
586 | iterator | |
587 | insert(const_iterator __position, value_type&& __x) | |
588 | { return _M_t._M_insert_equal_(__position, std::move(__x)); } | |
589 | ||
01b2b7a5 | 590 | template<typename _Pair> |
591 | __enable_if_t<is_constructible<value_type, _Pair&&>::value, iterator> | |
b49b5511 | 592 | insert(const_iterator __position, _Pair&& __x) |
01b2b7a5 | 593 | { |
594 | return _M_t._M_emplace_hint_equal(__position, | |
595 | std::forward<_Pair>(__x)); | |
596 | } | |
3e469200 | 597 | #endif |
32973e22 | 598 | // @} |
3e469200 | 599 | |
b9156b5c | 600 | /** |
c53be2be | 601 | * @brief A template function that attempts to insert a range |
602 | * of elements. | |
e12e4f3b | 603 | * @param __first Iterator pointing to the start of the range to be |
604 | * inserted. | |
605 | * @param __last Iterator pointing to the end of the range. | |
b9156b5c | 606 | * |
607 | * Complexity similar to that of the range constructor. | |
608 | */ | |
707bff49 | 609 | template<typename _InputIterator> |
b49b5511 | 610 | void |
611 | insert(_InputIterator __first, _InputIterator __last) | |
dc0e5150 | 612 | { _M_t._M_insert_range_equal(__first, __last); } |
bae9b8af | 613 | |
0c8766b1 | 614 | #if __cplusplus >= 201103L |
b23fdac1 | 615 | /** |
616 | * @brief Attempts to insert a list of std::pairs into the %multimap. | |
e12e4f3b | 617 | * @param __l A std::initializer_list<value_type> of pairs to be |
618 | * inserted. | |
b23fdac1 | 619 | * |
620 | * Complexity similar to that of the range constructor. | |
621 | */ | |
622 | void | |
623 | insert(initializer_list<value_type> __l) | |
624 | { this->insert(__l.begin(), __l.end()); } | |
625 | #endif | |
626 | ||
67218f06 | 627 | #if __cplusplus > 201402L |
628 | /// Extract a node. | |
629 | node_type | |
630 | extract(const_iterator __pos) | |
c695dcd2 | 631 | { |
632 | __glibcxx_assert(__pos != end()); | |
633 | return _M_t.extract(__pos); | |
634 | } | |
67218f06 | 635 | |
636 | /// Extract a node. | |
637 | node_type | |
638 | extract(const key_type& __x) | |
639 | { return _M_t.extract(__x); } | |
640 | ||
641 | /// Re-insert an extracted node. | |
642 | iterator | |
643 | insert(node_type&& __nh) | |
644 | { return _M_t._M_reinsert_node_equal(std::move(__nh)); } | |
645 | ||
646 | /// Re-insert an extracted node. | |
647 | iterator | |
648 | insert(const_iterator __hint, node_type&& __nh) | |
649 | { return _M_t._M_reinsert_node_hint_equal(__hint, std::move(__nh)); } | |
650 | ||
651 | template<typename, typename> | |
50cd55c3 | 652 | friend class std::_Rb_tree_merge_helper; |
67218f06 | 653 | |
654 | template<typename _C2> | |
655 | void | |
656 | merge(multimap<_Key, _Tp, _C2, _Alloc>& __source) | |
657 | { | |
658 | using _Merge_helper = _Rb_tree_merge_helper<multimap, _C2>; | |
659 | _M_t._M_merge_equal(_Merge_helper::_S_get_tree(__source)); | |
660 | } | |
661 | ||
662 | template<typename _C2> | |
663 | void | |
664 | merge(multimap<_Key, _Tp, _C2, _Alloc>&& __source) | |
665 | { merge(__source); } | |
666 | ||
667 | template<typename _C2> | |
668 | void | |
669 | merge(map<_Key, _Tp, _C2, _Alloc>& __source) | |
670 | { | |
671 | using _Merge_helper = _Rb_tree_merge_helper<multimap, _C2>; | |
672 | _M_t._M_merge_equal(_Merge_helper::_S_get_tree(__source)); | |
673 | } | |
674 | ||
675 | template<typename _C2> | |
676 | void | |
677 | merge(map<_Key, _Tp, _C2, _Alloc>&& __source) | |
678 | { merge(__source); } | |
679 | #endif // C++17 | |
680 | ||
0c8766b1 | 681 | #if __cplusplus >= 201103L |
200f291d | 682 | // _GLIBCXX_RESOLVE_LIB_DEFECTS |
683 | // DR 130. Associative erase should return an iterator. | |
684 | /** | |
685 | * @brief Erases an element from a %multimap. | |
e12e4f3b | 686 | * @param __position An iterator pointing to the element to be erased. |
200f291d | 687 | * @return An iterator pointing to the element immediately following |
b49b5511 | 688 | * @a position prior to the element being erased. If no such |
200f291d | 689 | * element exists, end() is returned. |
690 | * | |
691 | * This function erases an element, pointed to by the given iterator, | |
692 | * from a %multimap. Note that this function only erases the element, | |
693 | * and that if the element is itself a pointer, the pointed-to memory is | |
694 | * not touched in any way. Managing the pointer is the user's | |
695 | * responsibility. | |
d69b2470 | 696 | * |
697 | * @{ | |
200f291d | 698 | */ |
699 | iterator | |
3b607c40 | 700 | erase(const_iterator __position) |
200f291d | 701 | { return _M_t.erase(__position); } |
8683d45d | 702 | |
703 | // LWG 2059. | |
8544d95d | 704 | _GLIBCXX_ABI_TAG_CXX11 |
8683d45d | 705 | iterator |
706 | erase(iterator __position) | |
707 | { return _M_t.erase(__position); } | |
d69b2470 | 708 | // @} |
200f291d | 709 | #else |
b9156b5c | 710 | /** |
711 | * @brief Erases an element from a %multimap. | |
e12e4f3b | 712 | * @param __position An iterator pointing to the element to be erased. |
b9156b5c | 713 | * |
714 | * This function erases an element, pointed to by the given iterator, | |
715 | * from a %multimap. Note that this function only erases the element, | |
716 | * and that if the element is itself a pointer, the pointed-to memory is | |
717 | * not touched in any way. Managing the pointer is the user's | |
9fc1117c | 718 | * responsibility. |
b9156b5c | 719 | */ |
32bb2cd7 | 720 | void |
b9156b5c | 721 | erase(iterator __position) |
722 | { _M_t.erase(__position); } | |
200f291d | 723 | #endif |
bae9b8af | 724 | |
b9156b5c | 725 | /** |
726 | * @brief Erases elements according to the provided key. | |
e12e4f3b | 727 | * @param __x Key of element to be erased. |
b9156b5c | 728 | * @return The number of elements erased. |
729 | * | |
730 | * This function erases all elements located by the given key from a | |
731 | * %multimap. | |
732 | * Note that this function only erases the element, and that if | |
733 | * the element is itself a pointer, the pointed-to memory is not touched | |
9fc1117c | 734 | * in any way. Managing the pointer is the user's responsibility. |
b9156b5c | 735 | */ |
736 | size_type | |
737 | erase(const key_type& __x) | |
738 | { return _M_t.erase(__x); } | |
bae9b8af | 739 | |
0c8766b1 | 740 | #if __cplusplus >= 201103L |
200f291d | 741 | // _GLIBCXX_RESOLVE_LIB_DEFECTS |
742 | // DR 130. Associative erase should return an iterator. | |
743 | /** | |
744 | * @brief Erases a [first,last) range of elements from a %multimap. | |
e12e4f3b | 745 | * @param __first Iterator pointing to the start of the range to be |
746 | * erased. | |
747 | * @param __last Iterator pointing to the end of the range to be | |
748 | * erased . | |
749 | * @return The iterator @a __last. | |
200f291d | 750 | * |
751 | * This function erases a sequence of elements from a %multimap. | |
752 | * Note that this function only erases the elements, and that if | |
753 | * the elements themselves are pointers, the pointed-to memory is not | |
3b607c40 | 754 | * touched in any way. Managing the pointer is the user's |
755 | * responsibility. | |
200f291d | 756 | */ |
757 | iterator | |
3b607c40 | 758 | erase(const_iterator __first, const_iterator __last) |
200f291d | 759 | { return _M_t.erase(__first, __last); } |
760 | #else | |
761 | // _GLIBCXX_RESOLVE_LIB_DEFECTS | |
762 | // DR 130. Associative erase should return an iterator. | |
b9156b5c | 763 | /** |
764 | * @brief Erases a [first,last) range of elements from a %multimap. | |
e12e4f3b | 765 | * @param __first Iterator pointing to the start of the range to be |
b9156b5c | 766 | * erased. |
e12e4f3b | 767 | * @param __last Iterator pointing to the end of the range to |
768 | * be erased. | |
b9156b5c | 769 | * |
770 | * This function erases a sequence of elements from a %multimap. | |
771 | * Note that this function only erases the elements, and that if | |
772 | * the elements themselves are pointers, the pointed-to memory is not | |
3b607c40 | 773 | * touched in any way. Managing the pointer is the user's |
774 | * responsibility. | |
b9156b5c | 775 | */ |
776 | void | |
777 | erase(iterator __first, iterator __last) | |
778 | { _M_t.erase(__first, __last); } | |
200f291d | 779 | #endif |
bae9b8af | 780 | |
b9156b5c | 781 | /** |
782 | * @brief Swaps data with another %multimap. | |
e12e4f3b | 783 | * @param __x A %multimap of the same element and allocator types. |
b9156b5c | 784 | * |
785 | * This exchanges the elements between two multimaps in constant time. | |
786 | * (It is only swapping a pointer, an integer, and an instance of | |
787 | * the @c Compare type (which itself is often stateless and empty), so it | |
788 | * should be quite fast.) | |
789 | * Note that the global std::swap() function is specialized such that | |
790 | * std::swap(m1,m2) will feed to this function. | |
d481d9a2 | 791 | * |
792 | * Whether the allocators are swapped depends on the allocator traits. | |
b9156b5c | 793 | */ |
794 | void | |
795 | swap(multimap& __x) | |
02769f1f | 796 | _GLIBCXX_NOEXCEPT_IF(__is_nothrow_swappable<_Compare>::value) |
b9156b5c | 797 | { _M_t.swap(__x._M_t); } |
bae9b8af | 798 | |
b9156b5c | 799 | /** |
800 | * Erases all elements in a %multimap. Note that this function only | |
801 | * erases the elements, and that if the elements themselves are pointers, | |
802 | * the pointed-to memory is not touched in any way. Managing the pointer | |
9fc1117c | 803 | * is the user's responsibility. |
b9156b5c | 804 | */ |
805 | void | |
7cd718fd | 806 | clear() _GLIBCXX_NOEXCEPT |
b9156b5c | 807 | { _M_t.clear(); } |
bae9b8af | 808 | |
b9156b5c | 809 | // observers |
810 | /** | |
811 | * Returns the key comparison object out of which the %multimap | |
812 | * was constructed. | |
813 | */ | |
814 | key_compare | |
815 | key_comp() const | |
816 | { return _M_t.key_comp(); } | |
bae9b8af | 817 | |
b9156b5c | 818 | /** |
819 | * Returns a value comparison object, built from the key comparison | |
820 | * object out of which the %multimap was constructed. | |
821 | */ | |
822 | value_compare | |
823 | value_comp() const | |
824 | { return value_compare(_M_t.key_comp()); } | |
bae9b8af | 825 | |
b9156b5c | 826 | // multimap operations |
fcb2e07a | 827 | |
828 | //@{ | |
b9156b5c | 829 | /** |
830 | * @brief Tries to locate an element in a %multimap. | |
e12e4f3b | 831 | * @param __x Key of (key, value) pair to be located. |
b9156b5c | 832 | * @return Iterator pointing to sought-after element, |
833 | * or end() if not found. | |
834 | * | |
835 | * This function takes a key and tries to locate the element with which | |
836 | * the key matches. If successful the function returns an iterator | |
837 | * pointing to the sought after %pair. If unsuccessful it returns the | |
838 | * past-the-end ( @c end() ) iterator. | |
839 | */ | |
840 | iterator | |
841 | find(const key_type& __x) | |
842 | { return _M_t.find(__x); } | |
bae9b8af | 843 | |
fcb2e07a | 844 | #if __cplusplus > 201103L |
845 | template<typename _Kt> | |
846 | auto | |
847 | find(const _Kt& __x) -> decltype(_M_t._M_find_tr(__x)) | |
848 | { return _M_t._M_find_tr(__x); } | |
849 | #endif | |
850 | //@} | |
851 | ||
852 | //@{ | |
b9156b5c | 853 | /** |
854 | * @brief Tries to locate an element in a %multimap. | |
e12e4f3b | 855 | * @param __x Key of (key, value) pair to be located. |
b9156b5c | 856 | * @return Read-only (constant) iterator pointing to sought-after |
857 | * element, or end() if not found. | |
858 | * | |
859 | * This function takes a key and tries to locate the element with which | |
860 | * the key matches. If successful the function returns a constant | |
861 | * iterator pointing to the sought after %pair. If unsuccessful it | |
862 | * returns the past-the-end ( @c end() ) iterator. | |
863 | */ | |
864 | const_iterator | |
865 | find(const key_type& __x) const | |
866 | { return _M_t.find(__x); } | |
bae9b8af | 867 | |
fcb2e07a | 868 | #if __cplusplus > 201103L |
869 | template<typename _Kt> | |
870 | auto | |
871 | find(const _Kt& __x) const -> decltype(_M_t._M_find_tr(__x)) | |
872 | { return _M_t._M_find_tr(__x); } | |
873 | #endif | |
874 | //@} | |
875 | ||
876 | //@{ | |
b9156b5c | 877 | /** |
878 | * @brief Finds the number of elements with given key. | |
e12e4f3b | 879 | * @param __x Key of (key, value) pairs to be located. |
b9156b5c | 880 | * @return Number of elements with specified key. |
881 | */ | |
882 | size_type | |
883 | count(const key_type& __x) const | |
884 | { return _M_t.count(__x); } | |
bae9b8af | 885 | |
fcb2e07a | 886 | #if __cplusplus > 201103L |
887 | template<typename _Kt> | |
888 | auto | |
889 | count(const _Kt& __x) const -> decltype(_M_t._M_count_tr(__x)) | |
890 | { return _M_t._M_count_tr(__x); } | |
891 | #endif | |
892 | //@} | |
893 | ||
be7ce806 | 894 | #if __cplusplus > 201703L |
895 | //@{ | |
896 | /** | |
897 | * @brief Finds whether an element with the given key exists. | |
898 | * @param __x Key of (key, value) pairs to be located. | |
899 | * @return True if there is any element with the specified key. | |
900 | */ | |
901 | bool | |
902 | contains(const key_type& __x) const | |
903 | { return _M_t.find(__x) != _M_t.end(); } | |
904 | ||
905 | template<typename _Kt> | |
906 | auto | |
907 | contains(const _Kt& __x) const | |
908 | -> decltype(_M_t._M_find_tr(__x), void(), true) | |
909 | { return _M_t._M_find_tr(__x) != _M_t.end(); } | |
910 | //@} | |
911 | #endif | |
912 | ||
fcb2e07a | 913 | //@{ |
b9156b5c | 914 | /** |
915 | * @brief Finds the beginning of a subsequence matching given key. | |
e12e4f3b | 916 | * @param __x Key of (key, value) pair to be located. |
b9156b5c | 917 | * @return Iterator pointing to first element equal to or greater |
918 | * than key, or end(). | |
919 | * | |
920 | * This function returns the first element of a subsequence of elements | |
921 | * that matches the given key. If unsuccessful it returns an iterator | |
922 | * pointing to the first element that has a greater value than given key | |
923 | * or end() if no such element exists. | |
924 | */ | |
925 | iterator | |
926 | lower_bound(const key_type& __x) | |
927 | { return _M_t.lower_bound(__x); } | |
bae9b8af | 928 | |
fcb2e07a | 929 | #if __cplusplus > 201103L |
930 | template<typename _Kt> | |
931 | auto | |
932 | lower_bound(const _Kt& __x) | |
157a66e3 | 933 | -> decltype(iterator(_M_t._M_lower_bound_tr(__x))) |
934 | { return iterator(_M_t._M_lower_bound_tr(__x)); } | |
fcb2e07a | 935 | #endif |
936 | //@} | |
937 | ||
938 | //@{ | |
b9156b5c | 939 | /** |
940 | * @brief Finds the beginning of a subsequence matching given key. | |
e12e4f3b | 941 | * @param __x Key of (key, value) pair to be located. |
b9156b5c | 942 | * @return Read-only (constant) iterator pointing to first element |
943 | * equal to or greater than key, or end(). | |
944 | * | |
e12e4f3b | 945 | * This function returns the first element of a subsequence of |
946 | * elements that matches the given key. If unsuccessful the | |
947 | * iterator will point to the next greatest element or, if no | |
948 | * such greater element exists, to end(). | |
b9156b5c | 949 | */ |
950 | const_iterator | |
951 | lower_bound(const key_type& __x) const | |
952 | { return _M_t.lower_bound(__x); } | |
bae9b8af | 953 | |
fcb2e07a | 954 | #if __cplusplus > 201103L |
955 | template<typename _Kt> | |
956 | auto | |
957 | lower_bound(const _Kt& __x) const | |
157a66e3 | 958 | -> decltype(const_iterator(_M_t._M_lower_bound_tr(__x))) |
959 | { return const_iterator(_M_t._M_lower_bound_tr(__x)); } | |
fcb2e07a | 960 | #endif |
961 | //@} | |
962 | ||
963 | //@{ | |
b9156b5c | 964 | /** |
965 | * @brief Finds the end of a subsequence matching given key. | |
e12e4f3b | 966 | * @param __x Key of (key, value) pair to be located. |
b9156b5c | 967 | * @return Iterator pointing to the first element |
968 | * greater than key, or end(). | |
969 | */ | |
970 | iterator | |
971 | upper_bound(const key_type& __x) | |
972 | { return _M_t.upper_bound(__x); } | |
bae9b8af | 973 | |
fcb2e07a | 974 | #if __cplusplus > 201103L |
975 | template<typename _Kt> | |
976 | auto | |
977 | upper_bound(const _Kt& __x) | |
157a66e3 | 978 | -> decltype(iterator(_M_t._M_upper_bound_tr(__x))) |
979 | { return iterator(_M_t._M_upper_bound_tr(__x)); } | |
fcb2e07a | 980 | #endif |
981 | //@} | |
982 | ||
983 | //@{ | |
b9156b5c | 984 | /** |
985 | * @brief Finds the end of a subsequence matching given key. | |
e12e4f3b | 986 | * @param __x Key of (key, value) pair to be located. |
b9156b5c | 987 | * @return Read-only (constant) iterator pointing to first iterator |
988 | * greater than key, or end(). | |
989 | */ | |
990 | const_iterator | |
991 | upper_bound(const key_type& __x) const | |
992 | { return _M_t.upper_bound(__x); } | |
bae9b8af | 993 | |
fcb2e07a | 994 | #if __cplusplus > 201103L |
995 | template<typename _Kt> | |
996 | auto | |
997 | upper_bound(const _Kt& __x) const | |
157a66e3 | 998 | -> decltype(const_iterator(_M_t._M_upper_bound_tr(__x))) |
999 | { return const_iterator(_M_t._M_upper_bound_tr(__x)); } | |
fcb2e07a | 1000 | #endif |
1001 | //@} | |
1002 | ||
1003 | //@{ | |
b9156b5c | 1004 | /** |
1005 | * @brief Finds a subsequence matching given key. | |
e12e4f3b | 1006 | * @param __x Key of (key, value) pairs to be located. |
b9156b5c | 1007 | * @return Pair of iterators that possibly points to the subsequence |
1008 | * matching given key. | |
1009 | * | |
1010 | * This function is equivalent to | |
1011 | * @code | |
1012 | * std::make_pair(c.lower_bound(val), | |
1013 | * c.upper_bound(val)) | |
1014 | * @endcode | |
1015 | * (but is faster than making the calls separately). | |
1016 | */ | |
171a395a | 1017 | std::pair<iterator, iterator> |
b9156b5c | 1018 | equal_range(const key_type& __x) |
1019 | { return _M_t.equal_range(__x); } | |
bae9b8af | 1020 | |
fcb2e07a | 1021 | #if __cplusplus > 201103L |
1022 | template<typename _Kt> | |
1023 | auto | |
1024 | equal_range(const _Kt& __x) | |
157a66e3 | 1025 | -> decltype(pair<iterator, iterator>(_M_t._M_equal_range_tr(__x))) |
1026 | { return pair<iterator, iterator>(_M_t._M_equal_range_tr(__x)); } | |
fcb2e07a | 1027 | #endif |
1028 | //@} | |
1029 | ||
1030 | //@{ | |
b9156b5c | 1031 | /** |
1032 | * @brief Finds a subsequence matching given key. | |
e12e4f3b | 1033 | * @param __x Key of (key, value) pairs to be located. |
b9156b5c | 1034 | * @return Pair of read-only (constant) iterators that possibly points |
1035 | * to the subsequence matching given key. | |
1036 | * | |
1037 | * This function is equivalent to | |
1038 | * @code | |
1039 | * std::make_pair(c.lower_bound(val), | |
1040 | * c.upper_bound(val)) | |
1041 | * @endcode | |
1042 | * (but is faster than making the calls separately). | |
1043 | */ | |
171a395a | 1044 | std::pair<const_iterator, const_iterator> |
b9156b5c | 1045 | equal_range(const key_type& __x) const |
1046 | { return _M_t.equal_range(__x); } | |
bae9b8af | 1047 | |
fcb2e07a | 1048 | #if __cplusplus > 201103L |
1049 | template<typename _Kt> | |
1050 | auto | |
1051 | equal_range(const _Kt& __x) const | |
157a66e3 | 1052 | -> decltype(pair<const_iterator, const_iterator>( |
1053 | _M_t._M_equal_range_tr(__x))) | |
1054 | { | |
1055 | return pair<const_iterator, const_iterator>( | |
1056 | _M_t._M_equal_range_tr(__x)); | |
1057 | } | |
fcb2e07a | 1058 | #endif |
1059 | //@} | |
1060 | ||
707bff49 | 1061 | template<typename _K1, typename _T1, typename _C1, typename _A1> |
b49b5511 | 1062 | friend bool |
1063 | operator==(const multimap<_K1, _T1, _C1, _A1>&, | |
707bff49 | 1064 | const multimap<_K1, _T1, _C1, _A1>&); |
bae9b8af | 1065 | |
707bff49 | 1066 | template<typename _K1, typename _T1, typename _C1, typename _A1> |
b49b5511 | 1067 | friend bool |
1068 | operator<(const multimap<_K1, _T1, _C1, _A1>&, | |
707bff49 | 1069 | const multimap<_K1, _T1, _C1, _A1>&); |
32bb2cd7 | 1070 | }; |
bae9b8af | 1071 | |
aa9edc02 | 1072 | #if __cpp_deduction_guides >= 201606 |
1073 | ||
1074 | template<typename _InputIterator, | |
1075 | typename _Compare = less<__iter_key_t<_InputIterator>>, | |
1076 | typename _Allocator = allocator<__iter_to_alloc_t<_InputIterator>>, | |
1077 | typename = _RequireInputIter<_InputIterator>, | |
1078 | typename = _RequireAllocator<_Allocator>> | |
1079 | multimap(_InputIterator, _InputIterator, | |
1080 | _Compare = _Compare(), _Allocator = _Allocator()) | |
1081 | -> multimap<__iter_key_t<_InputIterator>, __iter_val_t<_InputIterator>, | |
1082 | _Compare, _Allocator>; | |
1083 | ||
1084 | template<typename _Key, typename _Tp, typename _Compare = less<_Key>, | |
1085 | typename _Allocator = allocator<pair<const _Key, _Tp>>, | |
1086 | typename = _RequireAllocator<_Allocator>> | |
1087 | multimap(initializer_list<pair<_Key, _Tp>>, | |
1088 | _Compare = _Compare(), _Allocator = _Allocator()) | |
1089 | -> multimap<_Key, _Tp, _Compare, _Allocator>; | |
1090 | ||
1091 | template<typename _InputIterator, typename _Allocator, | |
1092 | typename = _RequireInputIter<_InputIterator>, | |
1093 | typename = _RequireAllocator<_Allocator>> | |
1094 | multimap(_InputIterator, _InputIterator, _Allocator) | |
1095 | -> multimap<__iter_key_t<_InputIterator>, __iter_val_t<_InputIterator>, | |
1096 | less<__iter_key_t<_InputIterator>>, _Allocator>; | |
1097 | ||
1098 | template<typename _Key, typename _Tp, typename _Allocator, | |
1099 | typename = _RequireAllocator<_Allocator>> | |
1100 | multimap(initializer_list<pair<_Key, _Tp>>, _Allocator) | |
1101 | -> multimap<_Key, _Tp, less<_Key>, _Allocator>; | |
1102 | ||
1103 | #endif | |
1104 | ||
6f879981 | 1105 | /** |
32bb2cd7 | 1106 | * @brief Multimap equality comparison. |
e12e4f3b | 1107 | * @param __x A %multimap. |
1108 | * @param __y A %multimap of the same type as @a __x. | |
32bb2cd7 | 1109 | * @return True iff the size and elements of the maps are equal. |
6f879981 | 1110 | * |
32bb2cd7 | 1111 | * This is an equivalence relation. It is linear in the size of the |
1112 | * multimaps. Multimaps are considered equivalent if their sizes are equal, | |
1113 | * and if corresponding elements compare equal. | |
1114 | */ | |
707bff49 | 1115 | template<typename _Key, typename _Tp, typename _Compare, typename _Alloc> |
32bb2cd7 | 1116 | inline bool |
171a395a | 1117 | operator==(const multimap<_Key, _Tp, _Compare, _Alloc>& __x, |
b49b5511 | 1118 | const multimap<_Key, _Tp, _Compare, _Alloc>& __y) |
b9156b5c | 1119 | { return __x._M_t == __y._M_t; } |
bae9b8af | 1120 | |
32bb2cd7 | 1121 | /** |
1122 | * @brief Multimap ordering relation. | |
e12e4f3b | 1123 | * @param __x A %multimap. |
1124 | * @param __y A %multimap of the same type as @a __x. | |
78314996 | 1125 | * @return True iff @a x is lexicographically less than @a y. |
6f879981 | 1126 | * |
32bb2cd7 | 1127 | * This is a total ordering relation. It is linear in the size of the |
1128 | * multimaps. The elements must be comparable with @c <. | |
6f879981 | 1129 | * |
78314996 | 1130 | * See std::lexicographical_compare() for how the determination is made. |
32bb2cd7 | 1131 | */ |
707bff49 | 1132 | template<typename _Key, typename _Tp, typename _Compare, typename _Alloc> |
32bb2cd7 | 1133 | inline bool |
171a395a | 1134 | operator<(const multimap<_Key, _Tp, _Compare, _Alloc>& __x, |
b49b5511 | 1135 | const multimap<_Key, _Tp, _Compare, _Alloc>& __y) |
32bb2cd7 | 1136 | { return __x._M_t < __y._M_t; } |
bae9b8af | 1137 | |
32bb2cd7 | 1138 | /// Based on operator== |
707bff49 | 1139 | template<typename _Key, typename _Tp, typename _Compare, typename _Alloc> |
32bb2cd7 | 1140 | inline bool |
171a395a | 1141 | operator!=(const multimap<_Key, _Tp, _Compare, _Alloc>& __x, |
b49b5511 | 1142 | const multimap<_Key, _Tp, _Compare, _Alloc>& __y) |
32bb2cd7 | 1143 | { return !(__x == __y); } |
bae9b8af | 1144 | |
32bb2cd7 | 1145 | /// Based on operator< |
707bff49 | 1146 | template<typename _Key, typename _Tp, typename _Compare, typename _Alloc> |
32bb2cd7 | 1147 | inline bool |
171a395a | 1148 | operator>(const multimap<_Key, _Tp, _Compare, _Alloc>& __x, |
b49b5511 | 1149 | const multimap<_Key, _Tp, _Compare, _Alloc>& __y) |
32bb2cd7 | 1150 | { return __y < __x; } |
bae9b8af | 1151 | |
32bb2cd7 | 1152 | /// Based on operator< |
707bff49 | 1153 | template<typename _Key, typename _Tp, typename _Compare, typename _Alloc> |
32bb2cd7 | 1154 | inline bool |
171a395a | 1155 | operator<=(const multimap<_Key, _Tp, _Compare, _Alloc>& __x, |
b49b5511 | 1156 | const multimap<_Key, _Tp, _Compare, _Alloc>& __y) |
32bb2cd7 | 1157 | { return !(__y < __x); } |
bae9b8af | 1158 | |
32bb2cd7 | 1159 | /// Based on operator< |
707bff49 | 1160 | template<typename _Key, typename _Tp, typename _Compare, typename _Alloc> |
32bb2cd7 | 1161 | inline bool |
171a395a | 1162 | operator>=(const multimap<_Key, _Tp, _Compare, _Alloc>& __x, |
b49b5511 | 1163 | const multimap<_Key, _Tp, _Compare, _Alloc>& __y) |
32bb2cd7 | 1164 | { return !(__x < __y); } |
bae9b8af | 1165 | |
32bb2cd7 | 1166 | /// See std::multimap::swap(). |
707bff49 | 1167 | template<typename _Key, typename _Tp, typename _Compare, typename _Alloc> |
32bb2cd7 | 1168 | inline void |
171a395a | 1169 | swap(multimap<_Key, _Tp, _Compare, _Alloc>& __x, |
b49b5511 | 1170 | multimap<_Key, _Tp, _Compare, _Alloc>& __y) |
02769f1f | 1171 | _GLIBCXX_NOEXCEPT_IF(noexcept(__x.swap(__y))) |
32bb2cd7 | 1172 | { __x.swap(__y); } |
1069247d | 1173 | |
2948dd21 | 1174 | _GLIBCXX_END_NAMESPACE_CONTAINER |
67218f06 | 1175 | |
1176 | #if __cplusplus > 201402L | |
67218f06 | 1177 | // Allow std::multimap access to internals of compatible maps. |
1178 | template<typename _Key, typename _Val, typename _Cmp1, typename _Alloc, | |
1179 | typename _Cmp2> | |
1180 | struct | |
1181 | _Rb_tree_merge_helper<_GLIBCXX_STD_C::multimap<_Key, _Val, _Cmp1, _Alloc>, | |
1182 | _Cmp2> | |
1183 | { | |
1184 | private: | |
1185 | friend class _GLIBCXX_STD_C::multimap<_Key, _Val, _Cmp1, _Alloc>; | |
1186 | ||
1187 | static auto& | |
1188 | _S_get_tree(_GLIBCXX_STD_C::map<_Key, _Val, _Cmp2, _Alloc>& __map) | |
1189 | { return __map._M_t; } | |
1190 | ||
1191 | static auto& | |
1192 | _S_get_tree(_GLIBCXX_STD_C::multimap<_Key, _Val, _Cmp2, _Alloc>& __map) | |
1193 | { return __map._M_t; } | |
1194 | }; | |
67218f06 | 1195 | #endif // C++17 |
1196 | ||
ae6a4ce9 | 1197 | _GLIBCXX_END_NAMESPACE_VERSION |
2948dd21 | 1198 | } // namespace std |
1d487aca | 1199 | |
f142a34a | 1200 | #endif /* _STL_MULTIMAP_H */ |