]>
Commit | Line | Data |
---|---|---|
42526146 PE |
1 | // Map implementation -*- C++ -*- |
2 | ||
85ec4feb | 3 | // Copyright (C) 2001-2018 Free Software Foundation, Inc. |
42526146 PE |
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 | |
748086b7 | 8 | // Free Software Foundation; either version 3, or (at your option) |
42526146 PE |
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 | ||
748086b7 JJ |
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. | |
42526146 | 19 | |
748086b7 JJ |
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/>. | |
42526146 | 24 | |
725dc051 BK |
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 | ||
f910786b | 51 | /** @file bits/stl_map.h |
729e3d3f | 52 | * This is an internal header file, included by other library headers. |
f910786b | 53 | * Do not attempt to use it directly. @headername{map} |
725dc051 BK |
54 | */ |
55 | ||
046d30f4 PC |
56 | #ifndef _STL_MAP_H |
57 | #define _STL_MAP_H 1 | |
725dc051 | 58 | |
8b5f07a2 | 59 | #include <bits/functexcept.h> |
30a20a1e | 60 | #include <bits/concept_check.h> |
734f5023 | 61 | #if __cplusplus >= 201103L |
09357846 | 62 | #include <initializer_list> |
55826ab6 | 63 | #include <tuple> |
a7d5d7e2 | 64 | #endif |
725dc051 | 65 | |
12ffa228 BK |
66 | namespace std _GLIBCXX_VISIBILITY(default) |
67 | { | |
4a15d842 | 68 | _GLIBCXX_BEGIN_NAMESPACE_VERSION |
12ffa228 | 69 | _GLIBCXX_BEGIN_NAMESPACE_CONTAINER |
3cbc7af0 | 70 | |
2dbe56bd JW |
71 | template <typename _Key, typename _Tp, typename _Compare, typename _Alloc> |
72 | class multimap; | |
73 | ||
224a45d0 | 74 | /** |
3971a4d2 PE |
75 | * @brief A standard container made up of (key,value) pairs, which can be |
76 | * retrieved based on a key, in logarithmic time. | |
224a45d0 | 77 | * |
aac2878e | 78 | * @ingroup associative_containers |
224a45d0 | 79 | * |
d632488a BK |
80 | * @tparam _Key Type of key objects. |
81 | * @tparam _Tp Type of mapped objects. | |
82 | * @tparam _Compare Comparison function object type, defaults to less<_Key>. | |
fe62dd04 | 83 | * @tparam _Alloc Allocator type, defaults to |
d632488a BK |
84 | * allocator<pair<const _Key, _Tp>. |
85 | * | |
3971a4d2 PE |
86 | * Meets the requirements of a <a href="tables.html#65">container</a>, a |
87 | * <a href="tables.html#66">reversible container</a>, and an | |
88 | * <a href="tables.html#69">associative container</a> (using unique keys). | |
89 | * For a @c map<Key,T> the key_type is Key, the mapped_type is T, and the | |
90 | * value_type is std::pair<const Key,T>. | |
224a45d0 | 91 | * |
3971a4d2 | 92 | * Maps support bidirectional iterators. |
224a45d0 | 93 | * |
3971a4d2 PE |
94 | * The private tree data is declared exactly the same way for map and |
95 | * multimap; the distinction is made entirely in how the tree functions are | |
96 | * called (*_unique versus *_equal, same as the standard). | |
3971a4d2 | 97 | */ |
6323b34e | 98 | template <typename _Key, typename _Tp, typename _Compare = std::less<_Key>, |
fe62dd04 | 99 | typename _Alloc = std::allocator<std::pair<const _Key, _Tp> > > |
3971a4d2 | 100 | class map |
f6592a9e | 101 | { |
737ab798 | 102 | public: |
fe62dd04 FD |
103 | typedef _Key key_type; |
104 | typedef _Tp mapped_type; | |
105 | typedef std::pair<const _Key, _Tp> value_type; | |
106 | typedef _Compare key_compare; | |
107 | typedef _Alloc allocator_type; | |
4fd20a8f PC |
108 | |
109 | private: | |
fe62dd04 | 110 | #ifdef _GLIBCXX_CONCEPT_CHECKS |
4fd20a8f | 111 | // concept requirements |
fe62dd04 FD |
112 | typedef typename _Alloc::value_type _Alloc_value_type; |
113 | # if __cplusplus < 201103L | |
4fd20a8f | 114 | __glibcxx_class_requires(_Tp, _SGIAssignableConcept) |
fe62dd04 | 115 | # endif |
4fd20a8f PC |
116 | __glibcxx_class_requires4(_Compare, bool, _Key, _Key, |
117 | _BinaryFunctionConcept) | |
118 | __glibcxx_class_requires2(value_type, _Alloc_value_type, _SameTypeConcept) | |
fe62dd04 | 119 | #endif |
ed6814f7 | 120 | |
866e4d38 JW |
121 | #if __cplusplus >= 201103L && defined(__STRICT_ANSI__) |
122 | static_assert(is_same<typename _Alloc::value_type, value_type>::value, | |
123 | "std::map must have the same value_type as its allocator"); | |
124 | #endif | |
125 | ||
4fd20a8f | 126 | public: |
f6592a9e | 127 | class value_compare |
6323b34e | 128 | : public std::binary_function<value_type, value_type, bool> |
3971a4d2 | 129 | { |
4fd20a8f | 130 | friend class map<_Key, _Tp, _Compare, _Alloc>; |
3971a4d2 | 131 | protected: |
f6592a9e | 132 | _Compare comp; |
ed6814f7 | 133 | |
f6592a9e | 134 | value_compare(_Compare __c) |
737ab798 | 135 | : comp(__c) { } |
ed6814f7 | 136 | |
3971a4d2 | 137 | public: |
f6592a9e PC |
138 | bool operator()(const value_type& __x, const value_type& __y) const |
139 | { return comp(__x.first, __y.first); } | |
3971a4d2 | 140 | }; |
ed6814f7 | 141 | |
f6592a9e | 142 | private: |
fe62dd04 | 143 | /// This turns a red-black tree into a [multi]map. |
ff90a89e JW |
144 | typedef typename __gnu_cxx::__alloc_traits<_Alloc>::template |
145 | rebind<value_type>::other _Pair_alloc_type; | |
4fd20a8f PC |
146 | |
147 | typedef _Rb_tree<key_type, value_type, _Select1st<value_type>, | |
148 | key_compare, _Pair_alloc_type> _Rep_type; | |
149 | ||
4312e020 | 150 | /// The actual tree structure. |
f6592a9e | 151 | _Rep_type _M_t; |
ed6814f7 | 152 | |
ff90a89e JW |
153 | typedef __gnu_cxx::__alloc_traits<_Pair_alloc_type> _Alloc_traits; |
154 | ||
f6592a9e PC |
155 | public: |
156 | // many of these are specified differently in ISO, but the following are | |
157 | // "functionally equivalent" | |
fe62dd04 FD |
158 | typedef typename _Alloc_traits::pointer pointer; |
159 | typedef typename _Alloc_traits::const_pointer const_pointer; | |
160 | typedef typename _Alloc_traits::reference reference; | |
161 | typedef typename _Alloc_traits::const_reference const_reference; | |
162 | typedef typename _Rep_type::iterator iterator; | |
163 | typedef typename _Rep_type::const_iterator const_iterator; | |
164 | typedef typename _Rep_type::size_type size_type; | |
165 | typedef typename _Rep_type::difference_type difference_type; | |
166 | typedef typename _Rep_type::reverse_iterator reverse_iterator; | |
7338fc64 | 167 | typedef typename _Rep_type::const_reverse_iterator const_reverse_iterator; |
ed6814f7 | 168 | |
2dbe56bd JW |
169 | #if __cplusplus > 201402L |
170 | using node_type = typename _Rep_type::node_type; | |
171 | using insert_return_type = typename _Rep_type::insert_return_type; | |
172 | #endif | |
173 | ||
f6592a9e | 174 | // [23.3.1.1] construct/copy/destroy |
4d0bb770 JW |
175 | // (get_allocator() is also listed in this section) |
176 | ||
f6592a9e PC |
177 | /** |
178 | * @brief Default constructor creates no elements. | |
179 | */ | |
d72c3f0a FD |
180 | #if __cplusplus < 201103L |
181 | map() : _M_t() { } | |
182 | #else | |
183 | map() = default; | |
184 | #endif | |
ed6814f7 | 185 | |
f6592a9e | 186 | /** |
78b36b70 | 187 | * @brief Creates a %map with no elements. |
93c66bc6 BK |
188 | * @param __comp A comparison object. |
189 | * @param __a An allocator object. | |
f6592a9e PC |
190 | */ |
191 | explicit | |
78b36b70 PC |
192 | map(const _Compare& __comp, |
193 | const allocator_type& __a = allocator_type()) | |
ff15f019 | 194 | : _M_t(__comp, _Pair_alloc_type(__a)) { } |
ed6814f7 | 195 | |
f6592a9e | 196 | /** |
78b36b70 | 197 | * @brief %Map copy constructor. |
f6592a9e | 198 | * |
a4dec0d6 | 199 | * Whether the allocator is copied depends on the allocator traits. |
f6592a9e | 200 | */ |
a4dec0d6 | 201 | #if __cplusplus < 201103L |
f6592a9e | 202 | map(const map& __x) |
3971a4d2 | 203 | : _M_t(__x._M_t) { } |
a4dec0d6 FD |
204 | #else |
205 | map(const map&) = default; | |
ed6814f7 | 206 | |
78b36b70 PC |
207 | /** |
208 | * @brief %Map move constructor. | |
78b36b70 | 209 | * |
a4dec0d6 FD |
210 | * The newly-created %map contains the exact contents of the moved |
211 | * instance. The moved instance is a valid, but unspecified, %map. | |
78b36b70 | 212 | */ |
a4dec0d6 | 213 | map(map&&) = default; |
988499f4 JM |
214 | |
215 | /** | |
216 | * @brief Builds a %map from an initializer_list. | |
93c66bc6 BK |
217 | * @param __l An initializer_list. |
218 | * @param __comp A comparison object. | |
219 | * @param __a An allocator object. | |
988499f4 JM |
220 | * |
221 | * Create a %map consisting of copies of the elements in the | |
93c66bc6 | 222 | * initializer_list @a __l. |
988499f4 | 223 | * This is linear in N if the range is already sorted, and NlogN |
93c66bc6 | 224 | * otherwise (where N is @a __l.size()). |
988499f4 JM |
225 | */ |
226 | map(initializer_list<value_type> __l, | |
93c66bc6 | 227 | const _Compare& __comp = _Compare(), |
988499f4 | 228 | const allocator_type& __a = allocator_type()) |
ff15f019 | 229 | : _M_t(__comp, _Pair_alloc_type(__a)) |
988499f4 | 230 | { _M_t._M_insert_unique(__l.begin(), __l.end()); } |
ff90a89e JW |
231 | |
232 | /// Allocator-extended default constructor. | |
233 | explicit | |
234 | map(const allocator_type& __a) | |
235 | : _M_t(_Compare(), _Pair_alloc_type(__a)) { } | |
236 | ||
237 | /// Allocator-extended copy constructor. | |
238 | map(const map& __m, const allocator_type& __a) | |
239 | : _M_t(__m._M_t, _Pair_alloc_type(__a)) { } | |
240 | ||
241 | /// Allocator-extended move constructor. | |
242 | map(map&& __m, const allocator_type& __a) | |
243 | noexcept(is_nothrow_copy_constructible<_Compare>::value | |
244 | && _Alloc_traits::_S_always_equal()) | |
245 | : _M_t(std::move(__m._M_t), _Pair_alloc_type(__a)) { } | |
246 | ||
247 | /// Allocator-extended initialier-list constructor. | |
248 | map(initializer_list<value_type> __l, const allocator_type& __a) | |
249 | : _M_t(_Compare(), _Pair_alloc_type(__a)) | |
250 | { _M_t._M_insert_unique(__l.begin(), __l.end()); } | |
251 | ||
252 | /// Allocator-extended range constructor. | |
253 | template<typename _InputIterator> | |
fe62dd04 | 254 | map(_InputIterator __first, _InputIterator __last, |
ff90a89e JW |
255 | const allocator_type& __a) |
256 | : _M_t(_Compare(), _Pair_alloc_type(__a)) | |
fe62dd04 | 257 | { _M_t._M_insert_unique(__first, __last); } |
78b36b70 PC |
258 | #endif |
259 | ||
f6592a9e PC |
260 | /** |
261 | * @brief Builds a %map from a range. | |
93c66bc6 BK |
262 | * @param __first An input iterator. |
263 | * @param __last An input iterator. | |
f6592a9e | 264 | * |
93c66bc6 BK |
265 | * Create a %map consisting of copies of the elements from |
266 | * [__first,__last). This is linear in N if the range is | |
267 | * already sorted, and NlogN otherwise (where N is | |
268 | * distance(__first,__last)). | |
f6592a9e | 269 | */ |
78b36b70 | 270 | template<typename _InputIterator> |
fe62dd04 | 271 | map(_InputIterator __first, _InputIterator __last) |
78b36b70 | 272 | : _M_t() |
fe62dd04 | 273 | { _M_t._M_insert_unique(__first, __last); } |
ed6814f7 | 274 | |
f6592a9e PC |
275 | /** |
276 | * @brief Builds a %map from a range. | |
93c66bc6 BK |
277 | * @param __first An input iterator. |
278 | * @param __last An input iterator. | |
279 | * @param __comp A comparison functor. | |
280 | * @param __a An allocator object. | |
f6592a9e | 281 | * |
93c66bc6 BK |
282 | * Create a %map consisting of copies of the elements from |
283 | * [__first,__last). This is linear in N if the range is | |
284 | * already sorted, and NlogN otherwise (where N is | |
285 | * distance(__first,__last)). | |
f6592a9e | 286 | */ |
78b36b70 | 287 | template<typename _InputIterator> |
fe62dd04 | 288 | map(_InputIterator __first, _InputIterator __last, |
78b36b70 PC |
289 | const _Compare& __comp, |
290 | const allocator_type& __a = allocator_type()) | |
ff15f019 | 291 | : _M_t(__comp, _Pair_alloc_type(__a)) |
fe62dd04 | 292 | { _M_t._M_insert_unique(__first, __last); } |
ed6814f7 | 293 | |
a4dec0d6 | 294 | #if __cplusplus >= 201103L |
f6592a9e PC |
295 | /** |
296 | * The dtor only erases the elements, and note that if the elements | |
297 | * themselves are pointers, the pointed-to memory is not touched in any | |
28dac70a | 298 | * way. Managing the pointer is the user's responsibility. |
f6592a9e | 299 | */ |
a4dec0d6 FD |
300 | ~map() = default; |
301 | #endif | |
ed6814f7 | 302 | |
f6592a9e | 303 | /** |
78b36b70 | 304 | * @brief %Map assignment operator. |
0a2bf188 JW |
305 | * |
306 | * Whether the allocator is copied depends on the allocator traits. | |
f6592a9e | 307 | */ |
a4dec0d6 | 308 | #if __cplusplus < 201103L |
f6592a9e PC |
309 | map& |
310 | operator=(const map& __x) | |
311 | { | |
312 | _M_t = __x._M_t; | |
313 | return *this; | |
314 | } | |
a4dec0d6 FD |
315 | #else |
316 | map& | |
317 | operator=(const map&) = default; | |
ed6814f7 | 318 | |
c6195f58 | 319 | /// Move assignment operator. |
78b36b70 | 320 | map& |
c6195f58 | 321 | operator=(map&&) = default; |
988499f4 JM |
322 | |
323 | /** | |
324 | * @brief %Map list assignment operator. | |
93c66bc6 | 325 | * @param __l An initializer_list. |
988499f4 JM |
326 | * |
327 | * This function fills a %map with copies of the elements in the | |
93c66bc6 | 328 | * initializer list @a __l. |
988499f4 JM |
329 | * |
330 | * Note that the assignment completely changes the %map and | |
331 | * that the resulting %map's size is the same as the number | |
0a2bf188 | 332 | * of elements assigned. |
988499f4 JM |
333 | */ |
334 | map& | |
335 | operator=(initializer_list<value_type> __l) | |
336 | { | |
c6195f58 | 337 | _M_t._M_assign_unique(__l.begin(), __l.end()); |
988499f4 JM |
338 | return *this; |
339 | } | |
78b36b70 PC |
340 | #endif |
341 | ||
f6592a9e PC |
342 | /// Get a copy of the memory allocation object. |
343 | allocator_type | |
d3677132 | 344 | get_allocator() const _GLIBCXX_NOEXCEPT |
ff15f019 | 345 | { return allocator_type(_M_t.get_allocator()); } |
ed6814f7 | 346 | |
f6592a9e PC |
347 | // iterators |
348 | /** | |
ed6814f7 | 349 | * Returns a read/write iterator that points to the first pair in the |
f6592a9e PC |
350 | * %map. |
351 | * Iteration is done in ascending order according to the keys. | |
352 | */ | |
353 | iterator | |
d3677132 | 354 | begin() _GLIBCXX_NOEXCEPT |
f6592a9e | 355 | { return _M_t.begin(); } |
ed6814f7 | 356 | |
f6592a9e PC |
357 | /** |
358 | * Returns a read-only (constant) iterator that points to the first pair | |
359 | * in the %map. Iteration is done in ascending order according to the | |
360 | * keys. | |
361 | */ | |
362 | const_iterator | |
d3677132 | 363 | begin() const _GLIBCXX_NOEXCEPT |
f6592a9e | 364 | { return _M_t.begin(); } |
ed6814f7 | 365 | |
f6592a9e | 366 | /** |
45f388bb BK |
367 | * Returns a read/write iterator that points one past the last |
368 | * pair in the %map. Iteration is done in ascending order | |
369 | * according to the keys. | |
f6592a9e PC |
370 | */ |
371 | iterator | |
d3677132 | 372 | end() _GLIBCXX_NOEXCEPT |
f6592a9e | 373 | { return _M_t.end(); } |
ed6814f7 | 374 | |
f6592a9e PC |
375 | /** |
376 | * Returns a read-only (constant) iterator that points one past the last | |
377 | * pair in the %map. Iteration is done in ascending order according to | |
378 | * the keys. | |
379 | */ | |
380 | const_iterator | |
d3677132 | 381 | end() const _GLIBCXX_NOEXCEPT |
f6592a9e | 382 | { return _M_t.end(); } |
ed6814f7 | 383 | |
f6592a9e PC |
384 | /** |
385 | * Returns a read/write reverse iterator that points to the last pair in | |
386 | * the %map. Iteration is done in descending order according to the | |
387 | * keys. | |
388 | */ | |
389 | reverse_iterator | |
d3677132 | 390 | rbegin() _GLIBCXX_NOEXCEPT |
f6592a9e | 391 | { return _M_t.rbegin(); } |
ed6814f7 | 392 | |
f6592a9e PC |
393 | /** |
394 | * Returns a read-only (constant) reverse iterator that points to the | |
395 | * last pair in the %map. Iteration is done in descending order | |
396 | * according to the keys. | |
397 | */ | |
398 | const_reverse_iterator | |
d3677132 | 399 | rbegin() const _GLIBCXX_NOEXCEPT |
f6592a9e | 400 | { return _M_t.rbegin(); } |
ed6814f7 | 401 | |
f6592a9e PC |
402 | /** |
403 | * Returns a read/write reverse iterator that points to one before the | |
404 | * first pair in the %map. Iteration is done in descending order | |
405 | * according to the keys. | |
406 | */ | |
407 | reverse_iterator | |
d3677132 | 408 | rend() _GLIBCXX_NOEXCEPT |
f6592a9e | 409 | { return _M_t.rend(); } |
ed6814f7 | 410 | |
f6592a9e PC |
411 | /** |
412 | * Returns a read-only (constant) reverse iterator that points to one | |
413 | * before the first pair in the %map. Iteration is done in descending | |
414 | * order according to the keys. | |
415 | */ | |
416 | const_reverse_iterator | |
d3677132 | 417 | rend() const _GLIBCXX_NOEXCEPT |
f6592a9e | 418 | { return _M_t.rend(); } |
ed6814f7 | 419 | |
734f5023 | 420 | #if __cplusplus >= 201103L |
0cd50f89 PC |
421 | /** |
422 | * Returns a read-only (constant) iterator that points to the first pair | |
423 | * in the %map. Iteration is done in ascending order according to the | |
424 | * keys. | |
425 | */ | |
426 | const_iterator | |
d3677132 | 427 | cbegin() const noexcept |
0cd50f89 PC |
428 | { return _M_t.begin(); } |
429 | ||
430 | /** | |
431 | * Returns a read-only (constant) iterator that points one past the last | |
432 | * pair in the %map. Iteration is done in ascending order according to | |
433 | * the keys. | |
434 | */ | |
435 | const_iterator | |
d3677132 | 436 | cend() const noexcept |
0cd50f89 PC |
437 | { return _M_t.end(); } |
438 | ||
439 | /** | |
440 | * Returns a read-only (constant) reverse iterator that points to the | |
441 | * last pair in the %map. Iteration is done in descending order | |
442 | * according to the keys. | |
443 | */ | |
444 | const_reverse_iterator | |
d3677132 | 445 | crbegin() const noexcept |
0cd50f89 PC |
446 | { return _M_t.rbegin(); } |
447 | ||
448 | /** | |
449 | * Returns a read-only (constant) reverse iterator that points to one | |
450 | * before the first pair in the %map. Iteration is done in descending | |
451 | * order according to the keys. | |
452 | */ | |
453 | const_reverse_iterator | |
d3677132 | 454 | crend() const noexcept |
0cd50f89 PC |
455 | { return _M_t.rend(); } |
456 | #endif | |
457 | ||
f6592a9e PC |
458 | // capacity |
459 | /** Returns true if the %map is empty. (Thus begin() would equal | |
460 | * end().) | |
461 | */ | |
462 | bool | |
d3677132 | 463 | empty() const _GLIBCXX_NOEXCEPT |
f6592a9e | 464 | { return _M_t.empty(); } |
ed6814f7 | 465 | |
f6592a9e PC |
466 | /** Returns the size of the %map. */ |
467 | size_type | |
d3677132 | 468 | size() const _GLIBCXX_NOEXCEPT |
f6592a9e | 469 | { return _M_t.size(); } |
ed6814f7 | 470 | |
f6592a9e PC |
471 | /** Returns the maximum size of the %map. */ |
472 | size_type | |
d3677132 | 473 | max_size() const _GLIBCXX_NOEXCEPT |
f6592a9e | 474 | { return _M_t.max_size(); } |
ed6814f7 | 475 | |
f6592a9e PC |
476 | // [23.3.1.2] element access |
477 | /** | |
478 | * @brief Subscript ( @c [] ) access to %map data. | |
93c66bc6 | 479 | * @param __k The key for which data should be retrieved. |
f6592a9e PC |
480 | * @return A reference to the data of the (key,data) %pair. |
481 | * | |
45f388bb BK |
482 | * Allows for easy lookup with the subscript ( @c [] ) |
483 | * operator. Returns data associated with the key specified in | |
484 | * subscript. If the key does not exist, a pair with that key | |
485 | * is created using default values, which is then returned. | |
f6592a9e PC |
486 | * |
487 | * Lookup requires logarithmic time. | |
488 | */ | |
489 | mapped_type& | |
490 | operator[](const key_type& __k) | |
491 | { | |
492 | // concept requirements | |
493 | __glibcxx_function_requires(_DefaultConstructibleConcept<mapped_type>) | |
ed6814f7 | 494 | |
f6592a9e PC |
495 | iterator __i = lower_bound(__k); |
496 | // __i->first is greater than or equivalent to __k. | |
497 | if (__i == end() || key_comp()(__k, (*__i).first)) | |
734f5023 | 498 | #if __cplusplus >= 201103L |
55826ab6 FD |
499 | __i = _M_t._M_emplace_hint_unique(__i, std::piecewise_construct, |
500 | std::tuple<const key_type&>(__k), | |
501 | std::tuple<>()); | |
502 | #else | |
fe62dd04 | 503 | __i = insert(__i, value_type(__k, mapped_type())); |
55826ab6 | 504 | #endif |
f6592a9e PC |
505 | return (*__i).second; |
506 | } | |
ed6814f7 | 507 | |
734f5023 | 508 | #if __cplusplus >= 201103L |
e6a05448 PC |
509 | mapped_type& |
510 | operator[](key_type&& __k) | |
511 | { | |
512 | // concept requirements | |
513 | __glibcxx_function_requires(_DefaultConstructibleConcept<mapped_type>) | |
514 | ||
515 | iterator __i = lower_bound(__k); | |
516 | // __i->first is greater than or equivalent to __k. | |
517 | if (__i == end() || key_comp()(__k, (*__i).first)) | |
55826ab6 FD |
518 | __i = _M_t._M_emplace_hint_unique(__i, std::piecewise_construct, |
519 | std::forward_as_tuple(std::move(__k)), | |
520 | std::tuple<>()); | |
e6a05448 PC |
521 | return (*__i).second; |
522 | } | |
523 | #endif | |
524 | ||
8b5f07a2 PC |
525 | // _GLIBCXX_RESOLVE_LIB_DEFECTS |
526 | // DR 464. Suggestion for new member functions in standard containers. | |
527 | /** | |
528 | * @brief Access to %map data. | |
93c66bc6 BK |
529 | * @param __k The key for which data should be retrieved. |
530 | * @return A reference to the data whose key is equivalent to @a __k, if | |
76c6705b | 531 | * such a data is present in the %map. |
8b5f07a2 PC |
532 | * @throw std::out_of_range If no such data is present. |
533 | */ | |
534 | mapped_type& | |
535 | at(const key_type& __k) | |
536 | { | |
537 | iterator __i = lower_bound(__k); | |
538 | if (__i == end() || key_comp()(__k, (*__i).first)) | |
539 | __throw_out_of_range(__N("map::at")); | |
540 | return (*__i).second; | |
541 | } | |
542 | ||
543 | const mapped_type& | |
544 | at(const key_type& __k) const | |
545 | { | |
546 | const_iterator __i = lower_bound(__k); | |
547 | if (__i == end() || key_comp()(__k, (*__i).first)) | |
548 | __throw_out_of_range(__N("map::at")); | |
549 | return (*__i).second; | |
550 | } | |
551 | ||
f6592a9e | 552 | // modifiers |
734f5023 | 553 | #if __cplusplus >= 201103L |
55826ab6 FD |
554 | /** |
555 | * @brief Attempts to build and insert a std::pair into the %map. | |
556 | * | |
557 | * @param __args Arguments used to generate a new pair instance (see | |
558 | * std::piecewise_contruct for passing arguments to each | |
559 | * part of the pair constructor). | |
560 | * | |
561 | * @return A pair, of which the first element is an iterator that points | |
562 | * to the possibly inserted pair, and the second is a bool that | |
563 | * is true if the pair was actually inserted. | |
564 | * | |
565 | * This function attempts to build and insert a (key, value) %pair into | |
566 | * the %map. | |
567 | * A %map relies on unique keys and thus a %pair is only inserted if its | |
568 | * first element (the key) is not already present in the %map. | |
569 | * | |
570 | * Insertion requires logarithmic time. | |
571 | */ | |
572 | template<typename... _Args> | |
573 | std::pair<iterator, bool> | |
574 | emplace(_Args&&... __args) | |
575 | { return _M_t._M_emplace_unique(std::forward<_Args>(__args)...); } | |
576 | ||
577 | /** | |
578 | * @brief Attempts to build and insert a std::pair into the %map. | |
579 | * | |
580 | * @param __pos An iterator that serves as a hint as to where the pair | |
581 | * should be inserted. | |
582 | * @param __args Arguments used to generate a new pair instance (see | |
583 | * std::piecewise_contruct for passing arguments to each | |
584 | * part of the pair constructor). | |
585 | * @return An iterator that points to the element with key of the | |
586 | * std::pair built from @a __args (may or may not be that | |
587 | * std::pair). | |
588 | * | |
589 | * This function is not concerned about whether the insertion took place, | |
590 | * and thus does not return a boolean like the single-argument emplace() | |
591 | * does. | |
592 | * Note that the first parameter is only a hint and can potentially | |
593 | * improve the performance of the insertion process. A bad hint would | |
594 | * cause no gains in efficiency. | |
595 | * | |
596 | * See | |
10d43d2f | 597 | * https://gcc.gnu.org/onlinedocs/libstdc++/manual/associative.html#containers.associative.insert_hints |
55826ab6 FD |
598 | * for more on @a hinting. |
599 | * | |
600 | * Insertion requires logarithmic time (if the hint is not taken). | |
601 | */ | |
602 | template<typename... _Args> | |
603 | iterator | |
604 | emplace_hint(const_iterator __pos, _Args&&... __args) | |
605 | { | |
606 | return _M_t._M_emplace_hint_unique(__pos, | |
607 | std::forward<_Args>(__args)...); | |
608 | } | |
609 | #endif | |
db23e4c4 | 610 | |
2dbe56bd JW |
611 | #if __cplusplus > 201402L |
612 | /// Extract a node. | |
613 | node_type | |
614 | extract(const_iterator __pos) | |
976160b9 JW |
615 | { |
616 | __glibcxx_assert(__pos != end()); | |
617 | return _M_t.extract(__pos); | |
618 | } | |
2dbe56bd JW |
619 | |
620 | /// Extract a node. | |
621 | node_type | |
622 | extract(const key_type& __x) | |
623 | { return _M_t.extract(__x); } | |
624 | ||
625 | /// Re-insert an extracted node. | |
626 | insert_return_type | |
627 | insert(node_type&& __nh) | |
628 | { return _M_t._M_reinsert_node_unique(std::move(__nh)); } | |
629 | ||
630 | /// Re-insert an extracted node. | |
631 | iterator | |
632 | insert(const_iterator __hint, node_type&& __nh) | |
633 | { return _M_t._M_reinsert_node_hint_unique(__hint, std::move(__nh)); } | |
634 | ||
635 | template<typename, typename> | |
636 | friend class _Rb_tree_merge_helper; | |
637 | ||
638 | template<typename _C2> | |
639 | void | |
640 | merge(map<_Key, _Tp, _C2, _Alloc>& __source) | |
641 | { | |
642 | using _Merge_helper = _Rb_tree_merge_helper<map, _C2>; | |
643 | _M_t._M_merge_unique(_Merge_helper::_S_get_tree(__source)); | |
644 | } | |
645 | ||
646 | template<typename _C2> | |
647 | void | |
648 | merge(map<_Key, _Tp, _C2, _Alloc>&& __source) | |
649 | { merge(__source); } | |
650 | ||
651 | template<typename _C2> | |
652 | void | |
653 | merge(multimap<_Key, _Tp, _C2, _Alloc>& __source) | |
654 | { | |
655 | using _Merge_helper = _Rb_tree_merge_helper<map, _C2>; | |
656 | _M_t._M_merge_unique(_Merge_helper::_S_get_tree(__source)); | |
657 | } | |
658 | ||
659 | template<typename _C2> | |
660 | void | |
661 | merge(multimap<_Key, _Tp, _C2, _Alloc>&& __source) | |
662 | { merge(__source); } | |
663 | #endif // C++17 | |
664 | ||
b95170d3 | 665 | #if __cplusplus > 201402L |
db23e4c4 | 666 | #define __cpp_lib_map_try_emplace 201411 |
b95170d3 VV |
667 | /** |
668 | * @brief Attempts to build and insert a std::pair into the %map. | |
669 | * | |
670 | * @param __k Key to use for finding a possibly existing pair in | |
671 | * the map. | |
fe62dd04 | 672 | * @param __args Arguments used to generate the .second for a new pair |
b95170d3 VV |
673 | * instance. |
674 | * | |
675 | * @return A pair, of which the first element is an iterator that points | |
676 | * to the possibly inserted pair, and the second is a bool that | |
677 | * is true if the pair was actually inserted. | |
678 | * | |
679 | * This function attempts to build and insert a (key, value) %pair into | |
680 | * the %map. | |
681 | * A %map relies on unique keys and thus a %pair is only inserted if its | |
682 | * first element (the key) is not already present in the %map. | |
683 | * If a %pair is not inserted, this function has no effect. | |
684 | * | |
685 | * Insertion requires logarithmic time. | |
686 | */ | |
687 | template <typename... _Args> | |
fe62dd04 FD |
688 | pair<iterator, bool> |
689 | try_emplace(const key_type& __k, _Args&&... __args) | |
690 | { | |
691 | iterator __i = lower_bound(__k); | |
692 | if (__i == end() || key_comp()(__k, (*__i).first)) | |
693 | { | |
694 | __i = emplace_hint(__i, std::piecewise_construct, | |
695 | std::forward_as_tuple(__k), | |
696 | std::forward_as_tuple( | |
697 | std::forward<_Args>(__args)...)); | |
698 | return {__i, true}; | |
699 | } | |
700 | return {__i, false}; | |
701 | } | |
b95170d3 VV |
702 | |
703 | // move-capable overload | |
704 | template <typename... _Args> | |
fe62dd04 FD |
705 | pair<iterator, bool> |
706 | try_emplace(key_type&& __k, _Args&&... __args) | |
707 | { | |
708 | iterator __i = lower_bound(__k); | |
709 | if (__i == end() || key_comp()(__k, (*__i).first)) | |
710 | { | |
711 | __i = emplace_hint(__i, std::piecewise_construct, | |
712 | std::forward_as_tuple(std::move(__k)), | |
713 | std::forward_as_tuple( | |
714 | std::forward<_Args>(__args)...)); | |
715 | return {__i, true}; | |
716 | } | |
717 | return {__i, false}; | |
718 | } | |
55826ab6 | 719 | |
b95170d3 VV |
720 | /** |
721 | * @brief Attempts to build and insert a std::pair into the %map. | |
722 | * | |
723 | * @param __hint An iterator that serves as a hint as to where the | |
724 | * pair should be inserted. | |
725 | * @param __k Key to use for finding a possibly existing pair in | |
726 | * the map. | |
fe62dd04 | 727 | * @param __args Arguments used to generate the .second for a new pair |
b95170d3 VV |
728 | * instance. |
729 | * @return An iterator that points to the element with key of the | |
730 | * std::pair built from @a __args (may or may not be that | |
731 | * std::pair). | |
732 | * | |
733 | * This function is not concerned about whether the insertion took place, | |
fe62dd04 | 734 | * and thus does not return a boolean like the single-argument |
b95170d3 VV |
735 | * try_emplace() does. However, if insertion did not take place, |
736 | * this function has no effect. | |
737 | * Note that the first parameter is only a hint and can potentially | |
738 | * improve the performance of the insertion process. A bad hint would | |
739 | * cause no gains in efficiency. | |
740 | * | |
741 | * See | |
742 | * https://gcc.gnu.org/onlinedocs/libstdc++/manual/associative.html#containers.associative.insert_hints | |
743 | * for more on @a hinting. | |
744 | * | |
745 | * Insertion requires logarithmic time (if the hint is not taken). | |
746 | */ | |
747 | template <typename... _Args> | |
fe62dd04 FD |
748 | iterator |
749 | try_emplace(const_iterator __hint, const key_type& __k, | |
750 | _Args&&... __args) | |
751 | { | |
752 | iterator __i; | |
753 | auto __true_hint = _M_t._M_get_insert_hint_unique_pos(__hint, __k); | |
754 | if (__true_hint.second) | |
755 | __i = emplace_hint(iterator(__true_hint.second), | |
756 | std::piecewise_construct, | |
757 | std::forward_as_tuple(__k), | |
758 | std::forward_as_tuple( | |
759 | std::forward<_Args>(__args)...)); | |
760 | else | |
761 | __i = iterator(__true_hint.first); | |
762 | return __i; | |
763 | } | |
b95170d3 VV |
764 | |
765 | // move-capable overload | |
766 | template <typename... _Args> | |
fe62dd04 FD |
767 | iterator |
768 | try_emplace(const_iterator __hint, key_type&& __k, _Args&&... __args) | |
769 | { | |
770 | iterator __i; | |
771 | auto __true_hint = _M_t._M_get_insert_hint_unique_pos(__hint, __k); | |
772 | if (__true_hint.second) | |
773 | __i = emplace_hint(iterator(__true_hint.second), | |
774 | std::piecewise_construct, | |
775 | std::forward_as_tuple(std::move(__k)), | |
776 | std::forward_as_tuple( | |
777 | std::forward<_Args>(__args)...)); | |
778 | else | |
779 | __i = iterator(__true_hint.first); | |
780 | return __i; | |
781 | } | |
b95170d3 | 782 | #endif |
db23e4c4 | 783 | |
f6592a9e PC |
784 | /** |
785 | * @brief Attempts to insert a std::pair into the %map. | |
93c66bc6 BK |
786 | * @param __x Pair to be inserted (see std::make_pair for easy |
787 | * creation of pairs). | |
788 | * | |
fe62dd04 FD |
789 | * @return A pair, of which the first element is an iterator that |
790 | * points to the possibly inserted pair, and the second is | |
45f388bb | 791 | * a bool that is true if the pair was actually inserted. |
f6592a9e PC |
792 | * |
793 | * This function attempts to insert a (key, value) %pair into the %map. | |
794 | * A %map relies on unique keys and thus a %pair is only inserted if its | |
795 | * first element (the key) is not already present in the %map. | |
796 | * | |
797 | * Insertion requires logarithmic time. | |
3b0dd4fe | 798 | * @{ |
f6592a9e | 799 | */ |
eb9af792 | 800 | std::pair<iterator, bool> |
f6592a9e | 801 | insert(const value_type& __x) |
42a27024 | 802 | { return _M_t._M_insert_unique(__x); } |
ed6814f7 | 803 | |
734f5023 | 804 | #if __cplusplus >= 201103L |
3b0dd4fe JW |
805 | // _GLIBCXX_RESOLVE_LIB_DEFECTS |
806 | // 2354. Unnecessary copying when inserting into maps with braced-init | |
807 | std::pair<iterator, bool> | |
808 | insert(value_type&& __x) | |
809 | { return _M_t._M_insert_unique(std::move(__x)); } | |
810 | ||
e6a05448 | 811 | template<typename _Pair, typename = typename |
57cee56a PC |
812 | std::enable_if<std::is_constructible<value_type, |
813 | _Pair&&>::value>::type> | |
fe62dd04 FD |
814 | std::pair<iterator, bool> |
815 | insert(_Pair&& __x) | |
816 | { return _M_t._M_insert_unique(std::forward<_Pair>(__x)); } | |
e6a05448 | 817 | #endif |
3b0dd4fe | 818 | // @} |
e6a05448 | 819 | |
734f5023 | 820 | #if __cplusplus >= 201103L |
09357846 JM |
821 | /** |
822 | * @brief Attempts to insert a list of std::pairs into the %map. | |
93c66bc6 BK |
823 | * @param __list A std::initializer_list<value_type> of pairs to be |
824 | * inserted. | |
09357846 JM |
825 | * |
826 | * Complexity similar to that of the range constructor. | |
09357846 JM |
827 | */ |
828 | void | |
6010fae7 | 829 | insert(std::initializer_list<value_type> __list) |
7606bd11 | 830 | { insert(__list.begin(), __list.end()); } |
6010fae7 | 831 | #endif |
09357846 | 832 | |
f6592a9e PC |
833 | /** |
834 | * @brief Attempts to insert a std::pair into the %map. | |
93c66bc6 | 835 | * @param __position An iterator that serves as a hint as to where the |
f6592a9e | 836 | * pair should be inserted. |
93c66bc6 BK |
837 | * @param __x Pair to be inserted (see std::make_pair for easy creation |
838 | * of pairs). | |
839 | * @return An iterator that points to the element with key of | |
840 | * @a __x (may or may not be the %pair passed in). | |
f6592a9e | 841 | * |
45f388bb BK |
842 | |
843 | * This function is not concerned about whether the insertion | |
844 | * took place, and thus does not return a boolean like the | |
845 | * single-argument insert() does. Note that the first | |
846 | * parameter is only a hint and can potentially improve the | |
847 | * performance of the insertion process. A bad hint would | |
848 | * cause no gains in efficiency. | |
f6592a9e | 849 | * |
45f388bb | 850 | * See |
10d43d2f | 851 | * https://gcc.gnu.org/onlinedocs/libstdc++/manual/associative.html#containers.associative.insert_hints |
2a60a9f6 | 852 | * for more on @a hinting. |
f6592a9e PC |
853 | * |
854 | * Insertion requires logarithmic time (if the hint is not taken). | |
3b0dd4fe | 855 | * @{ |
f6592a9e PC |
856 | */ |
857 | iterator | |
734f5023 | 858 | #if __cplusplus >= 201103L |
7606bd11 PC |
859 | insert(const_iterator __position, const value_type& __x) |
860 | #else | |
eb9af792 | 861 | insert(iterator __position, const value_type& __x) |
7606bd11 | 862 | #endif |
eb9af792 | 863 | { return _M_t._M_insert_unique_(__position, __x); } |
ed6814f7 | 864 | |
734f5023 | 865 | #if __cplusplus >= 201103L |
3b0dd4fe JW |
866 | // _GLIBCXX_RESOLVE_LIB_DEFECTS |
867 | // 2354. Unnecessary copying when inserting into maps with braced-init | |
868 | iterator | |
869 | insert(const_iterator __position, value_type&& __x) | |
870 | { return _M_t._M_insert_unique_(__position, std::move(__x)); } | |
871 | ||
e6a05448 | 872 | template<typename _Pair, typename = typename |
57cee56a PC |
873 | std::enable_if<std::is_constructible<value_type, |
874 | _Pair&&>::value>::type> | |
fe62dd04 FD |
875 | iterator |
876 | insert(const_iterator __position, _Pair&& __x) | |
877 | { return _M_t._M_insert_unique_(__position, | |
e6a05448 PC |
878 | std::forward<_Pair>(__x)); } |
879 | #endif | |
3b0dd4fe | 880 | // @} |
e6a05448 | 881 | |
f6592a9e | 882 | /** |
28dac70a | 883 | * @brief Template function that attempts to insert a range of elements. |
93c66bc6 BK |
884 | * @param __first Iterator pointing to the start of the range to be |
885 | * inserted. | |
886 | * @param __last Iterator pointing to the end of the range. | |
f6592a9e PC |
887 | * |
888 | * Complexity similar to that of the range constructor. | |
889 | */ | |
78b36b70 | 890 | template<typename _InputIterator> |
fe62dd04 FD |
891 | void |
892 | insert(_InputIterator __first, _InputIterator __last) | |
893 | { _M_t._M_insert_unique(__first, __last); } | |
ed6814f7 | 894 | |
b95170d3 | 895 | #if __cplusplus > 201402L |
db23e4c4 | 896 | #define __cpp_lib_map_insertion 201411 |
b95170d3 VV |
897 | /** |
898 | * @brief Attempts to insert or assign a std::pair into the %map. | |
899 | * @param __k Key to use for finding a possibly existing pair in | |
900 | * the map. | |
fe62dd04 | 901 | * @param __obj Argument used to generate the .second for a pair |
b95170d3 VV |
902 | * instance. |
903 | * | |
fe62dd04 FD |
904 | * @return A pair, of which the first element is an iterator that |
905 | * points to the possibly inserted pair, and the second is | |
b95170d3 VV |
906 | * a bool that is true if the pair was actually inserted. |
907 | * | |
908 | * This function attempts to insert a (key, value) %pair into the %map. | |
909 | * A %map relies on unique keys and thus a %pair is only inserted if its | |
910 | * first element (the key) is not already present in the %map. | |
911 | * If the %pair was already in the %map, the .second of the %pair | |
912 | * is assigned from __obj. | |
913 | * | |
914 | * Insertion requires logarithmic time. | |
915 | */ | |
916 | template <typename _Obj> | |
fe62dd04 FD |
917 | pair<iterator, bool> |
918 | insert_or_assign(const key_type& __k, _Obj&& __obj) | |
919 | { | |
920 | iterator __i = lower_bound(__k); | |
921 | if (__i == end() || key_comp()(__k, (*__i).first)) | |
922 | { | |
923 | __i = emplace_hint(__i, std::piecewise_construct, | |
924 | std::forward_as_tuple(__k), | |
925 | std::forward_as_tuple( | |
926 | std::forward<_Obj>(__obj))); | |
927 | return {__i, true}; | |
928 | } | |
929 | (*__i).second = std::forward<_Obj>(__obj); | |
930 | return {__i, false}; | |
931 | } | |
b95170d3 VV |
932 | |
933 | // move-capable overload | |
934 | template <typename _Obj> | |
fe62dd04 FD |
935 | pair<iterator, bool> |
936 | insert_or_assign(key_type&& __k, _Obj&& __obj) | |
937 | { | |
938 | iterator __i = lower_bound(__k); | |
939 | if (__i == end() || key_comp()(__k, (*__i).first)) | |
940 | { | |
941 | __i = emplace_hint(__i, std::piecewise_construct, | |
942 | std::forward_as_tuple(std::move(__k)), | |
943 | std::forward_as_tuple( | |
944 | std::forward<_Obj>(__obj))); | |
945 | return {__i, true}; | |
946 | } | |
947 | (*__i).second = std::forward<_Obj>(__obj); | |
948 | return {__i, false}; | |
949 | } | |
b95170d3 VV |
950 | |
951 | /** | |
952 | * @brief Attempts to insert or assign a std::pair into the %map. | |
953 | * @param __hint An iterator that serves as a hint as to where the | |
954 | * pair should be inserted. | |
955 | * @param __k Key to use for finding a possibly existing pair in | |
956 | * the map. | |
fe62dd04 | 957 | * @param __obj Argument used to generate the .second for a pair |
b95170d3 VV |
958 | * instance. |
959 | * | |
960 | * @return An iterator that points to the element with key of | |
961 | * @a __x (may or may not be the %pair passed in). | |
962 | * | |
963 | * This function attempts to insert a (key, value) %pair into the %map. | |
964 | * A %map relies on unique keys and thus a %pair is only inserted if its | |
965 | * first element (the key) is not already present in the %map. | |
966 | * If the %pair was already in the %map, the .second of the %pair | |
967 | * is assigned from __obj. | |
968 | * | |
969 | * Insertion requires logarithmic time. | |
970 | */ | |
971 | template <typename _Obj> | |
fe62dd04 FD |
972 | iterator |
973 | insert_or_assign(const_iterator __hint, | |
974 | const key_type& __k, _Obj&& __obj) | |
975 | { | |
976 | iterator __i; | |
977 | auto __true_hint = _M_t._M_get_insert_hint_unique_pos(__hint, __k); | |
978 | if (__true_hint.second) | |
979 | { | |
980 | return emplace_hint(iterator(__true_hint.second), | |
981 | std::piecewise_construct, | |
982 | std::forward_as_tuple(__k), | |
983 | std::forward_as_tuple( | |
984 | std::forward<_Obj>(__obj))); | |
985 | } | |
986 | __i = iterator(__true_hint.first); | |
987 | (*__i).second = std::forward<_Obj>(__obj); | |
988 | return __i; | |
989 | } | |
b95170d3 VV |
990 | |
991 | // move-capable overload | |
992 | template <typename _Obj> | |
fe62dd04 FD |
993 | iterator |
994 | insert_or_assign(const_iterator __hint, key_type&& __k, _Obj&& __obj) | |
995 | { | |
996 | iterator __i; | |
997 | auto __true_hint = _M_t._M_get_insert_hint_unique_pos(__hint, __k); | |
998 | if (__true_hint.second) | |
999 | { | |
1000 | return emplace_hint(iterator(__true_hint.second), | |
1001 | std::piecewise_construct, | |
1002 | std::forward_as_tuple(std::move(__k)), | |
1003 | std::forward_as_tuple( | |
1004 | std::forward<_Obj>(__obj))); | |
1005 | } | |
1006 | __i = iterator(__true_hint.first); | |
1007 | (*__i).second = std::forward<_Obj>(__obj); | |
1008 | return __i; | |
1009 | } | |
b95170d3 VV |
1010 | #endif |
1011 | ||
734f5023 | 1012 | #if __cplusplus >= 201103L |
c105751c ESR |
1013 | // _GLIBCXX_RESOLVE_LIB_DEFECTS |
1014 | // DR 130. Associative erase should return an iterator. | |
1015 | /** | |
1016 | * @brief Erases an element from a %map. | |
93c66bc6 | 1017 | * @param __position An iterator pointing to the element to be erased. |
c105751c | 1018 | * @return An iterator pointing to the element immediately following |
fe62dd04 | 1019 | * @a position prior to the element being erased. If no such |
c105751c ESR |
1020 | * element exists, end() is returned. |
1021 | * | |
1022 | * This function erases an element, pointed to by the given | |
1023 | * iterator, from a %map. Note that this function only erases | |
1024 | * the element, and that if the element is itself a pointer, | |
1025 | * the pointed-to memory is not touched in any way. Managing | |
1026 | * the pointer is the user's responsibility. | |
f23e3d74 JW |
1027 | * |
1028 | * @{ | |
c105751c ESR |
1029 | */ |
1030 | iterator | |
7606bd11 | 1031 | erase(const_iterator __position) |
c105751c | 1032 | { return _M_t.erase(__position); } |
6dc88283 | 1033 | |
3b31a727 BK |
1034 | // LWG 2059 |
1035 | _GLIBCXX_ABI_TAG_CXX11 | |
6dc88283 PC |
1036 | iterator |
1037 | erase(iterator __position) | |
1038 | { return _M_t.erase(__position); } | |
f23e3d74 | 1039 | // @} |
c105751c | 1040 | #else |
f6592a9e PC |
1041 | /** |
1042 | * @brief Erases an element from a %map. | |
93c66bc6 | 1043 | * @param __position An iterator pointing to the element to be erased. |
f6592a9e | 1044 | * |
45f388bb BK |
1045 | * This function erases an element, pointed to by the given |
1046 | * iterator, from a %map. Note that this function only erases | |
1047 | * the element, and that if the element is itself a pointer, | |
1048 | * the pointed-to memory is not touched in any way. Managing | |
28dac70a | 1049 | * the pointer is the user's responsibility. |
f6592a9e | 1050 | */ |
3971a4d2 | 1051 | void |
f6592a9e PC |
1052 | erase(iterator __position) |
1053 | { _M_t.erase(__position); } | |
c105751c | 1054 | #endif |
ed6814f7 | 1055 | |
f6592a9e PC |
1056 | /** |
1057 | * @brief Erases elements according to the provided key. | |
93c66bc6 | 1058 | * @param __x Key of element to be erased. |
f6592a9e PC |
1059 | * @return The number of elements erased. |
1060 | * | |
1061 | * This function erases all the elements located by the given key from | |
1062 | * a %map. | |
1063 | * Note that this function only erases the element, and that if | |
1064 | * the element is itself a pointer, the pointed-to memory is not touched | |
28dac70a | 1065 | * in any way. Managing the pointer is the user's responsibility. |
f6592a9e PC |
1066 | */ |
1067 | size_type | |
1068 | erase(const key_type& __x) | |
1069 | { return _M_t.erase(__x); } | |
ed6814f7 | 1070 | |
734f5023 | 1071 | #if __cplusplus >= 201103L |
c105751c ESR |
1072 | // _GLIBCXX_RESOLVE_LIB_DEFECTS |
1073 | // DR 130. Associative erase should return an iterator. | |
1074 | /** | |
1075 | * @brief Erases a [first,last) range of elements from a %map. | |
93c66bc6 BK |
1076 | * @param __first Iterator pointing to the start of the range to be |
1077 | * erased. | |
1078 | * @param __last Iterator pointing to the end of the range to | |
1079 | * be erased. | |
1080 | * @return The iterator @a __last. | |
c105751c ESR |
1081 | * |
1082 | * This function erases a sequence of elements from a %map. | |
1083 | * Note that this function only erases the element, and that if | |
1084 | * the element is itself a pointer, the pointed-to memory is not touched | |
1085 | * in any way. Managing the pointer is the user's responsibility. | |
1086 | */ | |
1087 | iterator | |
7606bd11 | 1088 | erase(const_iterator __first, const_iterator __last) |
c105751c ESR |
1089 | { return _M_t.erase(__first, __last); } |
1090 | #else | |
f6592a9e | 1091 | /** |
93c66bc6 BK |
1092 | * @brief Erases a [__first,__last) range of elements from a %map. |
1093 | * @param __first Iterator pointing to the start of the range to be | |
1094 | * erased. | |
1095 | * @param __last Iterator pointing to the end of the range to | |
1096 | * be erased. | |
f6592a9e PC |
1097 | * |
1098 | * This function erases a sequence of elements from a %map. | |
1099 | * Note that this function only erases the element, and that if | |
1100 | * the element is itself a pointer, the pointed-to memory is not touched | |
28dac70a | 1101 | * in any way. Managing the pointer is the user's responsibility. |
f6592a9e PC |
1102 | */ |
1103 | void | |
1104 | erase(iterator __first, iterator __last) | |
1105 | { _M_t.erase(__first, __last); } | |
c105751c | 1106 | #endif |
ed6814f7 | 1107 | |
f6592a9e PC |
1108 | /** |
1109 | * @brief Swaps data with another %map. | |
93c66bc6 | 1110 | * @param __x A %map of the same element and allocator types. |
f6592a9e | 1111 | * |
45f388bb BK |
1112 | * This exchanges the elements between two maps in constant |
1113 | * time. (It is only swapping a pointer, an integer, and an | |
1114 | * instance of the @c Compare type (which itself is often | |
1115 | * stateless and empty), so it should be quite fast.) Note | |
1116 | * that the global std::swap() function is specialized such | |
1117 | * that std::swap(m1,m2) will feed to this function. | |
0a2bf188 JW |
1118 | * |
1119 | * Whether the allocators are swapped depends on the allocator traits. | |
f6592a9e PC |
1120 | */ |
1121 | void | |
1122 | swap(map& __x) | |
c5d9ec56 | 1123 | _GLIBCXX_NOEXCEPT_IF(__is_nothrow_swappable<_Compare>::value) |
f6592a9e | 1124 | { _M_t.swap(__x._M_t); } |
ed6814f7 | 1125 | |
f6592a9e | 1126 | /** |
45f388bb BK |
1127 | * Erases all elements in a %map. Note that this function only |
1128 | * erases the elements, and that if the elements themselves are | |
1129 | * pointers, the pointed-to memory is not touched in any way. | |
28dac70a | 1130 | * Managing the pointer is the user's responsibility. |
f6592a9e PC |
1131 | */ |
1132 | void | |
d3677132 | 1133 | clear() _GLIBCXX_NOEXCEPT |
f6592a9e | 1134 | { _M_t.clear(); } |
ed6814f7 | 1135 | |
f6592a9e PC |
1136 | // observers |
1137 | /** | |
1138 | * Returns the key comparison object out of which the %map was | |
1139 | * constructed. | |
1140 | */ | |
1141 | key_compare | |
1142 | key_comp() const | |
1143 | { return _M_t.key_comp(); } | |
ed6814f7 | 1144 | |
f6592a9e PC |
1145 | /** |
1146 | * Returns a value comparison object, built from the key comparison | |
1147 | * object out of which the %map was constructed. | |
1148 | */ | |
1149 | value_compare | |
1150 | value_comp() const | |
1151 | { return value_compare(_M_t.key_comp()); } | |
ed6814f7 | 1152 | |
f6592a9e | 1153 | // [23.3.1.3] map operations |
91c78ea5 JW |
1154 | |
1155 | //@{ | |
f6592a9e PC |
1156 | /** |
1157 | * @brief Tries to locate an element in a %map. | |
93c66bc6 | 1158 | * @param __x Key of (key, value) %pair to be located. |
f6592a9e PC |
1159 | * @return Iterator pointing to sought-after element, or end() if not |
1160 | * found. | |
1161 | * | |
1162 | * This function takes a key and tries to locate the element with which | |
1163 | * the key matches. If successful the function returns an iterator | |
1164 | * pointing to the sought after %pair. If unsuccessful it returns the | |
1165 | * past-the-end ( @c end() ) iterator. | |
1166 | */ | |
91c78ea5 | 1167 | |
f6592a9e PC |
1168 | iterator |
1169 | find(const key_type& __x) | |
1170 | { return _M_t.find(__x); } | |
ed6814f7 | 1171 | |
91c78ea5 JW |
1172 | #if __cplusplus > 201103L |
1173 | template<typename _Kt> | |
1174 | auto | |
1175 | find(const _Kt& __x) -> decltype(_M_t._M_find_tr(__x)) | |
1176 | { return _M_t._M_find_tr(__x); } | |
1177 | #endif | |
1178 | //@} | |
1179 | ||
1180 | //@{ | |
f6592a9e PC |
1181 | /** |
1182 | * @brief Tries to locate an element in a %map. | |
93c66bc6 | 1183 | * @param __x Key of (key, value) %pair to be located. |
f6592a9e PC |
1184 | * @return Read-only (constant) iterator pointing to sought-after |
1185 | * element, or end() if not found. | |
1186 | * | |
1187 | * This function takes a key and tries to locate the element with which | |
1188 | * the key matches. If successful the function returns a constant | |
1189 | * iterator pointing to the sought after %pair. If unsuccessful it | |
1190 | * returns the past-the-end ( @c end() ) iterator. | |
1191 | */ | |
91c78ea5 | 1192 | |
f6592a9e PC |
1193 | const_iterator |
1194 | find(const key_type& __x) const | |
1195 | { return _M_t.find(__x); } | |
ed6814f7 | 1196 | |
91c78ea5 JW |
1197 | #if __cplusplus > 201103L |
1198 | template<typename _Kt> | |
1199 | auto | |
1200 | find(const _Kt& __x) const -> decltype(_M_t._M_find_tr(__x)) | |
1201 | { return _M_t._M_find_tr(__x); } | |
1202 | #endif | |
1203 | //@} | |
1204 | ||
1205 | //@{ | |
f6592a9e PC |
1206 | /** |
1207 | * @brief Finds the number of elements with given key. | |
93c66bc6 | 1208 | * @param __x Key of (key, value) pairs to be located. |
f6592a9e PC |
1209 | * @return Number of elements with specified key. |
1210 | * | |
1211 | * This function only makes sense for multimaps; for map the result will | |
1212 | * either be 0 (not present) or 1 (present). | |
1213 | */ | |
1214 | size_type | |
1215 | count(const key_type& __x) const | |
1216 | { return _M_t.find(__x) == _M_t.end() ? 0 : 1; } | |
ed6814f7 | 1217 | |
91c78ea5 JW |
1218 | #if __cplusplus > 201103L |
1219 | template<typename _Kt> | |
1220 | auto | |
1221 | count(const _Kt& __x) const -> decltype(_M_t._M_count_tr(__x)) | |
b091b8dc | 1222 | { return _M_t._M_count_tr(__x); } |
91c78ea5 JW |
1223 | #endif |
1224 | //@} | |
1225 | ||
1226 | //@{ | |
f6592a9e PC |
1227 | /** |
1228 | * @brief Finds the beginning of a subsequence matching given key. | |
93c66bc6 | 1229 | * @param __x Key of (key, value) pair to be located. |
f6592a9e PC |
1230 | * @return Iterator pointing to first element equal to or greater |
1231 | * than key, or end(). | |
1232 | * | |
1233 | * This function returns the first element of a subsequence of elements | |
1234 | * that matches the given key. If unsuccessful it returns an iterator | |
1235 | * pointing to the first element that has a greater value than given key | |
1236 | * or end() if no such element exists. | |
1237 | */ | |
1238 | iterator | |
1239 | lower_bound(const key_type& __x) | |
1240 | { return _M_t.lower_bound(__x); } | |
ed6814f7 | 1241 | |
91c78ea5 JW |
1242 | #if __cplusplus > 201103L |
1243 | template<typename _Kt> | |
1244 | auto | |
1245 | lower_bound(const _Kt& __x) | |
b744bf4e JW |
1246 | -> decltype(iterator(_M_t._M_lower_bound_tr(__x))) |
1247 | { return iterator(_M_t._M_lower_bound_tr(__x)); } | |
91c78ea5 JW |
1248 | #endif |
1249 | //@} | |
1250 | ||
1251 | //@{ | |
f6592a9e PC |
1252 | /** |
1253 | * @brief Finds the beginning of a subsequence matching given key. | |
93c66bc6 | 1254 | * @param __x Key of (key, value) pair to be located. |
f6592a9e PC |
1255 | * @return Read-only (constant) iterator pointing to first element |
1256 | * equal to or greater than key, or end(). | |
1257 | * | |
1258 | * This function returns the first element of a subsequence of elements | |
1259 | * that matches the given key. If unsuccessful it returns an iterator | |
1260 | * pointing to the first element that has a greater value than given key | |
1261 | * or end() if no such element exists. | |
1262 | */ | |
1263 | const_iterator | |
1264 | lower_bound(const key_type& __x) const | |
1265 | { return _M_t.lower_bound(__x); } | |
ed6814f7 | 1266 | |
91c78ea5 JW |
1267 | #if __cplusplus > 201103L |
1268 | template<typename _Kt> | |
1269 | auto | |
1270 | lower_bound(const _Kt& __x) const | |
b744bf4e JW |
1271 | -> decltype(const_iterator(_M_t._M_lower_bound_tr(__x))) |
1272 | { return const_iterator(_M_t._M_lower_bound_tr(__x)); } | |
91c78ea5 JW |
1273 | #endif |
1274 | //@} | |
1275 | ||
1276 | //@{ | |
f6592a9e PC |
1277 | /** |
1278 | * @brief Finds the end of a subsequence matching given key. | |
93c66bc6 | 1279 | * @param __x Key of (key, value) pair to be located. |
f6592a9e PC |
1280 | * @return Iterator pointing to the first element |
1281 | * greater than key, or end(). | |
1282 | */ | |
1283 | iterator | |
1284 | upper_bound(const key_type& __x) | |
1285 | { return _M_t.upper_bound(__x); } | |
ed6814f7 | 1286 | |
91c78ea5 JW |
1287 | #if __cplusplus > 201103L |
1288 | template<typename _Kt> | |
1289 | auto | |
1290 | upper_bound(const _Kt& __x) | |
b744bf4e JW |
1291 | -> decltype(iterator(_M_t._M_upper_bound_tr(__x))) |
1292 | { return iterator(_M_t._M_upper_bound_tr(__x)); } | |
91c78ea5 JW |
1293 | #endif |
1294 | //@} | |
1295 | ||
1296 | //@{ | |
f6592a9e PC |
1297 | /** |
1298 | * @brief Finds the end of a subsequence matching given key. | |
93c66bc6 | 1299 | * @param __x Key of (key, value) pair to be located. |
f6592a9e PC |
1300 | * @return Read-only (constant) iterator pointing to first iterator |
1301 | * greater than key, or end(). | |
1302 | */ | |
1303 | const_iterator | |
1304 | upper_bound(const key_type& __x) const | |
1305 | { return _M_t.upper_bound(__x); } | |
ed6814f7 | 1306 | |
91c78ea5 JW |
1307 | #if __cplusplus > 201103L |
1308 | template<typename _Kt> | |
1309 | auto | |
1310 | upper_bound(const _Kt& __x) const | |
b744bf4e JW |
1311 | -> decltype(const_iterator(_M_t._M_upper_bound_tr(__x))) |
1312 | { return const_iterator(_M_t._M_upper_bound_tr(__x)); } | |
91c78ea5 JW |
1313 | #endif |
1314 | //@} | |
1315 | ||
1316 | //@{ | |
f6592a9e PC |
1317 | /** |
1318 | * @brief Finds a subsequence matching given key. | |
93c66bc6 | 1319 | * @param __x Key of (key, value) pairs to be located. |
f6592a9e PC |
1320 | * @return Pair of iterators that possibly points to the subsequence |
1321 | * matching given key. | |
1322 | * | |
1323 | * This function is equivalent to | |
1324 | * @code | |
1325 | * std::make_pair(c.lower_bound(val), | |
1326 | * c.upper_bound(val)) | |
1327 | * @endcode | |
1328 | * (but is faster than making the calls separately). | |
1329 | * | |
1330 | * This function probably only makes sense for multimaps. | |
1331 | */ | |
4fd20a8f | 1332 | std::pair<iterator, iterator> |
f6592a9e PC |
1333 | equal_range(const key_type& __x) |
1334 | { return _M_t.equal_range(__x); } | |
ed6814f7 | 1335 | |
91c78ea5 JW |
1336 | #if __cplusplus > 201103L |
1337 | template<typename _Kt> | |
1338 | auto | |
1339 | equal_range(const _Kt& __x) | |
b744bf4e JW |
1340 | -> decltype(pair<iterator, iterator>(_M_t._M_equal_range_tr(__x))) |
1341 | { return pair<iterator, iterator>(_M_t._M_equal_range_tr(__x)); } | |
91c78ea5 JW |
1342 | #endif |
1343 | //@} | |
1344 | ||
1345 | //@{ | |
f6592a9e PC |
1346 | /** |
1347 | * @brief Finds a subsequence matching given key. | |
93c66bc6 | 1348 | * @param __x Key of (key, value) pairs to be located. |
f6592a9e PC |
1349 | * @return Pair of read-only (constant) iterators that possibly points |
1350 | * to the subsequence matching given key. | |
1351 | * | |
1352 | * This function is equivalent to | |
1353 | * @code | |
1354 | * std::make_pair(c.lower_bound(val), | |
1355 | * c.upper_bound(val)) | |
1356 | * @endcode | |
1357 | * (but is faster than making the calls separately). | |
1358 | * | |
1359 | * This function probably only makes sense for multimaps. | |
1360 | */ | |
4fd20a8f | 1361 | std::pair<const_iterator, const_iterator> |
f6592a9e PC |
1362 | equal_range(const key_type& __x) const |
1363 | { return _M_t.equal_range(__x); } | |
ed6814f7 | 1364 | |
91c78ea5 JW |
1365 | #if __cplusplus > 201103L |
1366 | template<typename _Kt> | |
1367 | auto | |
1368 | equal_range(const _Kt& __x) const | |
b744bf4e JW |
1369 | -> decltype(pair<const_iterator, const_iterator>( |
1370 | _M_t._M_equal_range_tr(__x))) | |
1371 | { | |
1372 | return pair<const_iterator, const_iterator>( | |
1373 | _M_t._M_equal_range_tr(__x)); | |
1374 | } | |
91c78ea5 JW |
1375 | #endif |
1376 | //@} | |
1377 | ||
78b36b70 | 1378 | template<typename _K1, typename _T1, typename _C1, typename _A1> |
fe62dd04 FD |
1379 | friend bool |
1380 | operator==(const map<_K1, _T1, _C1, _A1>&, | |
78b36b70 | 1381 | const map<_K1, _T1, _C1, _A1>&); |
737ab798 | 1382 | |
78b36b70 | 1383 | template<typename _K1, typename _T1, typename _C1, typename _A1> |
fe62dd04 FD |
1384 | friend bool |
1385 | operator<(const map<_K1, _T1, _C1, _A1>&, | |
78b36b70 | 1386 | const map<_K1, _T1, _C1, _A1>&); |
f6592a9e | 1387 | }; |
ed6814f7 | 1388 | |
957f5fea VV |
1389 | |
1390 | #if __cpp_deduction_guides >= 201606 | |
1391 | ||
1392 | template<typename _InputIterator, | |
1393 | typename _Compare = less<__iter_key_t<_InputIterator>>, | |
1394 | typename _Allocator = allocator<__iter_to_alloc_t<_InputIterator>>, | |
1395 | typename = _RequireInputIter<_InputIterator>, | |
1396 | typename = _RequireAllocator<_Allocator>> | |
1397 | map(_InputIterator, _InputIterator, | |
1398 | _Compare = _Compare(), _Allocator = _Allocator()) | |
1399 | -> map<__iter_key_t<_InputIterator>, __iter_val_t<_InputIterator>, | |
1400 | _Compare, _Allocator>; | |
1401 | ||
1402 | template<typename _Key, typename _Tp, typename _Compare = less<_Key>, | |
1403 | typename _Allocator = allocator<pair<const _Key, _Tp>>, | |
1404 | typename = _RequireAllocator<_Allocator>> | |
1405 | map(initializer_list<pair<_Key, _Tp>>, | |
1406 | _Compare = _Compare(), _Allocator = _Allocator()) | |
1407 | -> map<_Key, _Tp, _Compare, _Allocator>; | |
1408 | ||
1409 | template <typename _InputIterator, typename _Allocator, | |
1410 | typename = _RequireInputIter<_InputIterator>, | |
1411 | typename = _RequireAllocator<_Allocator>> | |
1412 | map(_InputIterator, _InputIterator, _Allocator) | |
1413 | -> map<__iter_key_t<_InputIterator>, __iter_val_t<_InputIterator>, | |
1414 | less<__iter_key_t<_InputIterator>>, _Allocator>; | |
1415 | ||
1416 | template<typename _Key, typename _Tp, typename _Allocator, | |
1417 | typename = _RequireAllocator<_Allocator>> | |
1418 | map(initializer_list<pair<_Key, _Tp>>, _Allocator) | |
1419 | -> map<_Key, _Tp, less<_Key>, _Allocator>; | |
1420 | ||
1421 | #endif | |
1422 | ||
3971a4d2 PE |
1423 | /** |
1424 | * @brief Map equality comparison. | |
93c66bc6 BK |
1425 | * @param __x A %map. |
1426 | * @param __y A %map of the same type as @a x. | |
3971a4d2 | 1427 | * @return True iff the size and elements of the maps are equal. |
fd58f127 | 1428 | * |
3971a4d2 PE |
1429 | * This is an equivalence relation. It is linear in the size of the |
1430 | * maps. Maps are considered equivalent if their sizes are equal, | |
1431 | * and if corresponding elements compare equal. | |
1432 | */ | |
78b36b70 | 1433 | template<typename _Key, typename _Tp, typename _Compare, typename _Alloc> |
3971a4d2 | 1434 | inline bool |
4fd20a8f | 1435 | operator==(const map<_Key, _Tp, _Compare, _Alloc>& __x, |
fe62dd04 | 1436 | const map<_Key, _Tp, _Compare, _Alloc>& __y) |
3971a4d2 | 1437 | { return __x._M_t == __y._M_t; } |
ed6814f7 | 1438 | |
3971a4d2 PE |
1439 | /** |
1440 | * @brief Map ordering relation. | |
93c66bc6 BK |
1441 | * @param __x A %map. |
1442 | * @param __y A %map of the same type as @a x. | |
9536ca34 | 1443 | * @return True iff @a x is lexicographically less than @a y. |
fd58f127 | 1444 | * |
3971a4d2 PE |
1445 | * This is a total ordering relation. It is linear in the size of the |
1446 | * maps. The elements must be comparable with @c <. | |
fd58f127 | 1447 | * |
9536ca34 | 1448 | * See std::lexicographical_compare() for how the determination is made. |
3971a4d2 | 1449 | */ |
78b36b70 | 1450 | template<typename _Key, typename _Tp, typename _Compare, typename _Alloc> |
3971a4d2 | 1451 | inline bool |
4fd20a8f | 1452 | operator<(const map<_Key, _Tp, _Compare, _Alloc>& __x, |
fe62dd04 | 1453 | const map<_Key, _Tp, _Compare, _Alloc>& __y) |
3971a4d2 | 1454 | { return __x._M_t < __y._M_t; } |
ed6814f7 | 1455 | |
3971a4d2 | 1456 | /// Based on operator== |
78b36b70 | 1457 | template<typename _Key, typename _Tp, typename _Compare, typename _Alloc> |
3971a4d2 | 1458 | inline bool |
4fd20a8f | 1459 | operator!=(const map<_Key, _Tp, _Compare, _Alloc>& __x, |
fe62dd04 | 1460 | const map<_Key, _Tp, _Compare, _Alloc>& __y) |
3971a4d2 | 1461 | { return !(__x == __y); } |
ed6814f7 | 1462 | |
3971a4d2 | 1463 | /// Based on operator< |
78b36b70 | 1464 | template<typename _Key, typename _Tp, typename _Compare, typename _Alloc> |
3971a4d2 | 1465 | inline bool |
4fd20a8f | 1466 | operator>(const map<_Key, _Tp, _Compare, _Alloc>& __x, |
fe62dd04 | 1467 | const map<_Key, _Tp, _Compare, _Alloc>& __y) |
3971a4d2 | 1468 | { return __y < __x; } |
ed6814f7 | 1469 | |
3971a4d2 | 1470 | /// Based on operator< |
78b36b70 | 1471 | template<typename _Key, typename _Tp, typename _Compare, typename _Alloc> |
3971a4d2 | 1472 | inline bool |
4fd20a8f | 1473 | operator<=(const map<_Key, _Tp, _Compare, _Alloc>& __x, |
fe62dd04 | 1474 | const map<_Key, _Tp, _Compare, _Alloc>& __y) |
3971a4d2 | 1475 | { return !(__y < __x); } |
ed6814f7 | 1476 | |
3971a4d2 | 1477 | /// Based on operator< |
78b36b70 | 1478 | template<typename _Key, typename _Tp, typename _Compare, typename _Alloc> |
3971a4d2 | 1479 | inline bool |
4fd20a8f | 1480 | operator>=(const map<_Key, _Tp, _Compare, _Alloc>& __x, |
fe62dd04 | 1481 | const map<_Key, _Tp, _Compare, _Alloc>& __y) |
3971a4d2 | 1482 | { return !(__x < __y); } |
ed6814f7 | 1483 | |
3971a4d2 | 1484 | /// See std::map::swap(). |
78b36b70 | 1485 | template<typename _Key, typename _Tp, typename _Compare, typename _Alloc> |
3971a4d2 | 1486 | inline void |
4fd20a8f PC |
1487 | swap(map<_Key, _Tp, _Compare, _Alloc>& __x, |
1488 | map<_Key, _Tp, _Compare, _Alloc>& __y) | |
c5d9ec56 | 1489 | _GLIBCXX_NOEXCEPT_IF(noexcept(__x.swap(__y))) |
3971a4d2 | 1490 | { __x.swap(__y); } |
3cbc7af0 | 1491 | |
12ffa228 | 1492 | _GLIBCXX_END_NAMESPACE_CONTAINER |
2dbe56bd JW |
1493 | |
1494 | #if __cplusplus > 201402L | |
2dbe56bd JW |
1495 | // Allow std::map access to internals of compatible maps. |
1496 | template<typename _Key, typename _Val, typename _Cmp1, typename _Alloc, | |
1497 | typename _Cmp2> | |
1498 | struct | |
1499 | _Rb_tree_merge_helper<_GLIBCXX_STD_C::map<_Key, _Val, _Cmp1, _Alloc>, | |
1500 | _Cmp2> | |
1501 | { | |
1502 | private: | |
1503 | friend class _GLIBCXX_STD_C::map<_Key, _Val, _Cmp1, _Alloc>; | |
1504 | ||
1505 | static auto& | |
1506 | _S_get_tree(_GLIBCXX_STD_C::map<_Key, _Val, _Cmp2, _Alloc>& __map) | |
1507 | { return __map._M_t; } | |
1508 | ||
1509 | static auto& | |
1510 | _S_get_tree(_GLIBCXX_STD_C::multimap<_Key, _Val, _Cmp2, _Alloc>& __map) | |
1511 | { return __map._M_t; } | |
1512 | }; | |
2dbe56bd JW |
1513 | #endif // C++17 |
1514 | ||
4a15d842 | 1515 | _GLIBCXX_END_NAMESPACE_VERSION |
12ffa228 | 1516 | } // namespace std |
725dc051 | 1517 | |
046d30f4 | 1518 | #endif /* _STL_MAP_H */ |