blob: 0da590fd71148dc140345783ff98c8f74ea15945 [file] [log] [blame]
Howard Hinnantc51e1022010-05-11 19:42:16 +00001// -*- C++ -*-
2//===----------------------------- map ------------------------------------===//
3//
Chandler Carruthd2012102019-01-19 10:56:40 +00004// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5// See https://llvm.org/LICENSE.txt for license information.
6// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
Howard Hinnantc51e1022010-05-11 19:42:16 +00007//
8//===----------------------------------------------------------------------===//
9
10#ifndef _LIBCPP_MAP
11#define _LIBCPP_MAP
12
13/*
14
15 map synopsis
16
17namespace std
18{
19
20template <class Key, class T, class Compare = less<Key>,
21 class Allocator = allocator<pair<const Key, T>>>
22class map
23{
24public:
25 // types:
26 typedef Key key_type;
27 typedef T mapped_type;
28 typedef pair<const key_type, mapped_type> value_type;
29 typedef Compare key_compare;
30 typedef Allocator allocator_type;
31 typedef typename allocator_type::reference reference;
32 typedef typename allocator_type::const_reference const_reference;
33 typedef typename allocator_type::pointer pointer;
34 typedef typename allocator_type::const_pointer const_pointer;
35 typedef typename allocator_type::size_type size_type;
36 typedef typename allocator_type::difference_type difference_type;
37
38 typedef implementation-defined iterator;
39 typedef implementation-defined const_iterator;
40 typedef std::reverse_iterator<iterator> reverse_iterator;
41 typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
Erik Pilkingtonc37a3d82018-08-01 01:33:38 +000042 typedef unspecified node_type; // C++17
43 typedef INSERT_RETURN_TYPE<iterator, node_type> insert_return_type; // C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +000044
45 class value_compare
Howard Hinnantc51e1022010-05-11 19:42:16 +000046 {
47 friend class map;
48 protected:
49 key_compare comp;
50
51 value_compare(key_compare c);
52 public:
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -040053 typedef bool result_type; // deprecated in C++17, removed in C++20
54 typedef value_type first_argument_type; // deprecated in C++17, removed in C++20
55 typedef value_type second_argument_type; // deprecated in C++17, removed in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +000056 bool operator()(const value_type& x, const value_type& y) const;
57 };
58
59 // construct/copy/destroy:
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +000060 map()
61 noexcept(
62 is_nothrow_default_constructible<allocator_type>::value &&
63 is_nothrow_default_constructible<key_compare>::value &&
64 is_nothrow_copy_constructible<key_compare>::value);
Howard Hinnantc51e1022010-05-11 19:42:16 +000065 explicit map(const key_compare& comp);
66 map(const key_compare& comp, const allocator_type& a);
67 template <class InputIterator>
68 map(InputIterator first, InputIterator last,
69 const key_compare& comp = key_compare());
70 template <class InputIterator>
71 map(InputIterator first, InputIterator last,
72 const key_compare& comp, const allocator_type& a);
73 map(const map& m);
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +000074 map(map&& m)
75 noexcept(
76 is_nothrow_move_constructible<allocator_type>::value &&
77 is_nothrow_move_constructible<key_compare>::value);
Howard Hinnantc51e1022010-05-11 19:42:16 +000078 explicit map(const allocator_type& a);
79 map(const map& m, const allocator_type& a);
80 map(map&& m, const allocator_type& a);
81 map(initializer_list<value_type> il, const key_compare& comp = key_compare());
82 map(initializer_list<value_type> il, const key_compare& comp, const allocator_type& a);
Marshall Clow300abfb2013-09-11 01:15:47 +000083 template <class InputIterator>
84 map(InputIterator first, InputIterator last, const allocator_type& a)
85 : map(first, last, Compare(), a) {} // C++14
86 map(initializer_list<value_type> il, const allocator_type& a)
87 : map(il, Compare(), a) {} // C++14
88 ~map();
Howard Hinnantc51e1022010-05-11 19:42:16 +000089
90 map& operator=(const map& m);
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +000091 map& operator=(map&& m)
92 noexcept(
93 allocator_type::propagate_on_container_move_assignment::value &&
94 is_nothrow_move_assignable<allocator_type>::value &&
Howard Hinnantf95f4f52011-06-04 15:22:34 +000095 is_nothrow_move_assignable<key_compare>::value);
Howard Hinnantc51e1022010-05-11 19:42:16 +000096 map& operator=(initializer_list<value_type> il);
97
98 // iterators:
Howard Hinnantf95f4f52011-06-04 15:22:34 +000099 iterator begin() noexcept;
100 const_iterator begin() const noexcept;
101 iterator end() noexcept;
102 const_iterator end() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000103
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000104 reverse_iterator rbegin() noexcept;
105 const_reverse_iterator rbegin() const noexcept;
106 reverse_iterator rend() noexcept;
107 const_reverse_iterator rend() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000108
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000109 const_iterator cbegin() const noexcept;
110 const_iterator cend() const noexcept;
111 const_reverse_iterator crbegin() const noexcept;
112 const_reverse_iterator crend() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000113
114 // capacity:
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000115 bool empty() const noexcept;
116 size_type size() const noexcept;
117 size_type max_size() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000118
119 // element access:
120 mapped_type& operator[](const key_type& k);
121 mapped_type& operator[](key_type&& k);
122
123 mapped_type& at(const key_type& k);
124 const mapped_type& at(const key_type& k) const;
125
126 // modifiers:
127 template <class... Args>
128 pair<iterator, bool> emplace(Args&&... args);
129 template <class... Args>
130 iterator emplace_hint(const_iterator position, Args&&... args);
131 pair<iterator, bool> insert(const value_type& v);
Marshall Clowd430d022016-01-05 19:32:41 +0000132 pair<iterator, bool> insert( value_type&& v); // C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000133 template <class P>
134 pair<iterator, bool> insert(P&& p);
135 iterator insert(const_iterator position, const value_type& v);
Marshall Clowd430d022016-01-05 19:32:41 +0000136 iterator insert(const_iterator position, value_type&& v); // C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000137 template <class P>
138 iterator insert(const_iterator position, P&& p);
139 template <class InputIterator>
140 void insert(InputIterator first, InputIterator last);
141 void insert(initializer_list<value_type> il);
142
Erik Pilkingtonc37a3d82018-08-01 01:33:38 +0000143 node_type extract(const_iterator position); // C++17
144 node_type extract(const key_type& x); // C++17
145 insert_return_type insert(node_type&& nh); // C++17
146 iterator insert(const_iterator hint, node_type&& nh); // C++17
147
Marshall Clow3223db82015-07-07 03:37:33 +0000148 template <class... Args>
149 pair<iterator, bool> try_emplace(const key_type& k, Args&&... args); // C++17
150 template <class... Args>
151 pair<iterator, bool> try_emplace(key_type&& k, Args&&... args); // C++17
152 template <class... Args>
153 iterator try_emplace(const_iterator hint, const key_type& k, Args&&... args); // C++17
154 template <class... Args>
155 iterator try_emplace(const_iterator hint, key_type&& k, Args&&... args); // C++17
156 template <class M>
157 pair<iterator, bool> insert_or_assign(const key_type& k, M&& obj); // C++17
158 template <class M>
159 pair<iterator, bool> insert_or_assign(key_type&& k, M&& obj); // C++17
160 template <class M>
161 iterator insert_or_assign(const_iterator hint, const key_type& k, M&& obj); // C++17
162 template <class M>
163 iterator insert_or_assign(const_iterator hint, key_type&& k, M&& obj); // C++17
164
Howard Hinnantc51e1022010-05-11 19:42:16 +0000165 iterator erase(const_iterator position);
Marshall Clow22ea5b82015-05-10 13:35:00 +0000166 iterator erase(iterator position); // C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000167 size_type erase(const key_type& k);
168 iterator erase(const_iterator first, const_iterator last);
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000169 void clear() noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000170
Erik Pilkington82a65ad2018-10-31 17:31:35 +0000171 template<class C2>
172 void merge(map<Key, T, C2, Allocator>& source); // C++17
173 template<class C2>
174 void merge(map<Key, T, C2, Allocator>&& source); // C++17
175 template<class C2>
176 void merge(multimap<Key, T, C2, Allocator>& source); // C++17
177 template<class C2>
178 void merge(multimap<Key, T, C2, Allocator>&& source); // C++17
179
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000180 void swap(map& m)
Marshall Clow8982dcd2015-07-13 20:04:56 +0000181 noexcept(allocator_traits<allocator_type>::is_always_equal::value &&
Eric Fiselier6bfed252016-04-21 23:38:59 +0000182 is_nothrow_swappable<key_compare>::value); // C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000183
184 // observers:
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000185 allocator_type get_allocator() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000186 key_compare key_comp() const;
187 value_compare value_comp() const;
188
189 // map operations:
190 iterator find(const key_type& k);
191 const_iterator find(const key_type& k) const;
Marshall Clowebb57322013-08-13 22:18:47 +0000192 template<typename K>
193 iterator find(const K& x); // C++14
194 template<typename K>
195 const_iterator find(const K& x) const; // C++14
Marek Kurdejd7e019e2021-04-13 17:10:55 +0200196
Marshall Clowebb57322013-08-13 22:18:47 +0000197 template<typename K>
Marshall Clowe6a5f522014-08-24 23:54:16 +0000198 size_type count(const K& x) const; // C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000199 size_type count(const key_type& k) const;
Marek Kurdejd7e019e2021-04-13 17:10:55 +0200200
201 bool contains(const key_type& x) const; // C++20
202 template<class K> bool contains(const K& x) const; // C++20
203
Howard Hinnantc51e1022010-05-11 19:42:16 +0000204 iterator lower_bound(const key_type& k);
205 const_iterator lower_bound(const key_type& k) const;
Marshall Clowebb57322013-08-13 22:18:47 +0000206 template<typename K>
207 iterator lower_bound(const K& x); // C++14
208 template<typename K>
209 const_iterator lower_bound(const K& x) const; // C++14
210
Howard Hinnantc51e1022010-05-11 19:42:16 +0000211 iterator upper_bound(const key_type& k);
212 const_iterator upper_bound(const key_type& k) const;
Marshall Clowebb57322013-08-13 22:18:47 +0000213 template<typename K>
214 iterator upper_bound(const K& x); // C++14
215 template<typename K>
216 const_iterator upper_bound(const K& x) const; // C++14
217
Howard Hinnantc51e1022010-05-11 19:42:16 +0000218 pair<iterator,iterator> equal_range(const key_type& k);
219 pair<const_iterator,const_iterator> equal_range(const key_type& k) const;
Marshall Clowebb57322013-08-13 22:18:47 +0000220 template<typename K>
221 pair<iterator,iterator> equal_range(const K& x); // C++14
222 template<typename K>
223 pair<const_iterator,const_iterator> equal_range(const K& x) const; // C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000224};
225
226template <class Key, class T, class Compare, class Allocator>
227bool
228operator==(const map<Key, T, Compare, Allocator>& x,
229 const map<Key, T, Compare, Allocator>& y);
230
231template <class Key, class T, class Compare, class Allocator>
232bool
233operator< (const map<Key, T, Compare, Allocator>& x,
234 const map<Key, T, Compare, Allocator>& y);
235
236template <class Key, class T, class Compare, class Allocator>
237bool
238operator!=(const map<Key, T, Compare, Allocator>& x,
239 const map<Key, T, Compare, Allocator>& y);
240
241template <class Key, class T, class Compare, class Allocator>
242bool
243operator> (const map<Key, T, Compare, Allocator>& x,
244 const map<Key, T, Compare, Allocator>& y);
245
246template <class Key, class T, class Compare, class Allocator>
247bool
248operator>=(const map<Key, T, Compare, Allocator>& x,
249 const map<Key, T, Compare, Allocator>& y);
250
251template <class Key, class T, class Compare, class Allocator>
252bool
253operator<=(const map<Key, T, Compare, Allocator>& x,
254 const map<Key, T, Compare, Allocator>& y);
255
256// specialized algorithms:
257template <class Key, class T, class Compare, class Allocator>
258void
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000259swap(map<Key, T, Compare, Allocator>& x, map<Key, T, Compare, Allocator>& y)
260 noexcept(noexcept(x.swap(y)));
Howard Hinnantc51e1022010-05-11 19:42:16 +0000261
Marshall Clow29b53f22018-12-14 18:49:35 +0000262template <class Key, class T, class Compare, class Allocator, class Predicate>
Marek Kurdeja98b1412020-05-02 13:58:03 +0200263typename map<Key, T, Compare, Allocator>::size_type
264erase_if(map<Key, T, Compare, Allocator>& c, Predicate pred); // C++20
Marshall Clow29b53f22018-12-14 18:49:35 +0000265
266
Howard Hinnantc51e1022010-05-11 19:42:16 +0000267template <class Key, class T, class Compare = less<Key>,
268 class Allocator = allocator<pair<const Key, T>>>
269class multimap
270{
271public:
272 // types:
273 typedef Key key_type;
274 typedef T mapped_type;
275 typedef pair<const key_type,mapped_type> value_type;
276 typedef Compare key_compare;
277 typedef Allocator allocator_type;
278 typedef typename allocator_type::reference reference;
279 typedef typename allocator_type::const_reference const_reference;
280 typedef typename allocator_type::size_type size_type;
281 typedef typename allocator_type::difference_type difference_type;
282 typedef typename allocator_type::pointer pointer;
283 typedef typename allocator_type::const_pointer const_pointer;
284
285 typedef implementation-defined iterator;
286 typedef implementation-defined const_iterator;
287 typedef std::reverse_iterator<iterator> reverse_iterator;
288 typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
Erik Pilkingtonc37a3d82018-08-01 01:33:38 +0000289 typedef unspecified node_type; // C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000290
291 class value_compare
Howard Hinnantc51e1022010-05-11 19:42:16 +0000292 {
293 friend class multimap;
294 protected:
295 key_compare comp;
296 value_compare(key_compare c);
297 public:
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400298 typedef bool result_type; // deprecated in C++17, removed in C++20
299 typedef value_type first_argument_type; // deprecated in C++17, removed in C++20
300 typedef value_type second_argument_type; // deprecated in C++17, removed in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000301 bool operator()(const value_type& x, const value_type& y) const;
302 };
303
304 // construct/copy/destroy:
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000305 multimap()
306 noexcept(
307 is_nothrow_default_constructible<allocator_type>::value &&
308 is_nothrow_default_constructible<key_compare>::value &&
309 is_nothrow_copy_constructible<key_compare>::value);
310 explicit multimap(const key_compare& comp);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000311 multimap(const key_compare& comp, const allocator_type& a);
312 template <class InputIterator>
313 multimap(InputIterator first, InputIterator last, const key_compare& comp);
314 template <class InputIterator>
315 multimap(InputIterator first, InputIterator last, const key_compare& comp,
316 const allocator_type& a);
317 multimap(const multimap& m);
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000318 multimap(multimap&& m)
319 noexcept(
320 is_nothrow_move_constructible<allocator_type>::value &&
321 is_nothrow_move_constructible<key_compare>::value);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000322 explicit multimap(const allocator_type& a);
323 multimap(const multimap& m, const allocator_type& a);
324 multimap(multimap&& m, const allocator_type& a);
325 multimap(initializer_list<value_type> il, const key_compare& comp = key_compare());
326 multimap(initializer_list<value_type> il, const key_compare& comp,
327 const allocator_type& a);
Marshall Clow300abfb2013-09-11 01:15:47 +0000328 template <class InputIterator>
329 multimap(InputIterator first, InputIterator last, const allocator_type& a)
330 : multimap(first, last, Compare(), a) {} // C++14
331 multimap(initializer_list<value_type> il, const allocator_type& a)
332 : multimap(il, Compare(), a) {} // C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000333 ~multimap();
334
335 multimap& operator=(const multimap& m);
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000336 multimap& operator=(multimap&& m)
337 noexcept(
338 allocator_type::propagate_on_container_move_assignment::value &&
339 is_nothrow_move_assignable<allocator_type>::value &&
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000340 is_nothrow_move_assignable<key_compare>::value);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000341 multimap& operator=(initializer_list<value_type> il);
342
343 // iterators:
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000344 iterator begin() noexcept;
345 const_iterator begin() const noexcept;
346 iterator end() noexcept;
347 const_iterator end() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000348
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000349 reverse_iterator rbegin() noexcept;
350 const_reverse_iterator rbegin() const noexcept;
351 reverse_iterator rend() noexcept;
352 const_reverse_iterator rend() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000353
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000354 const_iterator cbegin() const noexcept;
355 const_iterator cend() const noexcept;
356 const_reverse_iterator crbegin() const noexcept;
357 const_reverse_iterator crend() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000358
359 // capacity:
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000360 bool empty() const noexcept;
361 size_type size() const noexcept;
362 size_type max_size() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000363
364 // modifiers:
365 template <class... Args>
366 iterator emplace(Args&&... args);
367 template <class... Args>
368 iterator emplace_hint(const_iterator position, Args&&... args);
369 iterator insert(const value_type& v);
Marshall Clowd430d022016-01-05 19:32:41 +0000370 iterator insert( value_type&& v); // C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000371 template <class P>
372 iterator insert(P&& p);
373 iterator insert(const_iterator position, const value_type& v);
Marshall Clowd430d022016-01-05 19:32:41 +0000374 iterator insert(const_iterator position, value_type&& v); // C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000375 template <class P>
376 iterator insert(const_iterator position, P&& p);
377 template <class InputIterator>
378 void insert(InputIterator first, InputIterator last);
379 void insert(initializer_list<value_type> il);
380
Erik Pilkingtonc37a3d82018-08-01 01:33:38 +0000381 node_type extract(const_iterator position); // C++17
382 node_type extract(const key_type& x); // C++17
383 iterator insert(node_type&& nh); // C++17
384 iterator insert(const_iterator hint, node_type&& nh); // C++17
385
Howard Hinnantc51e1022010-05-11 19:42:16 +0000386 iterator erase(const_iterator position);
Marshall Clow22ea5b82015-05-10 13:35:00 +0000387 iterator erase(iterator position); // C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000388 size_type erase(const key_type& k);
389 iterator erase(const_iterator first, const_iterator last);
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000390 void clear() noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000391
Erik Pilkington82a65ad2018-10-31 17:31:35 +0000392 template<class C2>
393 void merge(multimap<Key, T, C2, Allocator>& source); // C++17
394 template<class C2>
395 void merge(multimap<Key, T, C2, Allocator>&& source); // C++17
396 template<class C2>
397 void merge(map<Key, T, C2, Allocator>& source); // C++17
398 template<class C2>
399 void merge(map<Key, T, C2, Allocator>&& source); // C++17
400
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000401 void swap(multimap& m)
Marshall Clow8982dcd2015-07-13 20:04:56 +0000402 noexcept(allocator_traits<allocator_type>::is_always_equal::value &&
Eric Fiselier6bfed252016-04-21 23:38:59 +0000403 is_nothrow_swappable<key_compare>::value); // C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000404
405 // observers:
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000406 allocator_type get_allocator() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000407 key_compare key_comp() const;
408 value_compare value_comp() const;
409
410 // map operations:
411 iterator find(const key_type& k);
412 const_iterator find(const key_type& k) const;
Marshall Clowebb57322013-08-13 22:18:47 +0000413 template<typename K>
414 iterator find(const K& x); // C++14
415 template<typename K>
416 const_iterator find(const K& x) const; // C++14
Marek Kurdejd7e019e2021-04-13 17:10:55 +0200417
Marshall Clowebb57322013-08-13 22:18:47 +0000418 template<typename K>
Marshall Clowe6a5f522014-08-24 23:54:16 +0000419 size_type count(const K& x) const; // C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000420 size_type count(const key_type& k) const;
Marek Kurdejd7e019e2021-04-13 17:10:55 +0200421
422 bool contains(const key_type& x) const; // C++20
423 template<class K> bool contains(const K& x) const; // C++20
424
Howard Hinnantc51e1022010-05-11 19:42:16 +0000425 iterator lower_bound(const key_type& k);
426 const_iterator lower_bound(const key_type& k) const;
Marshall Clowebb57322013-08-13 22:18:47 +0000427 template<typename K>
428 iterator lower_bound(const K& x); // C++14
429 template<typename K>
430 const_iterator lower_bound(const K& x) const; // C++14
431
Howard Hinnantc51e1022010-05-11 19:42:16 +0000432 iterator upper_bound(const key_type& k);
433 const_iterator upper_bound(const key_type& k) const;
Marshall Clowebb57322013-08-13 22:18:47 +0000434 template<typename K>
435 iterator upper_bound(const K& x); // C++14
436 template<typename K>
437 const_iterator upper_bound(const K& x) const; // C++14
438
Howard Hinnantc51e1022010-05-11 19:42:16 +0000439 pair<iterator,iterator> equal_range(const key_type& k);
440 pair<const_iterator,const_iterator> equal_range(const key_type& k) const;
Marshall Clowebb57322013-08-13 22:18:47 +0000441 template<typename K>
442 pair<iterator,iterator> equal_range(const K& x); // C++14
443 template<typename K>
444 pair<const_iterator,const_iterator> equal_range(const K& x) const; // C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000445};
446
447template <class Key, class T, class Compare, class Allocator>
448bool
449operator==(const multimap<Key, T, Compare, Allocator>& x,
450 const multimap<Key, T, Compare, Allocator>& y);
451
452template <class Key, class T, class Compare, class Allocator>
453bool
454operator< (const multimap<Key, T, Compare, Allocator>& x,
455 const multimap<Key, T, Compare, Allocator>& y);
456
457template <class Key, class T, class Compare, class Allocator>
458bool
459operator!=(const multimap<Key, T, Compare, Allocator>& x,
460 const multimap<Key, T, Compare, Allocator>& y);
461
462template <class Key, class T, class Compare, class Allocator>
463bool
464operator> (const multimap<Key, T, Compare, Allocator>& x,
465 const multimap<Key, T, Compare, Allocator>& y);
466
467template <class Key, class T, class Compare, class Allocator>
468bool
469operator>=(const multimap<Key, T, Compare, Allocator>& x,
470 const multimap<Key, T, Compare, Allocator>& y);
471
472template <class Key, class T, class Compare, class Allocator>
473bool
474operator<=(const multimap<Key, T, Compare, Allocator>& x,
475 const multimap<Key, T, Compare, Allocator>& y);
476
477// specialized algorithms:
478template <class Key, class T, class Compare, class Allocator>
479void
480swap(multimap<Key, T, Compare, Allocator>& x,
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000481 multimap<Key, T, Compare, Allocator>& y)
482 noexcept(noexcept(x.swap(y)));
Howard Hinnantc51e1022010-05-11 19:42:16 +0000483
Marshall Clow29b53f22018-12-14 18:49:35 +0000484template <class Key, class T, class Compare, class Allocator, class Predicate>
Marek Kurdeja98b1412020-05-02 13:58:03 +0200485typename multimap<Key, T, Compare, Allocator>::size_type
486erase_if(multimap<Key, T, Compare, Allocator>& c, Predicate pred); // C++20
Marshall Clow29b53f22018-12-14 18:49:35 +0000487
Howard Hinnantc51e1022010-05-11 19:42:16 +0000488} // std
489
490*/
491
492#include <__config>
Arthur O'Dwyer597cac42021-05-12 23:04:03 -0400493#include <__debug>
Erik Pilkingtonc37a3d82018-08-01 01:33:38 +0000494#include <__node_handle>
Arthur O'Dwyer597cac42021-05-12 23:04:03 -0400495#include <__tree>
Christopher Di Bella41f26e82021-06-05 02:47:47 +0000496#include <__utility/forward.h>
Arthur O'Dwyer7deec122021-03-24 18:19:12 -0400497#include <compare>
Arthur O'Dwyeref181602021-05-19 11:57:04 -0400498#include <functional>
Arthur O'Dwyer7deec122021-03-24 18:19:12 -0400499#include <initializer_list>
Arthur O'Dwyerb6738bd2021-03-21 16:53:09 -0400500#include <iterator> // __libcpp_erase_if_container
Howard Hinnantc51e1022010-05-11 19:42:16 +0000501#include <memory>
Eric Fiselierf7394302015-06-13 07:08:02 +0000502#include <type_traits>
Arthur O'Dwyeref181602021-05-19 11:57:04 -0400503#include <utility>
Marshall Clow0a1e7502018-09-12 19:41:40 +0000504#include <version>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000505
Howard Hinnantaaaa52b2011-10-17 20:05:10 +0000506#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000507#pragma GCC system_header
Howard Hinnantaaaa52b2011-10-17 20:05:10 +0000508#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000509
510_LIBCPP_BEGIN_NAMESPACE_STD
511
Louis Dionne878a3a82018-12-06 21:46:17 +0000512template <class _Key, class _CP, class _Compare,
513 bool = is_empty<_Compare>::value && !__libcpp_is_final<_Compare>::value>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000514class __map_value_compare
515 : private _Compare
516{
Howard Hinnantc51e1022010-05-11 19:42:16 +0000517public:
Howard Hinnant756c69b2010-09-22 16:48:34 +0000518 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000519 __map_value_compare()
520 _NOEXCEPT_(is_nothrow_default_constructible<_Compare>::value)
521 : _Compare() {}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000522 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000523 __map_value_compare(_Compare c)
524 _NOEXCEPT_(is_nothrow_copy_constructible<_Compare>::value)
525 : _Compare(c) {}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000526 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000527 const _Compare& key_comp() const _NOEXCEPT {return *this;}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000528 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000529 bool operator()(const _CP& __x, const _CP& __y) const
Erik Pilkingtond3fe2992018-06-04 20:38:23 +0000530 {return static_cast<const _Compare&>(*this)(__x.__get_value().first, __y.__get_value().first);}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000531 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000532 bool operator()(const _CP& __x, const _Key& __y) const
Erik Pilkingtond3fe2992018-06-04 20:38:23 +0000533 {return static_cast<const _Compare&>(*this)(__x.__get_value().first, __y);}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000534 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000535 bool operator()(const _Key& __x, const _CP& __y) const
Erik Pilkingtond3fe2992018-06-04 20:38:23 +0000536 {return static_cast<const _Compare&>(*this)(__x, __y.__get_value().first);}
Marshall Clow8982dcd2015-07-13 20:04:56 +0000537 void swap(__map_value_compare&__y)
538 _NOEXCEPT_(__is_nothrow_swappable<_Compare>::value)
539 {
Eric Fiselier68b5f0b2017-04-13 00:34:24 +0000540 using _VSTD::swap;
541 swap(static_cast<_Compare&>(*this), static_cast<_Compare&>(__y));
Marshall Clow8982dcd2015-07-13 20:04:56 +0000542 }
Marshall Clowebb57322013-08-13 22:18:47 +0000543
544#if _LIBCPP_STD_VER > 11
545 template <typename _K2>
546 _LIBCPP_INLINE_VISIBILITY
547 typename enable_if<__is_transparent<_Compare, _K2>::value, bool>::type
548 operator () ( const _K2& __x, const _CP& __y ) const
Erik Pilkingtond3fe2992018-06-04 20:38:23 +0000549 {return static_cast<const _Compare&>(*this) (__x, __y.__get_value().first);}
Marshall Clowebb57322013-08-13 22:18:47 +0000550
551 template <typename _K2>
552 _LIBCPP_INLINE_VISIBILITY
553 typename enable_if<__is_transparent<_Compare, _K2>::value, bool>::type
554 operator () (const _CP& __x, const _K2& __y) const
Erik Pilkingtond3fe2992018-06-04 20:38:23 +0000555 {return static_cast<const _Compare&>(*this) (__x.__get_value().first, __y);}
Marshall Clowebb57322013-08-13 22:18:47 +0000556#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000557};
558
Howard Hinnant90b91592013-07-05 18:06:00 +0000559template <class _Key, class _CP, class _Compare>
560class __map_value_compare<_Key, _CP, _Compare, false>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000561{
562 _Compare comp;
563
Howard Hinnantc51e1022010-05-11 19:42:16 +0000564public:
Howard Hinnant756c69b2010-09-22 16:48:34 +0000565 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000566 __map_value_compare()
567 _NOEXCEPT_(is_nothrow_default_constructible<_Compare>::value)
568 : comp() {}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000569 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000570 __map_value_compare(_Compare c)
571 _NOEXCEPT_(is_nothrow_copy_constructible<_Compare>::value)
572 : comp(c) {}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000573 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000574 const _Compare& key_comp() const _NOEXCEPT {return comp;}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000575
Howard Hinnant756c69b2010-09-22 16:48:34 +0000576 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000577 bool operator()(const _CP& __x, const _CP& __y) const
Erik Pilkingtond3fe2992018-06-04 20:38:23 +0000578 {return comp(__x.__get_value().first, __y.__get_value().first);}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000579 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000580 bool operator()(const _CP& __x, const _Key& __y) const
Erik Pilkingtond3fe2992018-06-04 20:38:23 +0000581 {return comp(__x.__get_value().first, __y);}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000582 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000583 bool operator()(const _Key& __x, const _CP& __y) const
Erik Pilkingtond3fe2992018-06-04 20:38:23 +0000584 {return comp(__x, __y.__get_value().first);}
Marshall Clow8982dcd2015-07-13 20:04:56 +0000585 void swap(__map_value_compare&__y)
586 _NOEXCEPT_(__is_nothrow_swappable<_Compare>::value)
587 {
588 using _VSTD::swap;
589 swap(comp, __y.comp);
590 }
Eric Fiseliercf8c0212017-01-05 06:06:18 +0000591
Marshall Clowebb57322013-08-13 22:18:47 +0000592#if _LIBCPP_STD_VER > 11
593 template <typename _K2>
594 _LIBCPP_INLINE_VISIBILITY
595 typename enable_if<__is_transparent<_Compare, _K2>::value, bool>::type
596 operator () ( const _K2& __x, const _CP& __y ) const
Erik Pilkingtond3fe2992018-06-04 20:38:23 +0000597 {return comp (__x, __y.__get_value().first);}
Marshall Clowebb57322013-08-13 22:18:47 +0000598
599 template <typename _K2>
600 _LIBCPP_INLINE_VISIBILITY
601 typename enable_if<__is_transparent<_Compare, _K2>::value, bool>::type
602 operator () (const _CP& __x, const _K2& __y) const
Erik Pilkingtond3fe2992018-06-04 20:38:23 +0000603 {return comp (__x.__get_value().first, __y);}
Marshall Clowebb57322013-08-13 22:18:47 +0000604#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000605};
606
Marshall Clow8982dcd2015-07-13 20:04:56 +0000607template <class _Key, class _CP, class _Compare, bool __b>
608inline _LIBCPP_INLINE_VISIBILITY
609void
610swap(__map_value_compare<_Key, _CP, _Compare, __b>& __x,
611 __map_value_compare<_Key, _CP, _Compare, __b>& __y)
612 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
613{
614 __x.swap(__y);
615}
616
Howard Hinnantc51e1022010-05-11 19:42:16 +0000617template <class _Allocator>
618class __map_node_destructor
619{
620 typedef _Allocator allocator_type;
621 typedef allocator_traits<allocator_type> __alloc_traits;
Eric Fiseliera00b4842016-02-20 05:28:30 +0000622
Howard Hinnantc51e1022010-05-11 19:42:16 +0000623public:
624 typedef typename __alloc_traits::pointer pointer;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000625
Eric Fiseliera00b4842016-02-20 05:28:30 +0000626private:
Howard Hinnantc51e1022010-05-11 19:42:16 +0000627 allocator_type& __na_;
628
629 __map_node_destructor& operator=(const __map_node_destructor&);
630
631public:
632 bool __first_constructed;
633 bool __second_constructed;
634
Howard Hinnant756c69b2010-09-22 16:48:34 +0000635 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000636 explicit __map_node_destructor(allocator_type& __na) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +0000637 : __na_(__na),
638 __first_constructed(false),
639 __second_constructed(false)
640 {}
641
Eric Fiseliera85b1282017-04-18 21:08:06 +0000642#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant756c69b2010-09-22 16:48:34 +0000643 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000644 __map_node_destructor(__tree_node_destructor<allocator_type>&& __x) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +0000645 : __na_(__x.__na_),
646 __first_constructed(__x.__value_constructed),
647 __second_constructed(__x.__value_constructed)
648 {
649 __x.__value_constructed = false;
650 }
Louis Dionne2b1ceaa2021-04-20 12:03:32 -0400651#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000652
Howard Hinnant756c69b2010-09-22 16:48:34 +0000653 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000654 void operator()(pointer __p) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +0000655 {
656 if (__second_constructed)
Erik Pilkingtond3fe2992018-06-04 20:38:23 +0000657 __alloc_traits::destroy(__na_, _VSTD::addressof(__p->__value_.__get_value().second));
Howard Hinnantc51e1022010-05-11 19:42:16 +0000658 if (__first_constructed)
Erik Pilkingtond3fe2992018-06-04 20:38:23 +0000659 __alloc_traits::destroy(__na_, _VSTD::addressof(__p->__value_.__get_value().first));
Howard Hinnantc51e1022010-05-11 19:42:16 +0000660 if (__p)
661 __alloc_traits::deallocate(__na_, __p, 1);
662 }
663};
664
Howard Hinnant944510a2011-06-14 19:58:17 +0000665template <class _Key, class _Tp, class _Compare, class _Allocator>
666 class map;
667template <class _Key, class _Tp, class _Compare, class _Allocator>
668 class multimap;
669template <class _TreeIterator> class __map_const_iterator;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000670
Eric Fiseliera00b4842016-02-20 05:28:30 +0000671#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant89f8b792013-09-30 19:08:22 +0000672
673template <class _Key, class _Tp>
Amy Huang63f53b52021-03-15 14:20:49 -0700674struct _LIBCPP_STANDALONE_DEBUG __value_type
Howard Hinnant89f8b792013-09-30 19:08:22 +0000675{
676 typedef _Key key_type;
677 typedef _Tp mapped_type;
678 typedef pair<const key_type, mapped_type> value_type;
Erik Pilkingtond3fe2992018-06-04 20:38:23 +0000679 typedef pair<key_type&, mapped_type&> __nc_ref_pair_type;
680 typedef pair<key_type&&, mapped_type&&> __nc_rref_pair_type;
Howard Hinnant89f8b792013-09-30 19:08:22 +0000681
Erik Pilkingtond3fe2992018-06-04 20:38:23 +0000682private:
Howard Hinnant89f8b792013-09-30 19:08:22 +0000683 value_type __cc;
Erik Pilkingtond3fe2992018-06-04 20:38:23 +0000684
685public:
686 _LIBCPP_INLINE_VISIBILITY
687 value_type& __get_value()
688 {
689#if _LIBCPP_STD_VER > 14
690 return *_VSTD::launder(_VSTD::addressof(__cc));
691#else
692 return __cc;
693#endif
694 }
695
696 _LIBCPP_INLINE_VISIBILITY
697 const value_type& __get_value() const
698 {
699#if _LIBCPP_STD_VER > 14
700 return *_VSTD::launder(_VSTD::addressof(__cc));
701#else
702 return __cc;
703#endif
704 }
705
706 _LIBCPP_INLINE_VISIBILITY
707 __nc_ref_pair_type __ref()
708 {
709 value_type& __v = __get_value();
710 return __nc_ref_pair_type(const_cast<key_type&>(__v.first), __v.second);
711 }
712
713 _LIBCPP_INLINE_VISIBILITY
714 __nc_rref_pair_type __move()
715 {
716 value_type& __v = __get_value();
717 return __nc_rref_pair_type(
718 _VSTD::move(const_cast<key_type&>(__v.first)),
719 _VSTD::move(__v.second));
720 }
Howard Hinnant89f8b792013-09-30 19:08:22 +0000721
Howard Hinnant89f8b792013-09-30 19:08:22 +0000722 _LIBCPP_INLINE_VISIBILITY
723 __value_type& operator=(const __value_type& __v)
Erik Pilkingtond3fe2992018-06-04 20:38:23 +0000724 {
725 __ref() = __v.__get_value();
726 return *this;
727 }
Howard Hinnant89f8b792013-09-30 19:08:22 +0000728
729 _LIBCPP_INLINE_VISIBILITY
730 __value_type& operator=(__value_type&& __v)
Erik Pilkingtond3fe2992018-06-04 20:38:23 +0000731 {
732 __ref() = __v.__move();
733 return *this;
734 }
Howard Hinnant89f8b792013-09-30 19:08:22 +0000735
Eric Fiselierd06276b2016-03-31 02:15:15 +0000736 template <class _ValueTp,
737 class = typename enable_if<
738 __is_same_uncvref<_ValueTp, value_type>::value
739 >::type
740 >
Howard Hinnant89f8b792013-09-30 19:08:22 +0000741 _LIBCPP_INLINE_VISIBILITY
Erik Pilkingtond3fe2992018-06-04 20:38:23 +0000742 __value_type& operator=(_ValueTp&& __v)
743 {
744 __ref() = _VSTD::forward<_ValueTp>(__v);
745 return *this;
Eric Fiselierd06276b2016-03-31 02:15:15 +0000746 }
747
748private:
749 __value_type() _LIBCPP_EQUAL_DELETE;
750 ~__value_type() _LIBCPP_EQUAL_DELETE;
751 __value_type(const __value_type& __v) _LIBCPP_EQUAL_DELETE;
752 __value_type(__value_type&& __v) _LIBCPP_EQUAL_DELETE;
Howard Hinnant89f8b792013-09-30 19:08:22 +0000753};
754
755#else
756
757template <class _Key, class _Tp>
758struct __value_type
759{
760 typedef _Key key_type;
761 typedef _Tp mapped_type;
762 typedef pair<const key_type, mapped_type> value_type;
763
Erik Pilkingtond3fe2992018-06-04 20:38:23 +0000764private:
Howard Hinnant89f8b792013-09-30 19:08:22 +0000765 value_type __cc;
766
Erik Pilkingtond3fe2992018-06-04 20:38:23 +0000767public:
768 _LIBCPP_INLINE_VISIBILITY
769 value_type& __get_value() { return __cc; }
770 _LIBCPP_INLINE_VISIBILITY
771 const value_type& __get_value() const { return __cc; }
772
Eric Fiselierd06276b2016-03-31 02:15:15 +0000773private:
774 __value_type();
775 __value_type(__value_type const&);
776 __value_type& operator=(__value_type const&);
777 ~__value_type();
Howard Hinnant89f8b792013-09-30 19:08:22 +0000778};
779
Eric Fiseliera85b1282017-04-18 21:08:06 +0000780#endif // _LIBCPP_CXX03_LANG
Howard Hinnant89f8b792013-09-30 19:08:22 +0000781
Eric Fiselier44f9fd02015-03-03 20:10:01 +0000782template <class _Tp>
783struct __extract_key_value_types;
784
785template <class _Key, class _Tp>
786struct __extract_key_value_types<__value_type<_Key, _Tp> >
787{
788 typedef _Key const __key_type;
789 typedef _Tp __mapped_type;
790};
791
Howard Hinnantc51e1022010-05-11 19:42:16 +0000792template <class _TreeIterator>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000793class _LIBCPP_TEMPLATE_VIS __map_iterator
Howard Hinnantc51e1022010-05-11 19:42:16 +0000794{
Eric Fiseliera00b4842016-02-20 05:28:30 +0000795 typedef typename _TreeIterator::_NodeTypes _NodeTypes;
796 typedef typename _TreeIterator::__pointer_traits __pointer_traits;
797
Howard Hinnantc51e1022010-05-11 19:42:16 +0000798 _TreeIterator __i_;
799
Howard Hinnantc51e1022010-05-11 19:42:16 +0000800public:
801 typedef bidirectional_iterator_tag iterator_category;
Eric Fiseliera00b4842016-02-20 05:28:30 +0000802 typedef typename _NodeTypes::__map_value_type value_type;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000803 typedef typename _TreeIterator::difference_type difference_type;
804 typedef value_type& reference;
Eric Fiseliera00b4842016-02-20 05:28:30 +0000805 typedef typename _NodeTypes::__map_value_type_pointer pointer;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000806
Howard Hinnant756c69b2010-09-22 16:48:34 +0000807 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000808 __map_iterator() _NOEXCEPT {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000809
Howard Hinnant756c69b2010-09-22 16:48:34 +0000810 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000811 __map_iterator(_TreeIterator __i) _NOEXCEPT : __i_(__i) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000812
Howard Hinnant756c69b2010-09-22 16:48:34 +0000813 _LIBCPP_INLINE_VISIBILITY
Erik Pilkingtond3fe2992018-06-04 20:38:23 +0000814 reference operator*() const {return __i_->__get_value();}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000815 _LIBCPP_INLINE_VISIBILITY
Erik Pilkingtond3fe2992018-06-04 20:38:23 +0000816 pointer operator->() const {return pointer_traits<pointer>::pointer_to(__i_->__get_value());}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000817
Howard Hinnant756c69b2010-09-22 16:48:34 +0000818 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000819 __map_iterator& operator++() {++__i_; return *this;}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000820 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000821 __map_iterator operator++(int)
822 {
823 __map_iterator __t(*this);
824 ++(*this);
825 return __t;
826 }
827
Howard Hinnant756c69b2010-09-22 16:48:34 +0000828 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000829 __map_iterator& operator--() {--__i_; return *this;}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000830 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000831 __map_iterator operator--(int)
832 {
833 __map_iterator __t(*this);
834 --(*this);
835 return __t;
836 }
837
Howard Hinnant756c69b2010-09-22 16:48:34 +0000838 friend _LIBCPP_INLINE_VISIBILITY
839 bool operator==(const __map_iterator& __x, const __map_iterator& __y)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000840 {return __x.__i_ == __y.__i_;}
Eric Fiseliercf8c0212017-01-05 06:06:18 +0000841 friend
Howard Hinnant756c69b2010-09-22 16:48:34 +0000842 _LIBCPP_INLINE_VISIBILITY
843 bool operator!=(const __map_iterator& __x, const __map_iterator& __y)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000844 {return __x.__i_ != __y.__i_;}
845
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000846 template <class, class, class, class> friend class _LIBCPP_TEMPLATE_VIS map;
847 template <class, class, class, class> friend class _LIBCPP_TEMPLATE_VIS multimap;
848 template <class> friend class _LIBCPP_TEMPLATE_VIS __map_const_iterator;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000849};
850
851template <class _TreeIterator>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000852class _LIBCPP_TEMPLATE_VIS __map_const_iterator
Howard Hinnantc51e1022010-05-11 19:42:16 +0000853{
Eric Fiseliera00b4842016-02-20 05:28:30 +0000854 typedef typename _TreeIterator::_NodeTypes _NodeTypes;
855 typedef typename _TreeIterator::__pointer_traits __pointer_traits;
856
Howard Hinnantc51e1022010-05-11 19:42:16 +0000857 _TreeIterator __i_;
858
Howard Hinnantc51e1022010-05-11 19:42:16 +0000859public:
860 typedef bidirectional_iterator_tag iterator_category;
Eric Fiseliera00b4842016-02-20 05:28:30 +0000861 typedef typename _NodeTypes::__map_value_type value_type;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000862 typedef typename _TreeIterator::difference_type difference_type;
863 typedef const value_type& reference;
Eric Fiseliera00b4842016-02-20 05:28:30 +0000864 typedef typename _NodeTypes::__const_map_value_type_pointer pointer;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000865
Howard Hinnant756c69b2010-09-22 16:48:34 +0000866 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000867 __map_const_iterator() _NOEXCEPT {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000868
Howard Hinnant756c69b2010-09-22 16:48:34 +0000869 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000870 __map_const_iterator(_TreeIterator __i) _NOEXCEPT : __i_(__i) {}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000871 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier44f9fd02015-03-03 20:10:01 +0000872 __map_const_iterator(__map_iterator<
873 typename _TreeIterator::__non_const_iterator> __i) _NOEXCEPT
874 : __i_(__i.__i_) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000875
Howard Hinnant756c69b2010-09-22 16:48:34 +0000876 _LIBCPP_INLINE_VISIBILITY
Erik Pilkingtond3fe2992018-06-04 20:38:23 +0000877 reference operator*() const {return __i_->__get_value();}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000878 _LIBCPP_INLINE_VISIBILITY
Erik Pilkingtond3fe2992018-06-04 20:38:23 +0000879 pointer operator->() const {return pointer_traits<pointer>::pointer_to(__i_->__get_value());}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000880
Howard Hinnant756c69b2010-09-22 16:48:34 +0000881 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000882 __map_const_iterator& operator++() {++__i_; return *this;}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000883 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000884 __map_const_iterator operator++(int)
885 {
886 __map_const_iterator __t(*this);
887 ++(*this);
888 return __t;
889 }
890
Howard Hinnant756c69b2010-09-22 16:48:34 +0000891 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000892 __map_const_iterator& operator--() {--__i_; return *this;}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000893 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000894 __map_const_iterator operator--(int)
895 {
896 __map_const_iterator __t(*this);
897 --(*this);
898 return __t;
899 }
900
Howard Hinnant756c69b2010-09-22 16:48:34 +0000901 friend _LIBCPP_INLINE_VISIBILITY
902 bool operator==(const __map_const_iterator& __x, const __map_const_iterator& __y)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000903 {return __x.__i_ == __y.__i_;}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000904 friend _LIBCPP_INLINE_VISIBILITY
905 bool operator!=(const __map_const_iterator& __x, const __map_const_iterator& __y)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000906 {return __x.__i_ != __y.__i_;}
907
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000908 template <class, class, class, class> friend class _LIBCPP_TEMPLATE_VIS map;
909 template <class, class, class, class> friend class _LIBCPP_TEMPLATE_VIS multimap;
910 template <class, class, class> friend class _LIBCPP_TEMPLATE_VIS __tree_const_iterator;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000911};
912
913template <class _Key, class _Tp, class _Compare = less<_Key>,
914 class _Allocator = allocator<pair<const _Key, _Tp> > >
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000915class _LIBCPP_TEMPLATE_VIS map
Howard Hinnantc51e1022010-05-11 19:42:16 +0000916{
917public:
918 // types:
919 typedef _Key key_type;
920 typedef _Tp mapped_type;
921 typedef pair<const key_type, mapped_type> value_type;
Arthur O'Dwyer6a752e12021-03-03 11:10:49 -0500922 typedef __identity_t<_Compare> key_compare;
923 typedef __identity_t<_Allocator> allocator_type;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000924 typedef value_type& reference;
925 typedef const value_type& const_reference;
926
Marshall Clow5128cf32015-11-26 01:24:04 +0000927 static_assert((is_same<typename allocator_type::value_type, value_type>::value),
928 "Allocator::value_type must be same type as value_type");
929
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400930_LIBCPP_SUPPRESS_DEPRECATED_PUSH
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000931 class _LIBCPP_TEMPLATE_VIS value_compare
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400932#if defined(_LIBCPP_ENABLE_CXX20_REMOVED_BINDER_TYPEDEFS)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000933 : public binary_function<value_type, value_type, bool>
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400934#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000935 {
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400936_LIBCPP_SUPPRESS_DEPRECATED_POP
Howard Hinnantc51e1022010-05-11 19:42:16 +0000937 friend class map;
938 protected:
939 key_compare comp;
940
Howard Hinnant756c69b2010-09-22 16:48:34 +0000941 _LIBCPP_INLINE_VISIBILITY value_compare(key_compare c) : comp(c) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000942 public:
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400943#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_BINDER_TYPEDEFS)
944 _LIBCPP_DEPRECATED_IN_CXX17 typedef bool result_type;
945 _LIBCPP_DEPRECATED_IN_CXX17 typedef value_type first_argument_type;
946 _LIBCPP_DEPRECATED_IN_CXX17 typedef value_type second_argument_type;
947#endif
Howard Hinnant756c69b2010-09-22 16:48:34 +0000948 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000949 bool operator()(const value_type& __x, const value_type& __y) const
950 {return comp(__x.first, __y.first);}
951 };
952
953private:
Howard Hinnant2d0046b2013-06-19 21:29:40 +0000954
Howard Hinnant89f8b792013-09-30 19:08:22 +0000955 typedef _VSTD::__value_type<key_type, mapped_type> __value_type;
Howard Hinnant90b91592013-07-05 18:06:00 +0000956 typedef __map_value_compare<key_type, __value_type, key_compare> __vc;
Marshall Clow940e01c2015-04-07 05:21:38 +0000957 typedef typename __rebind_alloc_helper<allocator_traits<allocator_type>,
958 __value_type>::type __allocator_type;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000959 typedef __tree<__value_type, __vc, __allocator_type> __base;
960 typedef typename __base::__node_traits __node_traits;
961 typedef allocator_traits<allocator_type> __alloc_traits;
962
963 __base __tree_;
964
965public:
966 typedef typename __alloc_traits::pointer pointer;
967 typedef typename __alloc_traits::const_pointer const_pointer;
968 typedef typename __alloc_traits::size_type size_type;
969 typedef typename __alloc_traits::difference_type difference_type;
Eric Fiselier44f9fd02015-03-03 20:10:01 +0000970 typedef __map_iterator<typename __base::iterator> iterator;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000971 typedef __map_const_iterator<typename __base::const_iterator> const_iterator;
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000972 typedef _VSTD::reverse_iterator<iterator> reverse_iterator;
973 typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000974
Erik Pilkingtonc37a3d82018-08-01 01:33:38 +0000975#if _LIBCPP_STD_VER > 14
976 typedef __map_node_handle<typename __base::__node, allocator_type> node_type;
977 typedef __insert_return_type<iterator, node_type> insert_return_type;
978#endif
979
Erik Pilkington82a65ad2018-10-31 17:31:35 +0000980 template <class _Key2, class _Value2, class _Comp2, class _Alloc2>
981 friend class _LIBCPP_TEMPLATE_VIS map;
982 template <class _Key2, class _Value2, class _Comp2, class _Alloc2>
983 friend class _LIBCPP_TEMPLATE_VIS multimap;
984
Howard Hinnant756c69b2010-09-22 16:48:34 +0000985 _LIBCPP_INLINE_VISIBILITY
Marshall Clow7086a5a2014-03-10 04:50:10 +0000986 map()
987 _NOEXCEPT_(
988 is_nothrow_default_constructible<allocator_type>::value &&
989 is_nothrow_default_constructible<key_compare>::value &&
990 is_nothrow_copy_constructible<key_compare>::value)
991 : __tree_(__vc(key_compare())) {}
992
993 _LIBCPP_INLINE_VISIBILITY
994 explicit map(const key_compare& __comp)
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000995 _NOEXCEPT_(
996 is_nothrow_default_constructible<allocator_type>::value &&
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000997 is_nothrow_copy_constructible<key_compare>::value)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000998 : __tree_(__vc(__comp)) {}
999
Howard Hinnant756c69b2010-09-22 16:48:34 +00001000 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001001 explicit map(const key_compare& __comp, const allocator_type& __a)
Marshall Clow657cbc42016-08-17 05:58:40 +00001002 : __tree_(__vc(__comp), typename __base::allocator_type(__a)) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001003
1004 template <class _InputIterator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001005 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001006 map(_InputIterator __f, _InputIterator __l,
1007 const key_compare& __comp = key_compare())
1008 : __tree_(__vc(__comp))
1009 {
1010 insert(__f, __l);
1011 }
1012
1013 template <class _InputIterator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001014 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001015 map(_InputIterator __f, _InputIterator __l,
1016 const key_compare& __comp, const allocator_type& __a)
Marshall Clow657cbc42016-08-17 05:58:40 +00001017 : __tree_(__vc(__comp), typename __base::allocator_type(__a))
Howard Hinnantc51e1022010-05-11 19:42:16 +00001018 {
1019 insert(__f, __l);
1020 }
1021
Marshall Clow300abfb2013-09-11 01:15:47 +00001022#if _LIBCPP_STD_VER > 11
1023 template <class _InputIterator>
Eric Fiseliercf8c0212017-01-05 06:06:18 +00001024 _LIBCPP_INLINE_VISIBILITY
Marshall Clow300abfb2013-09-11 01:15:47 +00001025 map(_InputIterator __f, _InputIterator __l, const allocator_type& __a)
1026 : map(__f, __l, key_compare(), __a) {}
1027#endif
1028
Howard Hinnant756c69b2010-09-22 16:48:34 +00001029 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001030 map(const map& __m)
1031 : __tree_(__m.__tree_)
1032 {
1033 insert(__m.begin(), __m.end());
1034 }
1035
Howard Hinnantd3a657f2011-07-01 19:24:36 +00001036 _LIBCPP_INLINE_VISIBILITY
1037 map& operator=(const map& __m)
1038 {
Marshall Clow476d3f42016-07-18 13:19:00 +00001039#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantd3a657f2011-07-01 19:24:36 +00001040 __tree_ = __m.__tree_;
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001041#else
Marshall Clowdb3cfcb2014-02-08 04:03:14 +00001042 if (this != &__m) {
1043 __tree_.clear();
1044 __tree_.value_comp() = __m.__tree_.value_comp();
1045 __tree_.__copy_assign_alloc(__m.__tree_);
1046 insert(__m.begin(), __m.end());
1047 }
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001048#endif
Howard Hinnantd3a657f2011-07-01 19:24:36 +00001049 return *this;
1050 }
1051
Eric Fiseliera85b1282017-04-18 21:08:06 +00001052#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001053
Howard Hinnant756c69b2010-09-22 16:48:34 +00001054 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001055 map(map&& __m)
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001056 _NOEXCEPT_(is_nothrow_move_constructible<__base>::value)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001057 : __tree_(_VSTD::move(__m.__tree_))
Howard Hinnantc51e1022010-05-11 19:42:16 +00001058 {
1059 }
1060
1061 map(map&& __m, const allocator_type& __a);
1062
Howard Hinnant756c69b2010-09-22 16:48:34 +00001063 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant33711792011-08-12 21:56:02 +00001064 map& operator=(map&& __m)
1065 _NOEXCEPT_(is_nothrow_move_assignable<__base>::value)
1066 {
1067 __tree_ = _VSTD::move(__m.__tree_);
1068 return *this;
1069 }
1070
Howard Hinnant33711792011-08-12 21:56:02 +00001071 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001072 map(initializer_list<value_type> __il, const key_compare& __comp = key_compare())
1073 : __tree_(__vc(__comp))
1074 {
1075 insert(__il.begin(), __il.end());
1076 }
1077
Howard Hinnant756c69b2010-09-22 16:48:34 +00001078 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001079 map(initializer_list<value_type> __il, const key_compare& __comp, const allocator_type& __a)
Marshall Clow657cbc42016-08-17 05:58:40 +00001080 : __tree_(__vc(__comp), typename __base::allocator_type(__a))
Howard Hinnantc51e1022010-05-11 19:42:16 +00001081 {
1082 insert(__il.begin(), __il.end());
1083 }
1084
Marshall Clow300abfb2013-09-11 01:15:47 +00001085#if _LIBCPP_STD_VER > 11
Eric Fiseliercf8c0212017-01-05 06:06:18 +00001086 _LIBCPP_INLINE_VISIBILITY
Marshall Clow300abfb2013-09-11 01:15:47 +00001087 map(initializer_list<value_type> __il, const allocator_type& __a)
1088 : map(__il, key_compare(), __a) {}
1089#endif
1090
Howard Hinnant756c69b2010-09-22 16:48:34 +00001091 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001092 map& operator=(initializer_list<value_type> __il)
1093 {
1094 __tree_.__assign_unique(__il.begin(), __il.end());
1095 return *this;
1096 }
1097
Louis Dionne2b1ceaa2021-04-20 12:03:32 -04001098#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001099
Howard Hinnant756c69b2010-09-22 16:48:34 +00001100 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001101 explicit map(const allocator_type& __a)
Marshall Clow657cbc42016-08-17 05:58:40 +00001102 : __tree_(typename __base::allocator_type(__a))
Howard Hinnantc51e1022010-05-11 19:42:16 +00001103 {
1104 }
1105
Howard Hinnant756c69b2010-09-22 16:48:34 +00001106 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001107 map(const map& __m, const allocator_type& __a)
Marshall Clow657cbc42016-08-17 05:58:40 +00001108 : __tree_(__m.__tree_.value_comp(), typename __base::allocator_type(__a))
Howard Hinnantc51e1022010-05-11 19:42:16 +00001109 {
1110 insert(__m.begin(), __m.end());
1111 }
1112
Howard Hinnant756c69b2010-09-22 16:48:34 +00001113 _LIBCPP_INLINE_VISIBILITY
Louis Dionne69c42c02019-04-11 16:14:56 +00001114 ~map() {
1115 static_assert(sizeof(__diagnose_non_const_comparator<_Key, _Compare>()), "");
1116 }
1117
1118 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001119 iterator begin() _NOEXCEPT {return __tree_.begin();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001120 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001121 const_iterator begin() const _NOEXCEPT {return __tree_.begin();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001122 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001123 iterator end() _NOEXCEPT {return __tree_.end();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001124 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001125 const_iterator end() const _NOEXCEPT {return __tree_.end();}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001126
Howard Hinnant756c69b2010-09-22 16:48:34 +00001127 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001128 reverse_iterator rbegin() _NOEXCEPT {return reverse_iterator(end());}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001129 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001130 const_reverse_iterator rbegin() const _NOEXCEPT
1131 {return const_reverse_iterator(end());}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001132 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001133 reverse_iterator rend() _NOEXCEPT
1134 {return reverse_iterator(begin());}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001135 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001136 const_reverse_iterator rend() const _NOEXCEPT
1137 {return const_reverse_iterator(begin());}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001138
Howard Hinnant756c69b2010-09-22 16:48:34 +00001139 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001140 const_iterator cbegin() const _NOEXCEPT {return begin();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001141 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001142 const_iterator cend() const _NOEXCEPT {return end();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001143 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001144 const_reverse_iterator crbegin() const _NOEXCEPT {return rbegin();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001145 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001146 const_reverse_iterator crend() const _NOEXCEPT {return rend();}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001147
Marshall Clow425f5752017-11-15 05:51:26 +00001148 _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001149 bool empty() const _NOEXCEPT {return __tree_.size() == 0;}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001150 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001151 size_type size() const _NOEXCEPT {return __tree_.size();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001152 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001153 size_type max_size() const _NOEXCEPT {return __tree_.max_size();}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001154
1155 mapped_type& operator[](const key_type& __k);
Eric Fiselierd63f38e2016-03-31 03:13:37 +00001156#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001157 mapped_type& operator[](key_type&& __k);
1158#endif
1159
1160 mapped_type& at(const key_type& __k);
1161 const mapped_type& at(const key_type& __k) const;
1162
Howard Hinnant756c69b2010-09-22 16:48:34 +00001163 _LIBCPP_INLINE_VISIBILITY
Marshall Clow657cbc42016-08-17 05:58:40 +00001164 allocator_type get_allocator() const _NOEXCEPT {return allocator_type(__tree_.__alloc());}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001165 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001166 key_compare key_comp() const {return __tree_.value_comp().key_comp();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001167 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001168 value_compare value_comp() const {return value_compare(__tree_.value_comp().key_comp());}
1169
Eric Fiselierd06276b2016-03-31 02:15:15 +00001170#ifndef _LIBCPP_CXX03_LANG
1171 template <class ..._Args>
1172 _LIBCPP_INLINE_VISIBILITY
1173 pair<iterator, bool> emplace(_Args&& ...__args) {
1174 return __tree_.__emplace_unique(_VSTD::forward<_Args>(__args)...);
1175 }
Howard Hinnant74279a52010-09-04 23:28:19 +00001176
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001177 template <class ..._Args>
Eric Fiselierd06276b2016-03-31 02:15:15 +00001178 _LIBCPP_INLINE_VISIBILITY
1179 iterator emplace_hint(const_iterator __p, _Args&& ...__args) {
1180 return __tree_.__emplace_hint_unique(__p.__i_, _VSTD::forward<_Args>(__args)...);
1181 }
Howard Hinnant74279a52010-09-04 23:28:19 +00001182
Howard Hinnantc834c512011-11-29 18:15:50 +00001183 template <class _Pp,
1184 class = typename enable_if<is_constructible<value_type, _Pp>::value>::type>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001185 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc834c512011-11-29 18:15:50 +00001186 pair<iterator, bool> insert(_Pp&& __p)
1187 {return __tree_.__insert_unique(_VSTD::forward<_Pp>(__p));}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001188
Howard Hinnantc834c512011-11-29 18:15:50 +00001189 template <class _Pp,
1190 class = typename enable_if<is_constructible<value_type, _Pp>::value>::type>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001191 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc834c512011-11-29 18:15:50 +00001192 iterator insert(const_iterator __pos, _Pp&& __p)
1193 {return __tree_.__insert_unique(__pos.__i_, _VSTD::forward<_Pp>(__p));}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001194
Louis Dionne2b1ceaa2021-04-20 12:03:32 -04001195#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001196
Howard Hinnant756c69b2010-09-22 16:48:34 +00001197 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001198 pair<iterator, bool>
1199 insert(const value_type& __v) {return __tree_.__insert_unique(__v);}
1200
Howard Hinnant756c69b2010-09-22 16:48:34 +00001201 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001202 iterator
1203 insert(const_iterator __p, const value_type& __v)
1204 {return __tree_.__insert_unique(__p.__i_, __v);}
1205
Eric Fiselierd6143132016-04-18 01:40:45 +00001206#ifndef _LIBCPP_CXX03_LANG
Marshall Clowd430d022016-01-05 19:32:41 +00001207 _LIBCPP_INLINE_VISIBILITY
1208 pair<iterator, bool>
Eric Fiselierd06276b2016-03-31 02:15:15 +00001209 insert(value_type&& __v) {return __tree_.__insert_unique(_VSTD::move(__v));}
Marshall Clowd430d022016-01-05 19:32:41 +00001210
1211 _LIBCPP_INLINE_VISIBILITY
Eric Fiselierd06276b2016-03-31 02:15:15 +00001212 iterator insert(const_iterator __p, value_type&& __v)
1213 {return __tree_.__insert_unique(__p.__i_, _VSTD::move(__v));}
Eric Fiseliera85b1282017-04-18 21:08:06 +00001214
1215 _LIBCPP_INLINE_VISIBILITY
1216 void insert(initializer_list<value_type> __il)
1217 {insert(__il.begin(), __il.end());}
Marshall Clowd430d022016-01-05 19:32:41 +00001218#endif
1219
Howard Hinnantc51e1022010-05-11 19:42:16 +00001220 template <class _InputIterator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001221 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001222 void insert(_InputIterator __f, _InputIterator __l)
1223 {
1224 for (const_iterator __e = cend(); __f != __l; ++__f)
1225 insert(__e.__i_, *__f);
1226 }
1227
Marshall Clow3223db82015-07-07 03:37:33 +00001228#if _LIBCPP_STD_VER > 14
Eric Fiselierd63f38e2016-03-31 03:13:37 +00001229
Marshall Clow3223db82015-07-07 03:37:33 +00001230 template <class... _Args>
1231 _LIBCPP_INLINE_VISIBILITY
1232 pair<iterator, bool> try_emplace(const key_type& __k, _Args&&... __args)
1233 {
Eric Fiselierd63f38e2016-03-31 03:13:37 +00001234 return __tree_.__emplace_unique_key_args(__k,
1235 _VSTD::piecewise_construct,
1236 _VSTD::forward_as_tuple(__k),
1237 _VSTD::forward_as_tuple(_VSTD::forward<_Args>(__args)...));
Marshall Clow3223db82015-07-07 03:37:33 +00001238 }
1239
1240 template <class... _Args>
1241 _LIBCPP_INLINE_VISIBILITY
1242 pair<iterator, bool> try_emplace(key_type&& __k, _Args&&... __args)
1243 {
Eric Fiselierd63f38e2016-03-31 03:13:37 +00001244 return __tree_.__emplace_unique_key_args(__k,
1245 _VSTD::piecewise_construct,
1246 _VSTD::forward_as_tuple(_VSTD::move(__k)),
1247 _VSTD::forward_as_tuple(_VSTD::forward<_Args>(__args)...));
Marshall Clow3223db82015-07-07 03:37:33 +00001248 }
1249
1250 template <class... _Args>
1251 _LIBCPP_INLINE_VISIBILITY
1252 iterator try_emplace(const_iterator __h, const key_type& __k, _Args&&... __args)
1253 {
Eric Fiselierd63f38e2016-03-31 03:13:37 +00001254 return __tree_.__emplace_hint_unique_key_args(__h.__i_, __k,
1255 _VSTD::piecewise_construct,
1256 _VSTD::forward_as_tuple(__k),
Mark de Wever1ba476f2020-09-19 15:39:09 +02001257 _VSTD::forward_as_tuple(_VSTD::forward<_Args>(__args)...)).first;
Marshall Clow3223db82015-07-07 03:37:33 +00001258 }
1259
1260 template <class... _Args>
1261 _LIBCPP_INLINE_VISIBILITY
1262 iterator try_emplace(const_iterator __h, key_type&& __k, _Args&&... __args)
1263 {
Eric Fiselierd63f38e2016-03-31 03:13:37 +00001264 return __tree_.__emplace_hint_unique_key_args(__h.__i_, __k,
1265 _VSTD::piecewise_construct,
1266 _VSTD::forward_as_tuple(_VSTD::move(__k)),
Mark de Wever1ba476f2020-09-19 15:39:09 +02001267 _VSTD::forward_as_tuple(_VSTD::forward<_Args>(__args)...)).first;
Marshall Clow3223db82015-07-07 03:37:33 +00001268 }
1269
1270 template <class _Vp>
1271 _LIBCPP_INLINE_VISIBILITY
1272 pair<iterator, bool> insert_or_assign(const key_type& __k, _Vp&& __v)
1273 {
1274 iterator __p = lower_bound(__k);
1275 if ( __p != end() && !key_comp()(__k, __p->first))
1276 {
1277 __p->second = _VSTD::forward<_Vp>(__v);
1278 return _VSTD::make_pair(__p, false);
1279 }
1280 return _VSTD::make_pair(emplace_hint(__p, __k, _VSTD::forward<_Vp>(__v)), true);
1281 }
Eric Fiselierd63f38e2016-03-31 03:13:37 +00001282
Marshall Clow3223db82015-07-07 03:37:33 +00001283 template <class _Vp>
1284 _LIBCPP_INLINE_VISIBILITY
1285 pair<iterator, bool> insert_or_assign(key_type&& __k, _Vp&& __v)
1286 {
1287 iterator __p = lower_bound(__k);
1288 if ( __p != end() && !key_comp()(__k, __p->first))
1289 {
1290 __p->second = _VSTD::forward<_Vp>(__v);
1291 return _VSTD::make_pair(__p, false);
1292 }
1293 return _VSTD::make_pair(emplace_hint(__p, _VSTD::move(__k), _VSTD::forward<_Vp>(__v)), true);
1294 }
1295
1296 template <class _Vp>
Mark de Wever1ba476f2020-09-19 15:39:09 +02001297 _LIBCPP_INLINE_VISIBILITY iterator insert_or_assign(const_iterator __h,
1298 const key_type& __k,
1299 _Vp&& __v) {
1300 auto [__r, __inserted] = __tree_.__emplace_hint_unique_key_args(
1301 __h.__i_, __k, __k, _VSTD::forward<_Vp>(__v));
1302
1303 if (!__inserted)
1304 __r->__get_value().second = _VSTD::forward<_Vp>(__v);
1305
1306 return __r;
1307 }
Marshall Clow3223db82015-07-07 03:37:33 +00001308
1309 template <class _Vp>
Mark de Wever1ba476f2020-09-19 15:39:09 +02001310 _LIBCPP_INLINE_VISIBILITY iterator insert_or_assign(const_iterator __h,
1311 key_type&& __k,
1312 _Vp&& __v) {
1313 auto [__r, __inserted] = __tree_.__emplace_hint_unique_key_args(
1314 __h.__i_, __k, _VSTD::move(__k), _VSTD::forward<_Vp>(__v));
1315
1316 if (!__inserted)
1317 __r->__get_value().second = _VSTD::forward<_Vp>(__v);
1318
1319 return __r;
1320 }
Eric Fiselierd63f38e2016-03-31 03:13:37 +00001321
Eric Fiseliera85b1282017-04-18 21:08:06 +00001322#endif // _LIBCPP_STD_VER > 14
Marshall Clow3223db82015-07-07 03:37:33 +00001323
Howard Hinnant756c69b2010-09-22 16:48:34 +00001324 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001325 iterator erase(const_iterator __p) {return __tree_.erase(__p.__i_);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001326 _LIBCPP_INLINE_VISIBILITY
Marshall Clow22ea5b82015-05-10 13:35:00 +00001327 iterator erase(iterator __p) {return __tree_.erase(__p.__i_);}
1328 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001329 size_type erase(const key_type& __k)
1330 {return __tree_.__erase_unique(__k);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001331 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001332 iterator erase(const_iterator __f, const_iterator __l)
1333 {return __tree_.erase(__f.__i_, __l.__i_);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001334 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001335 void clear() _NOEXCEPT {__tree_.clear();}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001336
Erik Pilkingtonc37a3d82018-08-01 01:33:38 +00001337#if _LIBCPP_STD_VER > 14
1338 _LIBCPP_INLINE_VISIBILITY
1339 insert_return_type insert(node_type&& __nh)
1340 {
1341 _LIBCPP_ASSERT(__nh.empty() || __nh.get_allocator() == get_allocator(),
1342 "node_type with incompatible allocator passed to map::insert()");
1343 return __tree_.template __node_handle_insert_unique<
1344 node_type, insert_return_type>(_VSTD::move(__nh));
1345 }
1346 _LIBCPP_INLINE_VISIBILITY
1347 iterator insert(const_iterator __hint, node_type&& __nh)
1348 {
1349 _LIBCPP_ASSERT(__nh.empty() || __nh.get_allocator() == get_allocator(),
1350 "node_type with incompatible allocator passed to map::insert()");
1351 return __tree_.template __node_handle_insert_unique<node_type>(
1352 __hint.__i_, _VSTD::move(__nh));
1353 }
1354 _LIBCPP_INLINE_VISIBILITY
1355 node_type extract(key_type const& __key)
1356 {
1357 return __tree_.template __node_handle_extract<node_type>(__key);
1358 }
1359 _LIBCPP_INLINE_VISIBILITY
1360 node_type extract(const_iterator __it)
1361 {
1362 return __tree_.template __node_handle_extract<node_type>(__it.__i_);
1363 }
Louis Dionned2322c82018-11-01 14:41:37 +00001364 template <class _Compare2>
Erik Pilkington82a65ad2018-10-31 17:31:35 +00001365 _LIBCPP_INLINE_VISIBILITY
Louis Dionned2322c82018-11-01 14:41:37 +00001366 void merge(map<key_type, mapped_type, _Compare2, allocator_type>& __source)
Erik Pilkington82a65ad2018-10-31 17:31:35 +00001367 {
1368 _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
1369 "merging container with incompatible allocator");
1370 __tree_.__node_handle_merge_unique(__source.__tree_);
1371 }
Louis Dionned2322c82018-11-01 14:41:37 +00001372 template <class _Compare2>
Erik Pilkington82a65ad2018-10-31 17:31:35 +00001373 _LIBCPP_INLINE_VISIBILITY
Louis Dionned2322c82018-11-01 14:41:37 +00001374 void merge(map<key_type, mapped_type, _Compare2, allocator_type>&& __source)
Erik Pilkington82a65ad2018-10-31 17:31:35 +00001375 {
1376 _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
1377 "merging container with incompatible allocator");
1378 __tree_.__node_handle_merge_unique(__source.__tree_);
1379 }
Louis Dionned2322c82018-11-01 14:41:37 +00001380 template <class _Compare2>
Erik Pilkington82a65ad2018-10-31 17:31:35 +00001381 _LIBCPP_INLINE_VISIBILITY
Louis Dionned2322c82018-11-01 14:41:37 +00001382 void merge(multimap<key_type, mapped_type, _Compare2, allocator_type>& __source)
Erik Pilkington82a65ad2018-10-31 17:31:35 +00001383 {
1384 _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
1385 "merging container with incompatible allocator");
1386 __tree_.__node_handle_merge_unique(__source.__tree_);
1387 }
Louis Dionned2322c82018-11-01 14:41:37 +00001388 template <class _Compare2>
Erik Pilkington82a65ad2018-10-31 17:31:35 +00001389 _LIBCPP_INLINE_VISIBILITY
Louis Dionned2322c82018-11-01 14:41:37 +00001390 void merge(multimap<key_type, mapped_type, _Compare2, allocator_type>&& __source)
Erik Pilkington82a65ad2018-10-31 17:31:35 +00001391 {
1392 _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
1393 "merging container with incompatible allocator");
1394 __tree_.__node_handle_merge_unique(__source.__tree_);
1395 }
Erik Pilkingtonc37a3d82018-08-01 01:33:38 +00001396#endif
1397
Howard Hinnant756c69b2010-09-22 16:48:34 +00001398 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001399 void swap(map& __m)
1400 _NOEXCEPT_(__is_nothrow_swappable<__base>::value)
1401 {__tree_.swap(__m.__tree_);}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001402
Howard Hinnant756c69b2010-09-22 16:48:34 +00001403 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001404 iterator find(const key_type& __k) {return __tree_.find(__k);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001405 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001406 const_iterator find(const key_type& __k) const {return __tree_.find(__k);}
Marshall Clowebb57322013-08-13 22:18:47 +00001407#if _LIBCPP_STD_VER > 11
1408 template <typename _K2>
1409 _LIBCPP_INLINE_VISIBILITY
1410 typename enable_if<__is_transparent<_Compare, _K2>::value,iterator>::type
1411 find(const _K2& __k) {return __tree_.find(__k);}
1412 template <typename _K2>
1413 _LIBCPP_INLINE_VISIBILITY
1414 typename enable_if<__is_transparent<_Compare, _K2>::value,const_iterator>::type
1415 find(const _K2& __k) const {return __tree_.find(__k);}
1416#endif
1417
Howard Hinnant756c69b2010-09-22 16:48:34 +00001418 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001419 size_type count(const key_type& __k) const
1420 {return __tree_.__count_unique(__k);}
Marshall Clowe6a5f522014-08-24 23:54:16 +00001421#if _LIBCPP_STD_VER > 11
1422 template <typename _K2>
1423 _LIBCPP_INLINE_VISIBILITY
1424 typename enable_if<__is_transparent<_Compare, _K2>::value,size_type>::type
Eric Fiseliera85c9e92018-02-10 02:53:47 +00001425 count(const _K2& __k) const {return __tree_.__count_multi(__k);}
Marshall Clowe6a5f522014-08-24 23:54:16 +00001426#endif
Zoe Carver3ffbab12019-07-16 03:21:01 +00001427
1428#if _LIBCPP_STD_VER > 17
1429 _LIBCPP_INLINE_VISIBILITY
1430 bool contains(const key_type& __k) const {return find(__k) != end();}
Marek Kurdejd7e019e2021-04-13 17:10:55 +02001431 template <typename _K2>
1432 _LIBCPP_INLINE_VISIBILITY
1433 typename enable_if<__is_transparent<_Compare, _K2>::value, bool>::type
1434 contains(const _K2& __k) const { return find(__k) != end(); }
Zoe Carver3ffbab12019-07-16 03:21:01 +00001435#endif // _LIBCPP_STD_VER > 17
1436
Howard Hinnant756c69b2010-09-22 16:48:34 +00001437 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001438 iterator lower_bound(const key_type& __k)
1439 {return __tree_.lower_bound(__k);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001440 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001441 const_iterator lower_bound(const key_type& __k) const
1442 {return __tree_.lower_bound(__k);}
Marshall Clowebb57322013-08-13 22:18:47 +00001443#if _LIBCPP_STD_VER > 11
1444 template <typename _K2>
1445 _LIBCPP_INLINE_VISIBILITY
1446 typename enable_if<__is_transparent<_Compare, _K2>::value,iterator>::type
1447 lower_bound(const _K2& __k) {return __tree_.lower_bound(__k);}
1448
1449 template <typename _K2>
1450 _LIBCPP_INLINE_VISIBILITY
1451 typename enable_if<__is_transparent<_Compare, _K2>::value,const_iterator>::type
1452 lower_bound(const _K2& __k) const {return __tree_.lower_bound(__k);}
1453#endif
1454
Howard Hinnant756c69b2010-09-22 16:48:34 +00001455 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001456 iterator upper_bound(const key_type& __k)
1457 {return __tree_.upper_bound(__k);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001458 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001459 const_iterator upper_bound(const key_type& __k) const
1460 {return __tree_.upper_bound(__k);}
Marshall Clowebb57322013-08-13 22:18:47 +00001461#if _LIBCPP_STD_VER > 11
1462 template <typename _K2>
1463 _LIBCPP_INLINE_VISIBILITY
1464 typename enable_if<__is_transparent<_Compare, _K2>::value,iterator>::type
1465 upper_bound(const _K2& __k) {return __tree_.upper_bound(__k);}
1466 template <typename _K2>
1467 _LIBCPP_INLINE_VISIBILITY
1468 typename enable_if<__is_transparent<_Compare, _K2>::value,const_iterator>::type
1469 upper_bound(const _K2& __k) const {return __tree_.upper_bound(__k);}
1470#endif
1471
Howard Hinnant756c69b2010-09-22 16:48:34 +00001472 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001473 pair<iterator,iterator> equal_range(const key_type& __k)
1474 {return __tree_.__equal_range_unique(__k);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001475 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001476 pair<const_iterator,const_iterator> equal_range(const key_type& __k) const
1477 {return __tree_.__equal_range_unique(__k);}
Marshall Clowebb57322013-08-13 22:18:47 +00001478#if _LIBCPP_STD_VER > 11
1479 template <typename _K2>
1480 _LIBCPP_INLINE_VISIBILITY
1481 typename enable_if<__is_transparent<_Compare, _K2>::value,pair<iterator,iterator>>::type
Eric Fiseliera85c9e92018-02-10 02:53:47 +00001482 equal_range(const _K2& __k) {return __tree_.__equal_range_multi(__k);}
Marshall Clowebb57322013-08-13 22:18:47 +00001483 template <typename _K2>
1484 _LIBCPP_INLINE_VISIBILITY
1485 typename enable_if<__is_transparent<_Compare, _K2>::value,pair<const_iterator,const_iterator>>::type
Eric Fiseliera85c9e92018-02-10 02:53:47 +00001486 equal_range(const _K2& __k) const {return __tree_.__equal_range_multi(__k);}
Marshall Clowebb57322013-08-13 22:18:47 +00001487#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001488
1489private:
1490 typedef typename __base::__node __node;
1491 typedef typename __base::__node_allocator __node_allocator;
1492 typedef typename __base::__node_pointer __node_pointer;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001493 typedef typename __base::__node_base_pointer __node_base_pointer;
Eric Fiseliercf8c0212017-01-05 06:06:18 +00001494 typedef typename __base::__parent_pointer __parent_pointer;
Eric Fiseliera92b0732016-02-20 07:12:17 +00001495
Howard Hinnantc834c512011-11-29 18:15:50 +00001496 typedef __map_node_destructor<__node_allocator> _Dp;
1497 typedef unique_ptr<__node, _Dp> __node_holder;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001498
Eric Fiselierd63f38e2016-03-31 03:13:37 +00001499#ifdef _LIBCPP_CXX03_LANG
Howard Hinnantac7e7482013-07-04 20:59:16 +00001500 __node_holder __construct_node_with_key(const key_type& __k);
Eric Fiselierd63f38e2016-03-31 03:13:37 +00001501#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001502};
1503
Louis Dionned23a5f22019-06-20 19:32:00 +00001504#ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES
1505template<class _InputIterator, class _Compare = less<__iter_key_type<_InputIterator>>,
1506 class _Allocator = allocator<__iter_to_alloc_type<_InputIterator>>,
Louis Dionne6c7da9a2019-07-19 17:13:39 +00001507 class = _EnableIf<!__is_allocator<_Compare>::value, void>,
1508 class = _EnableIf<__is_allocator<_Allocator>::value, void>>
Louis Dionned23a5f22019-06-20 19:32:00 +00001509map(_InputIterator, _InputIterator, _Compare = _Compare(), _Allocator = _Allocator())
1510 -> map<__iter_key_type<_InputIterator>, __iter_mapped_type<_InputIterator>, _Compare, _Allocator>;
1511
1512template<class _Key, class _Tp, class _Compare = less<remove_const_t<_Key>>,
1513 class _Allocator = allocator<pair<const _Key, _Tp>>,
Louis Dionne6c7da9a2019-07-19 17:13:39 +00001514 class = _EnableIf<!__is_allocator<_Compare>::value, void>,
1515 class = _EnableIf<__is_allocator<_Allocator>::value, void>>
Louis Dionned23a5f22019-06-20 19:32:00 +00001516map(initializer_list<pair<_Key, _Tp>>, _Compare = _Compare(), _Allocator = _Allocator())
1517 -> map<remove_const_t<_Key>, _Tp, _Compare, _Allocator>;
1518
1519template<class _InputIterator, class _Allocator,
Louis Dionne6c7da9a2019-07-19 17:13:39 +00001520 class = _EnableIf<__is_allocator<_Allocator>::value, void>>
Louis Dionned23a5f22019-06-20 19:32:00 +00001521map(_InputIterator, _InputIterator, _Allocator)
1522 -> map<__iter_key_type<_InputIterator>, __iter_mapped_type<_InputIterator>,
1523 less<__iter_key_type<_InputIterator>>, _Allocator>;
1524
1525template<class _Key, class _Tp, class _Allocator,
Louis Dionne6c7da9a2019-07-19 17:13:39 +00001526 class = _EnableIf<__is_allocator<_Allocator>::value, void>>
Louis Dionned23a5f22019-06-20 19:32:00 +00001527map(initializer_list<pair<_Key, _Tp>>, _Allocator)
1528 -> map<remove_const_t<_Key>, _Tp, less<remove_const_t<_Key>>, _Allocator>;
1529#endif
Eric Fiseliera92b0732016-02-20 07:12:17 +00001530
Eric Fiselierd06276b2016-03-31 02:15:15 +00001531#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001532template <class _Key, class _Tp, class _Compare, class _Allocator>
1533map<_Key, _Tp, _Compare, _Allocator>::map(map&& __m, const allocator_type& __a)
Marshall Clow657cbc42016-08-17 05:58:40 +00001534 : __tree_(_VSTD::move(__m.__tree_), typename __base::allocator_type(__a))
Howard Hinnantc51e1022010-05-11 19:42:16 +00001535{
1536 if (__a != __m.get_allocator())
1537 {
1538 const_iterator __e = cend();
1539 while (!__m.empty())
1540 __tree_.__insert_unique(__e.__i_,
Erik Pilkingtond3fe2992018-06-04 20:38:23 +00001541 __m.__tree_.remove(__m.begin().__i_)->__value_.__move());
Howard Hinnantc51e1022010-05-11 19:42:16 +00001542 }
1543}
1544
Eric Fiseliera85b1282017-04-18 21:08:06 +00001545template <class _Key, class _Tp, class _Compare, class _Allocator>
1546_Tp&
1547map<_Key, _Tp, _Compare, _Allocator>::operator[](const key_type& __k)
1548{
1549 return __tree_.__emplace_unique_key_args(__k,
1550 _VSTD::piecewise_construct,
1551 _VSTD::forward_as_tuple(__k),
Erik Pilkingtond3fe2992018-06-04 20:38:23 +00001552 _VSTD::forward_as_tuple()).first->__get_value().second;
Eric Fiseliera85b1282017-04-18 21:08:06 +00001553}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001554
Eric Fiseliera85b1282017-04-18 21:08:06 +00001555template <class _Key, class _Tp, class _Compare, class _Allocator>
1556_Tp&
1557map<_Key, _Tp, _Compare, _Allocator>::operator[](key_type&& __k)
1558{
1559 return __tree_.__emplace_unique_key_args(__k,
1560 _VSTD::piecewise_construct,
1561 _VSTD::forward_as_tuple(_VSTD::move(__k)),
Erik Pilkingtond3fe2992018-06-04 20:38:23 +00001562 _VSTD::forward_as_tuple()).first->__get_value().second;
Eric Fiseliera85b1282017-04-18 21:08:06 +00001563}
Eric Fiselierd63f38e2016-03-31 03:13:37 +00001564
Eric Fiseliera85b1282017-04-18 21:08:06 +00001565#else // _LIBCPP_CXX03_LANG
Eric Fiselierd63f38e2016-03-31 03:13:37 +00001566
Howard Hinnantc51e1022010-05-11 19:42:16 +00001567template <class _Key, class _Tp, class _Compare, class _Allocator>
1568typename map<_Key, _Tp, _Compare, _Allocator>::__node_holder
Howard Hinnantac7e7482013-07-04 20:59:16 +00001569map<_Key, _Tp, _Compare, _Allocator>::__construct_node_with_key(const key_type& __k)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001570{
1571 __node_allocator& __na = __tree_.__node_alloc();
Howard Hinnantc834c512011-11-29 18:15:50 +00001572 __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
Erik Pilkingtond3fe2992018-06-04 20:38:23 +00001573 __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__get_value().first), __k);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001574 __h.get_deleter().__first_constructed = true;
Erik Pilkingtond3fe2992018-06-04 20:38:23 +00001575 __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__get_value().second));
Howard Hinnantc51e1022010-05-11 19:42:16 +00001576 __h.get_deleter().__second_constructed = true;
Louis Dionne7b844362020-07-30 09:42:23 -04001577 return __h;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001578}
1579
Howard Hinnantc51e1022010-05-11 19:42:16 +00001580template <class _Key, class _Tp, class _Compare, class _Allocator>
1581_Tp&
1582map<_Key, _Tp, _Compare, _Allocator>::operator[](const key_type& __k)
1583{
Eric Fiseliercf8c0212017-01-05 06:06:18 +00001584 __parent_pointer __parent;
1585 __node_base_pointer& __child = __tree_.__find_equal(__parent, __k);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001586 __node_pointer __r = static_cast<__node_pointer>(__child);
1587 if (__child == nullptr)
1588 {
Howard Hinnantac7e7482013-07-04 20:59:16 +00001589 __node_holder __h = __construct_node_with_key(__k);
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001590 __tree_.__insert_node_at(__parent, __child, static_cast<__node_base_pointer>(__h.get()));
Howard Hinnantc51e1022010-05-11 19:42:16 +00001591 __r = __h.release();
1592 }
Erik Pilkingtond3fe2992018-06-04 20:38:23 +00001593 return __r->__value_.__get_value().second;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001594}
1595
Louis Dionne2b1ceaa2021-04-20 12:03:32 -04001596#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001597
1598template <class _Key, class _Tp, class _Compare, class _Allocator>
1599_Tp&
1600map<_Key, _Tp, _Compare, _Allocator>::at(const key_type& __k)
1601{
Eric Fiseliercf8c0212017-01-05 06:06:18 +00001602 __parent_pointer __parent;
1603 __node_base_pointer& __child = __tree_.__find_equal(__parent, __k);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001604 if (__child == nullptr)
Louis Dionne2b239162019-02-12 16:06:02 +00001605 __throw_out_of_range("map::at: key not found");
Erik Pilkingtond3fe2992018-06-04 20:38:23 +00001606 return static_cast<__node_pointer>(__child)->__value_.__get_value().second;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001607}
1608
1609template <class _Key, class _Tp, class _Compare, class _Allocator>
1610const _Tp&
1611map<_Key, _Tp, _Compare, _Allocator>::at(const key_type& __k) const
1612{
Eric Fiseliercf8c0212017-01-05 06:06:18 +00001613 __parent_pointer __parent;
1614 __node_base_pointer __child = __tree_.__find_equal(__parent, __k);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001615 if (__child == nullptr)
Louis Dionne2b239162019-02-12 16:06:02 +00001616 __throw_out_of_range("map::at: key not found");
Erik Pilkingtond3fe2992018-06-04 20:38:23 +00001617 return static_cast<__node_pointer>(__child)->__value_.__get_value().second;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001618}
1619
Howard Hinnantc51e1022010-05-11 19:42:16 +00001620
1621template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001622inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001623bool
1624operator==(const map<_Key, _Tp, _Compare, _Allocator>& __x,
1625 const map<_Key, _Tp, _Compare, _Allocator>& __y)
1626{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001627 return __x.size() == __y.size() && _VSTD::equal(__x.begin(), __x.end(), __y.begin());
Howard Hinnantc51e1022010-05-11 19:42:16 +00001628}
1629
1630template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001631inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001632bool
1633operator< (const map<_Key, _Tp, _Compare, _Allocator>& __x,
1634 const map<_Key, _Tp, _Compare, _Allocator>& __y)
1635{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001636 return _VSTD::lexicographical_compare(__x.begin(), __x.end(), __y.begin(), __y.end());
Howard Hinnantc51e1022010-05-11 19:42:16 +00001637}
1638
1639template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001640inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001641bool
1642operator!=(const map<_Key, _Tp, _Compare, _Allocator>& __x,
1643 const map<_Key, _Tp, _Compare, _Allocator>& __y)
1644{
1645 return !(__x == __y);
1646}
1647
1648template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001649inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001650bool
1651operator> (const map<_Key, _Tp, _Compare, _Allocator>& __x,
1652 const map<_Key, _Tp, _Compare, _Allocator>& __y)
1653{
1654 return __y < __x;
1655}
1656
1657template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001658inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001659bool
1660operator>=(const map<_Key, _Tp, _Compare, _Allocator>& __x,
1661 const map<_Key, _Tp, _Compare, _Allocator>& __y)
1662{
1663 return !(__x < __y);
1664}
1665
1666template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001667inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001668bool
1669operator<=(const map<_Key, _Tp, _Compare, _Allocator>& __x,
1670 const map<_Key, _Tp, _Compare, _Allocator>& __y)
1671{
1672 return !(__y < __x);
1673}
1674
1675template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001676inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001677void
1678swap(map<_Key, _Tp, _Compare, _Allocator>& __x,
1679 map<_Key, _Tp, _Compare, _Allocator>& __y)
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001680 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
Howard Hinnantc51e1022010-05-11 19:42:16 +00001681{
1682 __x.swap(__y);
1683}
1684
Marshall Clow29b53f22018-12-14 18:49:35 +00001685#if _LIBCPP_STD_VER > 17
Marek Kurdeja98b1412020-05-02 13:58:03 +02001686template <class _Key, class _Tp, class _Compare, class _Allocator,
1687 class _Predicate>
Marshall Clow29b53f22018-12-14 18:49:35 +00001688inline _LIBCPP_INLINE_VISIBILITY
Marek Kurdeja98b1412020-05-02 13:58:03 +02001689 typename map<_Key, _Tp, _Compare, _Allocator>::size_type
1690 erase_if(map<_Key, _Tp, _Compare, _Allocator>& __c, _Predicate __pred) {
Arthur O'Dwyerb6738bd2021-03-21 16:53:09 -04001691 return _VSTD::__libcpp_erase_if_container(__c, __pred);
Marek Kurdeja98b1412020-05-02 13:58:03 +02001692}
Marshall Clow29b53f22018-12-14 18:49:35 +00001693#endif
1694
1695
Howard Hinnantc51e1022010-05-11 19:42:16 +00001696template <class _Key, class _Tp, class _Compare = less<_Key>,
1697 class _Allocator = allocator<pair<const _Key, _Tp> > >
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00001698class _LIBCPP_TEMPLATE_VIS multimap
Howard Hinnantc51e1022010-05-11 19:42:16 +00001699{
1700public:
1701 // types:
1702 typedef _Key key_type;
1703 typedef _Tp mapped_type;
1704 typedef pair<const key_type, mapped_type> value_type;
Arthur O'Dwyer6a752e12021-03-03 11:10:49 -05001705 typedef __identity_t<_Compare> key_compare;
1706 typedef __identity_t<_Allocator> allocator_type;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001707 typedef value_type& reference;
1708 typedef const value_type& const_reference;
1709
Marshall Clow5128cf32015-11-26 01:24:04 +00001710 static_assert((is_same<typename allocator_type::value_type, value_type>::value),
1711 "Allocator::value_type must be same type as value_type");
1712
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -04001713_LIBCPP_SUPPRESS_DEPRECATED_PUSH
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00001714 class _LIBCPP_TEMPLATE_VIS value_compare
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -04001715#if defined(_LIBCPP_ENABLE_CXX20_REMOVED_BINDER_TYPEDEFS)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001716 : public binary_function<value_type, value_type, bool>
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -04001717#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001718 {
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -04001719_LIBCPP_SUPPRESS_DEPRECATED_POP
Howard Hinnantc51e1022010-05-11 19:42:16 +00001720 friend class multimap;
1721 protected:
1722 key_compare comp;
1723
Howard Hinnant756c69b2010-09-22 16:48:34 +00001724 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001725 value_compare(key_compare c) : comp(c) {}
1726 public:
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -04001727#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_BINDER_TYPEDEFS)
1728 _LIBCPP_DEPRECATED_IN_CXX17 typedef bool result_type;
1729 _LIBCPP_DEPRECATED_IN_CXX17 typedef value_type first_argument_type;
1730 _LIBCPP_DEPRECATED_IN_CXX17 typedef value_type second_argument_type;
1731#endif
Howard Hinnant756c69b2010-09-22 16:48:34 +00001732 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001733 bool operator()(const value_type& __x, const value_type& __y) const
1734 {return comp(__x.first, __y.first);}
1735 };
1736
1737private:
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001738
Howard Hinnant89f8b792013-09-30 19:08:22 +00001739 typedef _VSTD::__value_type<key_type, mapped_type> __value_type;
Howard Hinnant90b91592013-07-05 18:06:00 +00001740 typedef __map_value_compare<key_type, __value_type, key_compare> __vc;
Marshall Clow940e01c2015-04-07 05:21:38 +00001741 typedef typename __rebind_alloc_helper<allocator_traits<allocator_type>,
1742 __value_type>::type __allocator_type;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001743 typedef __tree<__value_type, __vc, __allocator_type> __base;
1744 typedef typename __base::__node_traits __node_traits;
1745 typedef allocator_traits<allocator_type> __alloc_traits;
1746
1747 __base __tree_;
1748
1749public:
1750 typedef typename __alloc_traits::pointer pointer;
1751 typedef typename __alloc_traits::const_pointer const_pointer;
1752 typedef typename __alloc_traits::size_type size_type;
1753 typedef typename __alloc_traits::difference_type difference_type;
1754 typedef __map_iterator<typename __base::iterator> iterator;
1755 typedef __map_const_iterator<typename __base::const_iterator> const_iterator;
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001756 typedef _VSTD::reverse_iterator<iterator> reverse_iterator;
1757 typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001758
Erik Pilkingtonc37a3d82018-08-01 01:33:38 +00001759#if _LIBCPP_STD_VER > 14
1760 typedef __map_node_handle<typename __base::__node, allocator_type> node_type;
1761#endif
1762
Erik Pilkington82a65ad2018-10-31 17:31:35 +00001763 template <class _Key2, class _Value2, class _Comp2, class _Alloc2>
1764 friend class _LIBCPP_TEMPLATE_VIS map;
1765 template <class _Key2, class _Value2, class _Comp2, class _Alloc2>
1766 friend class _LIBCPP_TEMPLATE_VIS multimap;
1767
Howard Hinnant756c69b2010-09-22 16:48:34 +00001768 _LIBCPP_INLINE_VISIBILITY
Marshall Clow7086a5a2014-03-10 04:50:10 +00001769 multimap()
1770 _NOEXCEPT_(
1771 is_nothrow_default_constructible<allocator_type>::value &&
1772 is_nothrow_default_constructible<key_compare>::value &&
1773 is_nothrow_copy_constructible<key_compare>::value)
1774 : __tree_(__vc(key_compare())) {}
1775
1776 _LIBCPP_INLINE_VISIBILITY
1777 explicit multimap(const key_compare& __comp)
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001778 _NOEXCEPT_(
1779 is_nothrow_default_constructible<allocator_type>::value &&
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001780 is_nothrow_copy_constructible<key_compare>::value)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001781 : __tree_(__vc(__comp)) {}
1782
Howard Hinnant756c69b2010-09-22 16:48:34 +00001783 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001784 explicit multimap(const key_compare& __comp, const allocator_type& __a)
Marshall Clow657cbc42016-08-17 05:58:40 +00001785 : __tree_(__vc(__comp), typename __base::allocator_type(__a)) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001786
1787 template <class _InputIterator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001788 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001789 multimap(_InputIterator __f, _InputIterator __l,
1790 const key_compare& __comp = key_compare())
1791 : __tree_(__vc(__comp))
1792 {
1793 insert(__f, __l);
1794 }
1795
1796 template <class _InputIterator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001797 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001798 multimap(_InputIterator __f, _InputIterator __l,
1799 const key_compare& __comp, const allocator_type& __a)
Marshall Clow657cbc42016-08-17 05:58:40 +00001800 : __tree_(__vc(__comp), typename __base::allocator_type(__a))
Howard Hinnantc51e1022010-05-11 19:42:16 +00001801 {
1802 insert(__f, __l);
1803 }
1804
Marshall Clow300abfb2013-09-11 01:15:47 +00001805#if _LIBCPP_STD_VER > 11
1806 template <class _InputIterator>
Eric Fiseliercf8c0212017-01-05 06:06:18 +00001807 _LIBCPP_INLINE_VISIBILITY
Marshall Clow300abfb2013-09-11 01:15:47 +00001808 multimap(_InputIterator __f, _InputIterator __l, const allocator_type& __a)
1809 : multimap(__f, __l, key_compare(), __a) {}
1810#endif
1811
Howard Hinnant756c69b2010-09-22 16:48:34 +00001812 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001813 multimap(const multimap& __m)
1814 : __tree_(__m.__tree_.value_comp(),
1815 __alloc_traits::select_on_container_copy_construction(__m.__tree_.__alloc()))
1816 {
1817 insert(__m.begin(), __m.end());
1818 }
1819
Howard Hinnantd3a657f2011-07-01 19:24:36 +00001820 _LIBCPP_INLINE_VISIBILITY
1821 multimap& operator=(const multimap& __m)
1822 {
Marshall Clow476d3f42016-07-18 13:19:00 +00001823#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantd3a657f2011-07-01 19:24:36 +00001824 __tree_ = __m.__tree_;
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001825#else
Marshall Clowdb3cfcb2014-02-08 04:03:14 +00001826 if (this != &__m) {
1827 __tree_.clear();
1828 __tree_.value_comp() = __m.__tree_.value_comp();
1829 __tree_.__copy_assign_alloc(__m.__tree_);
1830 insert(__m.begin(), __m.end());
1831 }
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001832#endif
Howard Hinnantd3a657f2011-07-01 19:24:36 +00001833 return *this;
1834 }
1835
Eric Fiseliera85b1282017-04-18 21:08:06 +00001836#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001837
Howard Hinnant756c69b2010-09-22 16:48:34 +00001838 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001839 multimap(multimap&& __m)
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001840 _NOEXCEPT_(is_nothrow_move_constructible<__base>::value)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001841 : __tree_(_VSTD::move(__m.__tree_))
Howard Hinnantc51e1022010-05-11 19:42:16 +00001842 {
1843 }
1844
1845 multimap(multimap&& __m, const allocator_type& __a);
1846
Howard Hinnant756c69b2010-09-22 16:48:34 +00001847 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant33711792011-08-12 21:56:02 +00001848 multimap& operator=(multimap&& __m)
1849 _NOEXCEPT_(is_nothrow_move_assignable<__base>::value)
1850 {
1851 __tree_ = _VSTD::move(__m.__tree_);
1852 return *this;
1853 }
1854
Howard Hinnant33711792011-08-12 21:56:02 +00001855 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001856 multimap(initializer_list<value_type> __il, const key_compare& __comp = key_compare())
1857 : __tree_(__vc(__comp))
1858 {
1859 insert(__il.begin(), __il.end());
1860 }
1861
Howard Hinnant756c69b2010-09-22 16:48:34 +00001862 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001863 multimap(initializer_list<value_type> __il, const key_compare& __comp, const allocator_type& __a)
Marshall Clow657cbc42016-08-17 05:58:40 +00001864 : __tree_(__vc(__comp), typename __base::allocator_type(__a))
Howard Hinnantc51e1022010-05-11 19:42:16 +00001865 {
1866 insert(__il.begin(), __il.end());
1867 }
1868
Marshall Clow300abfb2013-09-11 01:15:47 +00001869#if _LIBCPP_STD_VER > 11
Eric Fiseliercf8c0212017-01-05 06:06:18 +00001870 _LIBCPP_INLINE_VISIBILITY
Marshall Clow300abfb2013-09-11 01:15:47 +00001871 multimap(initializer_list<value_type> __il, const allocator_type& __a)
1872 : multimap(__il, key_compare(), __a) {}
1873#endif
1874
Howard Hinnant756c69b2010-09-22 16:48:34 +00001875 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001876 multimap& operator=(initializer_list<value_type> __il)
1877 {
1878 __tree_.__assign_multi(__il.begin(), __il.end());
1879 return *this;
1880 }
Howard Hinnant33711792011-08-12 21:56:02 +00001881
Louis Dionne2b1ceaa2021-04-20 12:03:32 -04001882#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001883
Howard Hinnant756c69b2010-09-22 16:48:34 +00001884 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001885 explicit multimap(const allocator_type& __a)
Marshall Clow657cbc42016-08-17 05:58:40 +00001886 : __tree_(typename __base::allocator_type(__a))
Howard Hinnantc51e1022010-05-11 19:42:16 +00001887 {
1888 }
1889
Howard Hinnant756c69b2010-09-22 16:48:34 +00001890 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001891 multimap(const multimap& __m, const allocator_type& __a)
Marshall Clow657cbc42016-08-17 05:58:40 +00001892 : __tree_(__m.__tree_.value_comp(), typename __base::allocator_type(__a))
Howard Hinnantc51e1022010-05-11 19:42:16 +00001893 {
1894 insert(__m.begin(), __m.end());
1895 }
1896
Howard Hinnant756c69b2010-09-22 16:48:34 +00001897 _LIBCPP_INLINE_VISIBILITY
Louis Dionne69c42c02019-04-11 16:14:56 +00001898 ~multimap() {
1899 static_assert(sizeof(__diagnose_non_const_comparator<_Key, _Compare>()), "");
1900 }
1901
1902 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001903 iterator begin() _NOEXCEPT {return __tree_.begin();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001904 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001905 const_iterator begin() const _NOEXCEPT {return __tree_.begin();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001906 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001907 iterator end() _NOEXCEPT {return __tree_.end();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001908 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001909 const_iterator end() const _NOEXCEPT {return __tree_.end();}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001910
Howard Hinnant756c69b2010-09-22 16:48:34 +00001911 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001912 reverse_iterator rbegin() _NOEXCEPT {return reverse_iterator(end());}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001913 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001914 const_reverse_iterator rbegin() const _NOEXCEPT
1915 {return const_reverse_iterator(end());}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001916 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001917 reverse_iterator rend() _NOEXCEPT {return reverse_iterator(begin());}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001918 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001919 const_reverse_iterator rend() const _NOEXCEPT
1920 {return const_reverse_iterator(begin());}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001921
Howard Hinnant756c69b2010-09-22 16:48:34 +00001922 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001923 const_iterator cbegin() const _NOEXCEPT {return begin();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001924 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001925 const_iterator cend() const _NOEXCEPT {return end();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001926 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001927 const_reverse_iterator crbegin() const _NOEXCEPT {return rbegin();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001928 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001929 const_reverse_iterator crend() const _NOEXCEPT {return rend();}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001930
Marshall Clow425f5752017-11-15 05:51:26 +00001931 _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001932 bool empty() const _NOEXCEPT {return __tree_.size() == 0;}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001933 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001934 size_type size() const _NOEXCEPT {return __tree_.size();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001935 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001936 size_type max_size() const _NOEXCEPT {return __tree_.max_size();}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001937
Howard Hinnant756c69b2010-09-22 16:48:34 +00001938 _LIBCPP_INLINE_VISIBILITY
Marshall Clow657cbc42016-08-17 05:58:40 +00001939 allocator_type get_allocator() const _NOEXCEPT {return allocator_type(__tree_.__alloc());}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001940 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001941 key_compare key_comp() const {return __tree_.value_comp().key_comp();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001942 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001943 value_compare value_comp() const
1944 {return value_compare(__tree_.value_comp().key_comp());}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001945
Eric Fiselierd06276b2016-03-31 02:15:15 +00001946#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant74279a52010-09-04 23:28:19 +00001947
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001948 template <class ..._Args>
Eric Fiselierd06276b2016-03-31 02:15:15 +00001949 _LIBCPP_INLINE_VISIBILITY
1950 iterator emplace(_Args&& ...__args) {
1951 return __tree_.__emplace_multi(_VSTD::forward<_Args>(__args)...);
1952 }
Howard Hinnantc51e1022010-05-11 19:42:16 +00001953
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001954 template <class ..._Args>
Eric Fiselierd06276b2016-03-31 02:15:15 +00001955 _LIBCPP_INLINE_VISIBILITY
1956 iterator emplace_hint(const_iterator __p, _Args&& ...__args) {
1957 return __tree_.__emplace_hint_multi(__p.__i_, _VSTD::forward<_Args>(__args)...);
1958 }
Howard Hinnant74279a52010-09-04 23:28:19 +00001959
Howard Hinnantc834c512011-11-29 18:15:50 +00001960 template <class _Pp,
1961 class = typename enable_if<is_constructible<value_type, _Pp>::value>::type>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001962 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc834c512011-11-29 18:15:50 +00001963 iterator insert(_Pp&& __p)
1964 {return __tree_.__insert_multi(_VSTD::forward<_Pp>(__p));}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001965
Howard Hinnantc834c512011-11-29 18:15:50 +00001966 template <class _Pp,
1967 class = typename enable_if<is_constructible<value_type, _Pp>::value>::type>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001968 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc834c512011-11-29 18:15:50 +00001969 iterator insert(const_iterator __pos, _Pp&& __p)
1970 {return __tree_.__insert_multi(__pos.__i_, _VSTD::forward<_Pp>(__p));}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001971
Eric Fiselierd6143132016-04-18 01:40:45 +00001972 _LIBCPP_INLINE_VISIBILITY
1973 iterator insert(value_type&& __v)
1974 {return __tree_.__insert_multi(_VSTD::move(__v));}
1975
1976 _LIBCPP_INLINE_VISIBILITY
1977 iterator insert(const_iterator __p, value_type&& __v)
1978 {return __tree_.__insert_multi(__p.__i_, _VSTD::move(__v));}
1979
Eric Fiseliera85b1282017-04-18 21:08:06 +00001980
1981 _LIBCPP_INLINE_VISIBILITY
1982 void insert(initializer_list<value_type> __il)
1983 {insert(__il.begin(), __il.end());}
1984
Louis Dionne2b1ceaa2021-04-20 12:03:32 -04001985#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001986
Howard Hinnant756c69b2010-09-22 16:48:34 +00001987 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001988 iterator insert(const value_type& __v) {return __tree_.__insert_multi(__v);}
1989
Howard Hinnant756c69b2010-09-22 16:48:34 +00001990 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001991 iterator insert(const_iterator __p, const value_type& __v)
1992 {return __tree_.__insert_multi(__p.__i_, __v);}
1993
1994 template <class _InputIterator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001995 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001996 void insert(_InputIterator __f, _InputIterator __l)
1997 {
1998 for (const_iterator __e = cend(); __f != __l; ++__f)
1999 __tree_.__insert_multi(__e.__i_, *__f);
2000 }
2001
Howard Hinnant756c69b2010-09-22 16:48:34 +00002002 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002003 iterator erase(const_iterator __p) {return __tree_.erase(__p.__i_);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00002004 _LIBCPP_INLINE_VISIBILITY
Marshall Clow22ea5b82015-05-10 13:35:00 +00002005 iterator erase(iterator __p) {return __tree_.erase(__p.__i_);}
2006 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002007 size_type erase(const key_type& __k) {return __tree_.__erase_multi(__k);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00002008 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002009 iterator erase(const_iterator __f, const_iterator __l)
2010 {return __tree_.erase(__f.__i_, __l.__i_);}
Erik Pilkingtonc37a3d82018-08-01 01:33:38 +00002011
2012#if _LIBCPP_STD_VER > 14
2013 _LIBCPP_INLINE_VISIBILITY
2014 iterator insert(node_type&& __nh)
2015 {
2016 _LIBCPP_ASSERT(__nh.empty() || __nh.get_allocator() == get_allocator(),
2017 "node_type with incompatible allocator passed to multimap::insert()");
2018 return __tree_.template __node_handle_insert_multi<node_type>(
2019 _VSTD::move(__nh));
2020 }
2021 _LIBCPP_INLINE_VISIBILITY
2022 iterator insert(const_iterator __hint, node_type&& __nh)
2023 {
2024 _LIBCPP_ASSERT(__nh.empty() || __nh.get_allocator() == get_allocator(),
2025 "node_type with incompatible allocator passed to multimap::insert()");
2026 return __tree_.template __node_handle_insert_multi<node_type>(
2027 __hint.__i_, _VSTD::move(__nh));
2028 }
2029 _LIBCPP_INLINE_VISIBILITY
2030 node_type extract(key_type const& __key)
2031 {
2032 return __tree_.template __node_handle_extract<node_type>(__key);
2033 }
2034 _LIBCPP_INLINE_VISIBILITY
2035 node_type extract(const_iterator __it)
2036 {
2037 return __tree_.template __node_handle_extract<node_type>(
2038 __it.__i_);
2039 }
Louis Dionned2322c82018-11-01 14:41:37 +00002040 template <class _Compare2>
Erik Pilkington82a65ad2018-10-31 17:31:35 +00002041 _LIBCPP_INLINE_VISIBILITY
Louis Dionned2322c82018-11-01 14:41:37 +00002042 void merge(multimap<key_type, mapped_type, _Compare2, allocator_type>& __source)
Erik Pilkington82a65ad2018-10-31 17:31:35 +00002043 {
2044 _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
2045 "merging container with incompatible allocator");
2046 return __tree_.__node_handle_merge_multi(__source.__tree_);
2047 }
Louis Dionned2322c82018-11-01 14:41:37 +00002048 template <class _Compare2>
Erik Pilkington82a65ad2018-10-31 17:31:35 +00002049 _LIBCPP_INLINE_VISIBILITY
Louis Dionned2322c82018-11-01 14:41:37 +00002050 void merge(multimap<key_type, mapped_type, _Compare2, allocator_type>&& __source)
Erik Pilkington82a65ad2018-10-31 17:31:35 +00002051 {
2052 _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
2053 "merging container with incompatible allocator");
2054 return __tree_.__node_handle_merge_multi(__source.__tree_);
2055 }
Louis Dionned2322c82018-11-01 14:41:37 +00002056 template <class _Compare2>
Erik Pilkington82a65ad2018-10-31 17:31:35 +00002057 _LIBCPP_INLINE_VISIBILITY
Louis Dionned2322c82018-11-01 14:41:37 +00002058 void merge(map<key_type, mapped_type, _Compare2, allocator_type>& __source)
Erik Pilkington82a65ad2018-10-31 17:31:35 +00002059 {
2060 _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
2061 "merging container with incompatible allocator");
2062 return __tree_.__node_handle_merge_multi(__source.__tree_);
2063 }
Louis Dionned2322c82018-11-01 14:41:37 +00002064 template <class _Compare2>
Erik Pilkington82a65ad2018-10-31 17:31:35 +00002065 _LIBCPP_INLINE_VISIBILITY
Louis Dionned2322c82018-11-01 14:41:37 +00002066 void merge(map<key_type, mapped_type, _Compare2, allocator_type>&& __source)
Erik Pilkington82a65ad2018-10-31 17:31:35 +00002067 {
2068 _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
2069 "merging container with incompatible allocator");
2070 return __tree_.__node_handle_merge_multi(__source.__tree_);
2071 }
Erik Pilkingtonc37a3d82018-08-01 01:33:38 +00002072#endif
2073
Howard Hinnant756c69b2010-09-22 16:48:34 +00002074 _LIBCPP_INLINE_VISIBILITY
Marshall Clowde1312a2018-08-22 04:28:43 +00002075 void clear() _NOEXCEPT {__tree_.clear();}
Howard Hinnantc51e1022010-05-11 19:42:16 +00002076
Howard Hinnant756c69b2010-09-22 16:48:34 +00002077 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00002078 void swap(multimap& __m)
2079 _NOEXCEPT_(__is_nothrow_swappable<__base>::value)
2080 {__tree_.swap(__m.__tree_);}
Howard Hinnantc51e1022010-05-11 19:42:16 +00002081
Howard Hinnant756c69b2010-09-22 16:48:34 +00002082 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002083 iterator find(const key_type& __k) {return __tree_.find(__k);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00002084 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002085 const_iterator find(const key_type& __k) const {return __tree_.find(__k);}
Marshall Clowebb57322013-08-13 22:18:47 +00002086#if _LIBCPP_STD_VER > 11
2087 template <typename _K2>
2088 _LIBCPP_INLINE_VISIBILITY
2089 typename enable_if<__is_transparent<_Compare, _K2>::value,iterator>::type
2090 find(const _K2& __k) {return __tree_.find(__k);}
2091 template <typename _K2>
2092 _LIBCPP_INLINE_VISIBILITY
2093 typename enable_if<__is_transparent<_Compare, _K2>::value,const_iterator>::type
2094 find(const _K2& __k) const {return __tree_.find(__k);}
2095#endif
2096
Howard Hinnant756c69b2010-09-22 16:48:34 +00002097 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002098 size_type count(const key_type& __k) const
2099 {return __tree_.__count_multi(__k);}
Marshall Clowe6a5f522014-08-24 23:54:16 +00002100#if _LIBCPP_STD_VER > 11
2101 template <typename _K2>
2102 _LIBCPP_INLINE_VISIBILITY
2103 typename enable_if<__is_transparent<_Compare, _K2>::value,size_type>::type
Marshall Clow141e47b2015-06-30 18:15:41 +00002104 count(const _K2& __k) const {return __tree_.__count_multi(__k);}
Marshall Clowe6a5f522014-08-24 23:54:16 +00002105#endif
Zoe Carver3ffbab12019-07-16 03:21:01 +00002106
2107#if _LIBCPP_STD_VER > 17
2108 _LIBCPP_INLINE_VISIBILITY
2109 bool contains(const key_type& __k) const {return find(__k) != end();}
Marek Kurdejd7e019e2021-04-13 17:10:55 +02002110 template <typename _K2>
2111 _LIBCPP_INLINE_VISIBILITY
2112 typename enable_if<__is_transparent<_Compare, _K2>::value, bool>::type
2113 contains(const _K2& __k) const { return find(__k) != end(); }
Zoe Carver3ffbab12019-07-16 03:21:01 +00002114#endif // _LIBCPP_STD_VER > 17
2115
Howard Hinnant756c69b2010-09-22 16:48:34 +00002116 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002117 iterator lower_bound(const key_type& __k)
2118 {return __tree_.lower_bound(__k);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00002119 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002120 const_iterator lower_bound(const key_type& __k) const
2121 {return __tree_.lower_bound(__k);}
Marshall Clowebb57322013-08-13 22:18:47 +00002122#if _LIBCPP_STD_VER > 11
2123 template <typename _K2>
2124 _LIBCPP_INLINE_VISIBILITY
2125 typename enable_if<__is_transparent<_Compare, _K2>::value,iterator>::type
2126 lower_bound(const _K2& __k) {return __tree_.lower_bound(__k);}
2127
2128 template <typename _K2>
2129 _LIBCPP_INLINE_VISIBILITY
2130 typename enable_if<__is_transparent<_Compare, _K2>::value,const_iterator>::type
2131 lower_bound(const _K2& __k) const {return __tree_.lower_bound(__k);}
2132#endif
2133
Howard Hinnant756c69b2010-09-22 16:48:34 +00002134 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002135 iterator upper_bound(const key_type& __k)
2136 {return __tree_.upper_bound(__k);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00002137 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002138 const_iterator upper_bound(const key_type& __k) const
2139 {return __tree_.upper_bound(__k);}
Marshall Clowebb57322013-08-13 22:18:47 +00002140#if _LIBCPP_STD_VER > 11
2141 template <typename _K2>
2142 _LIBCPP_INLINE_VISIBILITY
2143 typename enable_if<__is_transparent<_Compare, _K2>::value,iterator>::type
2144 upper_bound(const _K2& __k) {return __tree_.upper_bound(__k);}
2145 template <typename _K2>
2146 _LIBCPP_INLINE_VISIBILITY
2147 typename enable_if<__is_transparent<_Compare, _K2>::value,const_iterator>::type
2148 upper_bound(const _K2& __k) const {return __tree_.upper_bound(__k);}
2149#endif
2150
Howard Hinnant756c69b2010-09-22 16:48:34 +00002151 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002152 pair<iterator,iterator> equal_range(const key_type& __k)
2153 {return __tree_.__equal_range_multi(__k);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00002154 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002155 pair<const_iterator,const_iterator> equal_range(const key_type& __k) const
2156 {return __tree_.__equal_range_multi(__k);}
Marshall Clowebb57322013-08-13 22:18:47 +00002157#if _LIBCPP_STD_VER > 11
2158 template <typename _K2>
2159 _LIBCPP_INLINE_VISIBILITY
2160 typename enable_if<__is_transparent<_Compare, _K2>::value,pair<iterator,iterator>>::type
2161 equal_range(const _K2& __k) {return __tree_.__equal_range_multi(__k);}
2162 template <typename _K2>
2163 _LIBCPP_INLINE_VISIBILITY
2164 typename enable_if<__is_transparent<_Compare, _K2>::value,pair<const_iterator,const_iterator>>::type
2165 equal_range(const _K2& __k) const {return __tree_.__equal_range_multi(__k);}
2166#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00002167
2168private:
2169 typedef typename __base::__node __node;
2170 typedef typename __base::__node_allocator __node_allocator;
2171 typedef typename __base::__node_pointer __node_pointer;
Eric Fiseliera92b0732016-02-20 07:12:17 +00002172
Howard Hinnantc834c512011-11-29 18:15:50 +00002173 typedef __map_node_destructor<__node_allocator> _Dp;
2174 typedef unique_ptr<__node, _Dp> __node_holder;
Howard Hinnantc51e1022010-05-11 19:42:16 +00002175};
2176
Louis Dionned23a5f22019-06-20 19:32:00 +00002177#ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES
2178template<class _InputIterator, class _Compare = less<__iter_key_type<_InputIterator>>,
2179 class _Allocator = allocator<__iter_to_alloc_type<_InputIterator>>,
Louis Dionne6c7da9a2019-07-19 17:13:39 +00002180 class = _EnableIf<!__is_allocator<_Compare>::value, void>,
2181 class = _EnableIf<__is_allocator<_Allocator>::value, void>>
Louis Dionned23a5f22019-06-20 19:32:00 +00002182multimap(_InputIterator, _InputIterator, _Compare = _Compare(), _Allocator = _Allocator())
2183 -> multimap<__iter_key_type<_InputIterator>, __iter_mapped_type<_InputIterator>, _Compare, _Allocator>;
2184
2185template<class _Key, class _Tp, class _Compare = less<remove_const_t<_Key>>,
2186 class _Allocator = allocator<pair<const _Key, _Tp>>,
Louis Dionne6c7da9a2019-07-19 17:13:39 +00002187 class = _EnableIf<!__is_allocator<_Compare>::value, void>,
2188 class = _EnableIf<__is_allocator<_Allocator>::value, void>>
Louis Dionned23a5f22019-06-20 19:32:00 +00002189multimap(initializer_list<pair<_Key, _Tp>>, _Compare = _Compare(), _Allocator = _Allocator())
2190 -> multimap<remove_const_t<_Key>, _Tp, _Compare, _Allocator>;
2191
2192template<class _InputIterator, class _Allocator,
Louis Dionne6c7da9a2019-07-19 17:13:39 +00002193 class = _EnableIf<__is_allocator<_Allocator>::value, void>>
Louis Dionned23a5f22019-06-20 19:32:00 +00002194multimap(_InputIterator, _InputIterator, _Allocator)
2195 -> multimap<__iter_key_type<_InputIterator>, __iter_mapped_type<_InputIterator>,
2196 less<__iter_key_type<_InputIterator>>, _Allocator>;
2197
2198template<class _Key, class _Tp, class _Allocator,
Louis Dionne6c7da9a2019-07-19 17:13:39 +00002199 class = _EnableIf<__is_allocator<_Allocator>::value, void>>
Louis Dionned23a5f22019-06-20 19:32:00 +00002200multimap(initializer_list<pair<_Key, _Tp>>, _Allocator)
2201 -> multimap<remove_const_t<_Key>, _Tp, less<remove_const_t<_Key>>, _Allocator>;
2202#endif
2203
Eric Fiselierd06276b2016-03-31 02:15:15 +00002204#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00002205template <class _Key, class _Tp, class _Compare, class _Allocator>
2206multimap<_Key, _Tp, _Compare, _Allocator>::multimap(multimap&& __m, const allocator_type& __a)
Marshall Clow657cbc42016-08-17 05:58:40 +00002207 : __tree_(_VSTD::move(__m.__tree_), typename __base::allocator_type(__a))
Howard Hinnantc51e1022010-05-11 19:42:16 +00002208{
2209 if (__a != __m.get_allocator())
2210 {
2211 const_iterator __e = cend();
2212 while (!__m.empty())
2213 __tree_.__insert_multi(__e.__i_,
Erik Pilkingtond3fe2992018-06-04 20:38:23 +00002214 _VSTD::move(__m.__tree_.remove(__m.begin().__i_)->__value_.__move()));
Howard Hinnantc51e1022010-05-11 19:42:16 +00002215 }
2216}
Eric Fiselierd06276b2016-03-31 02:15:15 +00002217#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00002218
2219template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00002220inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002221bool
2222operator==(const multimap<_Key, _Tp, _Compare, _Allocator>& __x,
2223 const multimap<_Key, _Tp, _Compare, _Allocator>& __y)
2224{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00002225 return __x.size() == __y.size() && _VSTD::equal(__x.begin(), __x.end(), __y.begin());
Howard Hinnantc51e1022010-05-11 19:42:16 +00002226}
2227
2228template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00002229inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002230bool
2231operator< (const multimap<_Key, _Tp, _Compare, _Allocator>& __x,
2232 const multimap<_Key, _Tp, _Compare, _Allocator>& __y)
2233{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00002234 return _VSTD::lexicographical_compare(__x.begin(), __x.end(), __y.begin(), __y.end());
Howard Hinnantc51e1022010-05-11 19:42:16 +00002235}
2236
2237template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00002238inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002239bool
2240operator!=(const multimap<_Key, _Tp, _Compare, _Allocator>& __x,
2241 const multimap<_Key, _Tp, _Compare, _Allocator>& __y)
2242{
2243 return !(__x == __y);
2244}
2245
2246template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00002247inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002248bool
2249operator> (const multimap<_Key, _Tp, _Compare, _Allocator>& __x,
2250 const multimap<_Key, _Tp, _Compare, _Allocator>& __y)
2251{
2252 return __y < __x;
2253}
2254
2255template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00002256inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002257bool
2258operator>=(const multimap<_Key, _Tp, _Compare, _Allocator>& __x,
2259 const multimap<_Key, _Tp, _Compare, _Allocator>& __y)
2260{
2261 return !(__x < __y);
2262}
2263
2264template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00002265inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002266bool
2267operator<=(const multimap<_Key, _Tp, _Compare, _Allocator>& __x,
2268 const multimap<_Key, _Tp, _Compare, _Allocator>& __y)
2269{
2270 return !(__y < __x);
2271}
2272
2273template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00002274inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002275void
2276swap(multimap<_Key, _Tp, _Compare, _Allocator>& __x,
2277 multimap<_Key, _Tp, _Compare, _Allocator>& __y)
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00002278 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
Howard Hinnantc51e1022010-05-11 19:42:16 +00002279{
2280 __x.swap(__y);
2281}
2282
Marshall Clow29b53f22018-12-14 18:49:35 +00002283#if _LIBCPP_STD_VER > 17
Marek Kurdeja98b1412020-05-02 13:58:03 +02002284template <class _Key, class _Tp, class _Compare, class _Allocator,
2285 class _Predicate>
Marshall Clow29b53f22018-12-14 18:49:35 +00002286inline _LIBCPP_INLINE_VISIBILITY
Marek Kurdeja98b1412020-05-02 13:58:03 +02002287 typename multimap<_Key, _Tp, _Compare, _Allocator>::size_type
2288 erase_if(multimap<_Key, _Tp, _Compare, _Allocator>& __c,
2289 _Predicate __pred) {
Arthur O'Dwyerb6738bd2021-03-21 16:53:09 -04002290 return _VSTD::__libcpp_erase_if_container(__c, __pred);
Marek Kurdeja98b1412020-05-02 13:58:03 +02002291}
Marshall Clow29b53f22018-12-14 18:49:35 +00002292#endif
2293
Howard Hinnantc51e1022010-05-11 19:42:16 +00002294_LIBCPP_END_NAMESPACE_STD
2295
Louis Dionne2b1ceaa2021-04-20 12:03:32 -04002296#endif // _LIBCPP_MAP