blob: ddb596f8f6317995cdbd8bae0f44139ce7a39496 [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
46 : public binary_function<value_type, value_type, bool>
47 {
48 friend class map;
49 protected:
50 key_compare comp;
51
52 value_compare(key_compare c);
53 public:
54 bool operator()(const value_type& x, const value_type& y) const;
55 };
56
57 // construct/copy/destroy:
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +000058 map()
59 noexcept(
60 is_nothrow_default_constructible<allocator_type>::value &&
61 is_nothrow_default_constructible<key_compare>::value &&
62 is_nothrow_copy_constructible<key_compare>::value);
Howard Hinnantc51e1022010-05-11 19:42:16 +000063 explicit map(const key_compare& comp);
64 map(const key_compare& comp, const allocator_type& a);
65 template <class InputIterator>
66 map(InputIterator first, InputIterator last,
67 const key_compare& comp = key_compare());
68 template <class InputIterator>
69 map(InputIterator first, InputIterator last,
70 const key_compare& comp, const allocator_type& a);
71 map(const map& m);
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +000072 map(map&& m)
73 noexcept(
74 is_nothrow_move_constructible<allocator_type>::value &&
75 is_nothrow_move_constructible<key_compare>::value);
Howard Hinnantc51e1022010-05-11 19:42:16 +000076 explicit map(const allocator_type& a);
77 map(const map& m, const allocator_type& a);
78 map(map&& m, const allocator_type& a);
79 map(initializer_list<value_type> il, const key_compare& comp = key_compare());
80 map(initializer_list<value_type> il, const key_compare& comp, const allocator_type& a);
Marshall Clow300abfb2013-09-11 01:15:47 +000081 template <class InputIterator>
82 map(InputIterator first, InputIterator last, const allocator_type& a)
83 : map(first, last, Compare(), a) {} // C++14
84 map(initializer_list<value_type> il, const allocator_type& a)
85 : map(il, Compare(), a) {} // C++14
86 ~map();
Howard Hinnantc51e1022010-05-11 19:42:16 +000087
88 map& operator=(const map& m);
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +000089 map& operator=(map&& m)
90 noexcept(
91 allocator_type::propagate_on_container_move_assignment::value &&
92 is_nothrow_move_assignable<allocator_type>::value &&
Howard Hinnantf95f4f52011-06-04 15:22:34 +000093 is_nothrow_move_assignable<key_compare>::value);
Howard Hinnantc51e1022010-05-11 19:42:16 +000094 map& operator=(initializer_list<value_type> il);
95
96 // iterators:
Howard Hinnantf95f4f52011-06-04 15:22:34 +000097 iterator begin() noexcept;
98 const_iterator begin() const noexcept;
99 iterator end() noexcept;
100 const_iterator end() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000101
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000102 reverse_iterator rbegin() noexcept;
103 const_reverse_iterator rbegin() const noexcept;
104 reverse_iterator rend() noexcept;
105 const_reverse_iterator rend() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000106
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000107 const_iterator cbegin() const noexcept;
108 const_iterator cend() const noexcept;
109 const_reverse_iterator crbegin() const noexcept;
110 const_reverse_iterator crend() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000111
112 // capacity:
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000113 bool empty() const noexcept;
114 size_type size() const noexcept;
115 size_type max_size() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000116
117 // element access:
118 mapped_type& operator[](const key_type& k);
119 mapped_type& operator[](key_type&& k);
120
121 mapped_type& at(const key_type& k);
122 const mapped_type& at(const key_type& k) const;
123
124 // modifiers:
125 template <class... Args>
126 pair<iterator, bool> emplace(Args&&... args);
127 template <class... Args>
128 iterator emplace_hint(const_iterator position, Args&&... args);
129 pair<iterator, bool> insert(const value_type& v);
Marshall Clowd430d022016-01-05 19:32:41 +0000130 pair<iterator, bool> insert( value_type&& v); // C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000131 template <class P>
132 pair<iterator, bool> insert(P&& p);
133 iterator insert(const_iterator position, const value_type& v);
Marshall Clowd430d022016-01-05 19:32:41 +0000134 iterator insert(const_iterator position, value_type&& v); // C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000135 template <class P>
136 iterator insert(const_iterator position, P&& p);
137 template <class InputIterator>
138 void insert(InputIterator first, InputIterator last);
139 void insert(initializer_list<value_type> il);
140
Erik Pilkingtonc37a3d82018-08-01 01:33:38 +0000141 node_type extract(const_iterator position); // C++17
142 node_type extract(const key_type& x); // C++17
143 insert_return_type insert(node_type&& nh); // C++17
144 iterator insert(const_iterator hint, node_type&& nh); // C++17
145
Marshall Clow3223db82015-07-07 03:37:33 +0000146 template <class... Args>
147 pair<iterator, bool> try_emplace(const key_type& k, Args&&... args); // C++17
148 template <class... Args>
149 pair<iterator, bool> try_emplace(key_type&& k, Args&&... args); // C++17
150 template <class... Args>
151 iterator try_emplace(const_iterator hint, const key_type& k, Args&&... args); // C++17
152 template <class... Args>
153 iterator try_emplace(const_iterator hint, key_type&& k, Args&&... args); // C++17
154 template <class M>
155 pair<iterator, bool> insert_or_assign(const key_type& k, M&& obj); // C++17
156 template <class M>
157 pair<iterator, bool> insert_or_assign(key_type&& k, M&& obj); // C++17
158 template <class M>
159 iterator insert_or_assign(const_iterator hint, const key_type& k, M&& obj); // C++17
160 template <class M>
161 iterator insert_or_assign(const_iterator hint, key_type&& k, M&& obj); // C++17
162
Howard Hinnantc51e1022010-05-11 19:42:16 +0000163 iterator erase(const_iterator position);
Marshall Clow22ea5b82015-05-10 13:35:00 +0000164 iterator erase(iterator position); // C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000165 size_type erase(const key_type& k);
166 iterator erase(const_iterator first, const_iterator last);
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000167 void clear() noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000168
Erik Pilkington82a65ad2018-10-31 17:31:35 +0000169 template<class C2>
170 void merge(map<Key, T, C2, Allocator>& source); // C++17
171 template<class C2>
172 void merge(map<Key, T, C2, Allocator>&& source); // C++17
173 template<class C2>
174 void merge(multimap<Key, T, C2, Allocator>& source); // C++17
175 template<class C2>
176 void merge(multimap<Key, T, C2, Allocator>&& source); // C++17
177
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000178 void swap(map& m)
Marshall Clow8982dcd2015-07-13 20:04:56 +0000179 noexcept(allocator_traits<allocator_type>::is_always_equal::value &&
Eric Fiselier6bfed252016-04-21 23:38:59 +0000180 is_nothrow_swappable<key_compare>::value); // C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000181
182 // observers:
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000183 allocator_type get_allocator() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000184 key_compare key_comp() const;
185 value_compare value_comp() const;
186
187 // map operations:
188 iterator find(const key_type& k);
189 const_iterator find(const key_type& k) const;
Marshall Clowebb57322013-08-13 22:18:47 +0000190 template<typename K>
191 iterator find(const K& x); // C++14
192 template<typename K>
193 const_iterator find(const K& x) const; // C++14
194 template<typename K>
Marshall Clowe6a5f522014-08-24 23:54:16 +0000195 size_type count(const K& x) const; // C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000196 size_type count(const key_type& k) const;
Zoe Carver3ffbab12019-07-16 03:21:01 +0000197 bool contains(const key_type& x) const; // C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000198 iterator lower_bound(const key_type& k);
199 const_iterator lower_bound(const key_type& k) const;
Marshall Clowebb57322013-08-13 22:18:47 +0000200 template<typename K>
201 iterator lower_bound(const K& x); // C++14
202 template<typename K>
203 const_iterator lower_bound(const K& x) const; // C++14
204
Howard Hinnantc51e1022010-05-11 19:42:16 +0000205 iterator upper_bound(const key_type& k);
206 const_iterator upper_bound(const key_type& k) const;
Marshall Clowebb57322013-08-13 22:18:47 +0000207 template<typename K>
208 iterator upper_bound(const K& x); // C++14
209 template<typename K>
210 const_iterator upper_bound(const K& x) const; // C++14
211
Howard Hinnantc51e1022010-05-11 19:42:16 +0000212 pair<iterator,iterator> equal_range(const key_type& k);
213 pair<const_iterator,const_iterator> equal_range(const key_type& k) const;
Marshall Clowebb57322013-08-13 22:18:47 +0000214 template<typename K>
215 pair<iterator,iterator> equal_range(const K& x); // C++14
216 template<typename K>
217 pair<const_iterator,const_iterator> equal_range(const K& x) const; // C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000218};
219
220template <class Key, class T, class Compare, class Allocator>
221bool
222operator==(const map<Key, T, Compare, Allocator>& x,
223 const map<Key, T, Compare, Allocator>& y);
224
225template <class Key, class T, class Compare, class Allocator>
226bool
227operator< (const map<Key, T, Compare, Allocator>& x,
228 const map<Key, T, Compare, Allocator>& y);
229
230template <class Key, class T, class Compare, class Allocator>
231bool
232operator!=(const map<Key, T, Compare, Allocator>& x,
233 const map<Key, T, Compare, Allocator>& y);
234
235template <class Key, class T, class Compare, class Allocator>
236bool
237operator> (const map<Key, T, Compare, Allocator>& x,
238 const map<Key, T, Compare, Allocator>& y);
239
240template <class Key, class T, class Compare, class Allocator>
241bool
242operator>=(const map<Key, T, Compare, Allocator>& x,
243 const map<Key, T, Compare, Allocator>& y);
244
245template <class Key, class T, class Compare, class Allocator>
246bool
247operator<=(const map<Key, T, Compare, Allocator>& x,
248 const map<Key, T, Compare, Allocator>& y);
249
250// specialized algorithms:
251template <class Key, class T, class Compare, class Allocator>
252void
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000253swap(map<Key, T, Compare, Allocator>& x, map<Key, T, Compare, Allocator>& y)
254 noexcept(noexcept(x.swap(y)));
Howard Hinnantc51e1022010-05-11 19:42:16 +0000255
Marshall Clow29b53f22018-12-14 18:49:35 +0000256template <class Key, class T, class Compare, class Allocator, class Predicate>
Marek Kurdeja98b1412020-05-02 13:58:03 +0200257typename map<Key, T, Compare, Allocator>::size_type
258erase_if(map<Key, T, Compare, Allocator>& c, Predicate pred); // C++20
Marshall Clow29b53f22018-12-14 18:49:35 +0000259
260
Howard Hinnantc51e1022010-05-11 19:42:16 +0000261template <class Key, class T, class Compare = less<Key>,
262 class Allocator = allocator<pair<const Key, T>>>
263class multimap
264{
265public:
266 // types:
267 typedef Key key_type;
268 typedef T mapped_type;
269 typedef pair<const key_type,mapped_type> value_type;
270 typedef Compare key_compare;
271 typedef Allocator allocator_type;
272 typedef typename allocator_type::reference reference;
273 typedef typename allocator_type::const_reference const_reference;
274 typedef typename allocator_type::size_type size_type;
275 typedef typename allocator_type::difference_type difference_type;
276 typedef typename allocator_type::pointer pointer;
277 typedef typename allocator_type::const_pointer const_pointer;
278
279 typedef implementation-defined iterator;
280 typedef implementation-defined const_iterator;
281 typedef std::reverse_iterator<iterator> reverse_iterator;
282 typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
Erik Pilkingtonc37a3d82018-08-01 01:33:38 +0000283 typedef unspecified node_type; // C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000284
285 class value_compare
286 : public binary_function<value_type,value_type,bool>
287 {
288 friend class multimap;
289 protected:
290 key_compare comp;
291 value_compare(key_compare c);
292 public:
293 bool operator()(const value_type& x, const value_type& y) const;
294 };
295
296 // construct/copy/destroy:
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000297 multimap()
298 noexcept(
299 is_nothrow_default_constructible<allocator_type>::value &&
300 is_nothrow_default_constructible<key_compare>::value &&
301 is_nothrow_copy_constructible<key_compare>::value);
302 explicit multimap(const key_compare& comp);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000303 multimap(const key_compare& comp, const allocator_type& a);
304 template <class InputIterator>
305 multimap(InputIterator first, InputIterator last, const key_compare& comp);
306 template <class InputIterator>
307 multimap(InputIterator first, InputIterator last, const key_compare& comp,
308 const allocator_type& a);
309 multimap(const multimap& m);
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000310 multimap(multimap&& m)
311 noexcept(
312 is_nothrow_move_constructible<allocator_type>::value &&
313 is_nothrow_move_constructible<key_compare>::value);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000314 explicit multimap(const allocator_type& a);
315 multimap(const multimap& m, const allocator_type& a);
316 multimap(multimap&& m, const allocator_type& a);
317 multimap(initializer_list<value_type> il, const key_compare& comp = key_compare());
318 multimap(initializer_list<value_type> il, const key_compare& comp,
319 const allocator_type& a);
Marshall Clow300abfb2013-09-11 01:15:47 +0000320 template <class InputIterator>
321 multimap(InputIterator first, InputIterator last, const allocator_type& a)
322 : multimap(first, last, Compare(), a) {} // C++14
323 multimap(initializer_list<value_type> il, const allocator_type& a)
324 : multimap(il, Compare(), a) {} // C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000325 ~multimap();
326
327 multimap& operator=(const multimap& m);
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000328 multimap& operator=(multimap&& m)
329 noexcept(
330 allocator_type::propagate_on_container_move_assignment::value &&
331 is_nothrow_move_assignable<allocator_type>::value &&
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000332 is_nothrow_move_assignable<key_compare>::value);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000333 multimap& operator=(initializer_list<value_type> il);
334
335 // iterators:
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000336 iterator begin() noexcept;
337 const_iterator begin() const noexcept;
338 iterator end() noexcept;
339 const_iterator end() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000340
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000341 reverse_iterator rbegin() noexcept;
342 const_reverse_iterator rbegin() const noexcept;
343 reverse_iterator rend() noexcept;
344 const_reverse_iterator rend() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000345
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000346 const_iterator cbegin() const noexcept;
347 const_iterator cend() const noexcept;
348 const_reverse_iterator crbegin() const noexcept;
349 const_reverse_iterator crend() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000350
351 // capacity:
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000352 bool empty() const noexcept;
353 size_type size() const noexcept;
354 size_type max_size() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000355
356 // modifiers:
357 template <class... Args>
358 iterator emplace(Args&&... args);
359 template <class... Args>
360 iterator emplace_hint(const_iterator position, Args&&... args);
361 iterator insert(const value_type& v);
Marshall Clowd430d022016-01-05 19:32:41 +0000362 iterator insert( value_type&& v); // C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000363 template <class P>
364 iterator insert(P&& p);
365 iterator insert(const_iterator position, const value_type& v);
Marshall Clowd430d022016-01-05 19:32:41 +0000366 iterator insert(const_iterator position, value_type&& v); // C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000367 template <class P>
368 iterator insert(const_iterator position, P&& p);
369 template <class InputIterator>
370 void insert(InputIterator first, InputIterator last);
371 void insert(initializer_list<value_type> il);
372
Erik Pilkingtonc37a3d82018-08-01 01:33:38 +0000373 node_type extract(const_iterator position); // C++17
374 node_type extract(const key_type& x); // C++17
375 iterator insert(node_type&& nh); // C++17
376 iterator insert(const_iterator hint, node_type&& nh); // C++17
377
Howard Hinnantc51e1022010-05-11 19:42:16 +0000378 iterator erase(const_iterator position);
Marshall Clow22ea5b82015-05-10 13:35:00 +0000379 iterator erase(iterator position); // C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000380 size_type erase(const key_type& k);
381 iterator erase(const_iterator first, const_iterator last);
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000382 void clear() noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000383
Erik Pilkington82a65ad2018-10-31 17:31:35 +0000384 template<class C2>
385 void merge(multimap<Key, T, C2, Allocator>& source); // C++17
386 template<class C2>
387 void merge(multimap<Key, T, C2, Allocator>&& source); // C++17
388 template<class C2>
389 void merge(map<Key, T, C2, Allocator>& source); // C++17
390 template<class C2>
391 void merge(map<Key, T, C2, Allocator>&& source); // C++17
392
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000393 void swap(multimap& m)
Marshall Clow8982dcd2015-07-13 20:04:56 +0000394 noexcept(allocator_traits<allocator_type>::is_always_equal::value &&
Eric Fiselier6bfed252016-04-21 23:38:59 +0000395 is_nothrow_swappable<key_compare>::value); // C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000396
397 // observers:
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000398 allocator_type get_allocator() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000399 key_compare key_comp() const;
400 value_compare value_comp() const;
401
402 // map operations:
403 iterator find(const key_type& k);
404 const_iterator find(const key_type& k) const;
Marshall Clowebb57322013-08-13 22:18:47 +0000405 template<typename K>
406 iterator find(const K& x); // C++14
407 template<typename K>
408 const_iterator find(const K& x) const; // C++14
409 template<typename K>
Marshall Clowe6a5f522014-08-24 23:54:16 +0000410 size_type count(const K& x) const; // C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000411 size_type count(const key_type& k) const;
Zoe Carver3ffbab12019-07-16 03:21:01 +0000412 bool contains(const key_type& x) const; // C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000413 iterator lower_bound(const key_type& k);
414 const_iterator lower_bound(const key_type& k) const;
Marshall Clowebb57322013-08-13 22:18:47 +0000415 template<typename K>
416 iterator lower_bound(const K& x); // C++14
417 template<typename K>
418 const_iterator lower_bound(const K& x) const; // C++14
419
Howard Hinnantc51e1022010-05-11 19:42:16 +0000420 iterator upper_bound(const key_type& k);
421 const_iterator upper_bound(const key_type& k) const;
Marshall Clowebb57322013-08-13 22:18:47 +0000422 template<typename K>
423 iterator upper_bound(const K& x); // C++14
424 template<typename K>
425 const_iterator upper_bound(const K& x) const; // C++14
426
Howard Hinnantc51e1022010-05-11 19:42:16 +0000427 pair<iterator,iterator> equal_range(const key_type& k);
428 pair<const_iterator,const_iterator> equal_range(const key_type& k) const;
Marshall Clowebb57322013-08-13 22:18:47 +0000429 template<typename K>
430 pair<iterator,iterator> equal_range(const K& x); // C++14
431 template<typename K>
432 pair<const_iterator,const_iterator> equal_range(const K& x) const; // C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000433};
434
435template <class Key, class T, class Compare, class Allocator>
436bool
437operator==(const multimap<Key, T, Compare, Allocator>& x,
438 const multimap<Key, T, Compare, Allocator>& y);
439
440template <class Key, class T, class Compare, class Allocator>
441bool
442operator< (const multimap<Key, T, Compare, Allocator>& x,
443 const multimap<Key, T, Compare, Allocator>& y);
444
445template <class Key, class T, class Compare, class Allocator>
446bool
447operator!=(const multimap<Key, T, Compare, Allocator>& x,
448 const multimap<Key, T, Compare, Allocator>& y);
449
450template <class Key, class T, class Compare, class Allocator>
451bool
452operator> (const multimap<Key, T, Compare, Allocator>& x,
453 const multimap<Key, T, Compare, Allocator>& y);
454
455template <class Key, class T, class Compare, class Allocator>
456bool
457operator>=(const multimap<Key, T, Compare, Allocator>& x,
458 const multimap<Key, T, Compare, Allocator>& y);
459
460template <class Key, class T, class Compare, class Allocator>
461bool
462operator<=(const multimap<Key, T, Compare, Allocator>& x,
463 const multimap<Key, T, Compare, Allocator>& y);
464
465// specialized algorithms:
466template <class Key, class T, class Compare, class Allocator>
467void
468swap(multimap<Key, T, Compare, Allocator>& x,
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000469 multimap<Key, T, Compare, Allocator>& y)
470 noexcept(noexcept(x.swap(y)));
Howard Hinnantc51e1022010-05-11 19:42:16 +0000471
Marshall Clow29b53f22018-12-14 18:49:35 +0000472template <class Key, class T, class Compare, class Allocator, class Predicate>
Marek Kurdeja98b1412020-05-02 13:58:03 +0200473typename multimap<Key, T, Compare, Allocator>::size_type
474erase_if(multimap<Key, T, Compare, Allocator>& c, Predicate pred); // C++20
Marshall Clow29b53f22018-12-14 18:49:35 +0000475
Howard Hinnantc51e1022010-05-11 19:42:16 +0000476} // std
477
478*/
479
480#include <__config>
481#include <__tree>
Erik Pilkingtonc37a3d82018-08-01 01:33:38 +0000482#include <__node_handle>
Arthur O'Dwyer7deec122021-03-24 18:19:12 -0400483#include <compare>
484#include <initializer_list>
Arthur O'Dwyerb6738bd2021-03-21 16:53:09 -0400485#include <iterator> // __libcpp_erase_if_container
Howard Hinnantc51e1022010-05-11 19:42:16 +0000486#include <memory>
487#include <utility>
488#include <functional>
489#include <initializer_list>
Eric Fiselierf7394302015-06-13 07:08:02 +0000490#include <type_traits>
Marshall Clow0a1e7502018-09-12 19:41:40 +0000491#include <version>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000492
Howard Hinnantaaaa52b2011-10-17 20:05:10 +0000493#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000494#pragma GCC system_header
Howard Hinnantaaaa52b2011-10-17 20:05:10 +0000495#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000496
497_LIBCPP_BEGIN_NAMESPACE_STD
498
Louis Dionne878a3a82018-12-06 21:46:17 +0000499template <class _Key, class _CP, class _Compare,
500 bool = is_empty<_Compare>::value && !__libcpp_is_final<_Compare>::value>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000501class __map_value_compare
502 : private _Compare
503{
Howard Hinnantc51e1022010-05-11 19:42:16 +0000504public:
Howard Hinnant756c69b2010-09-22 16:48:34 +0000505 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000506 __map_value_compare()
507 _NOEXCEPT_(is_nothrow_default_constructible<_Compare>::value)
508 : _Compare() {}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000509 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000510 __map_value_compare(_Compare c)
511 _NOEXCEPT_(is_nothrow_copy_constructible<_Compare>::value)
512 : _Compare(c) {}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000513 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000514 const _Compare& key_comp() const _NOEXCEPT {return *this;}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000515 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000516 bool operator()(const _CP& __x, const _CP& __y) const
Erik Pilkingtond3fe2992018-06-04 20:38:23 +0000517 {return static_cast<const _Compare&>(*this)(__x.__get_value().first, __y.__get_value().first);}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000518 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000519 bool operator()(const _CP& __x, const _Key& __y) const
Erik Pilkingtond3fe2992018-06-04 20:38:23 +0000520 {return static_cast<const _Compare&>(*this)(__x.__get_value().first, __y);}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000521 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000522 bool operator()(const _Key& __x, const _CP& __y) const
Erik Pilkingtond3fe2992018-06-04 20:38:23 +0000523 {return static_cast<const _Compare&>(*this)(__x, __y.__get_value().first);}
Marshall Clow8982dcd2015-07-13 20:04:56 +0000524 void swap(__map_value_compare&__y)
525 _NOEXCEPT_(__is_nothrow_swappable<_Compare>::value)
526 {
Eric Fiselier68b5f0b2017-04-13 00:34:24 +0000527 using _VSTD::swap;
528 swap(static_cast<_Compare&>(*this), static_cast<_Compare&>(__y));
Marshall Clow8982dcd2015-07-13 20:04:56 +0000529 }
Marshall Clowebb57322013-08-13 22:18:47 +0000530
531#if _LIBCPP_STD_VER > 11
532 template <typename _K2>
533 _LIBCPP_INLINE_VISIBILITY
534 typename enable_if<__is_transparent<_Compare, _K2>::value, bool>::type
535 operator () ( const _K2& __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 Clowebb57322013-08-13 22:18:47 +0000537
538 template <typename _K2>
539 _LIBCPP_INLINE_VISIBILITY
540 typename enable_if<__is_transparent<_Compare, _K2>::value, bool>::type
541 operator () (const _CP& __x, const _K2& __y) const
Erik Pilkingtond3fe2992018-06-04 20:38:23 +0000542 {return static_cast<const _Compare&>(*this) (__x.__get_value().first, __y);}
Marshall Clowebb57322013-08-13 22:18:47 +0000543#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000544};
545
Howard Hinnant90b91592013-07-05 18:06:00 +0000546template <class _Key, class _CP, class _Compare>
547class __map_value_compare<_Key, _CP, _Compare, false>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000548{
549 _Compare comp;
550
Howard Hinnantc51e1022010-05-11 19:42:16 +0000551public:
Howard Hinnant756c69b2010-09-22 16:48:34 +0000552 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000553 __map_value_compare()
554 _NOEXCEPT_(is_nothrow_default_constructible<_Compare>::value)
555 : comp() {}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000556 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000557 __map_value_compare(_Compare c)
558 _NOEXCEPT_(is_nothrow_copy_constructible<_Compare>::value)
559 : comp(c) {}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000560 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000561 const _Compare& key_comp() const _NOEXCEPT {return comp;}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000562
Howard Hinnant756c69b2010-09-22 16:48:34 +0000563 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000564 bool operator()(const _CP& __x, const _CP& __y) const
Erik Pilkingtond3fe2992018-06-04 20:38:23 +0000565 {return comp(__x.__get_value().first, __y.__get_value().first);}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000566 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000567 bool operator()(const _CP& __x, const _Key& __y) const
Erik Pilkingtond3fe2992018-06-04 20:38:23 +0000568 {return comp(__x.__get_value().first, __y);}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000569 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000570 bool operator()(const _Key& __x, const _CP& __y) const
Erik Pilkingtond3fe2992018-06-04 20:38:23 +0000571 {return comp(__x, __y.__get_value().first);}
Marshall Clow8982dcd2015-07-13 20:04:56 +0000572 void swap(__map_value_compare&__y)
573 _NOEXCEPT_(__is_nothrow_swappable<_Compare>::value)
574 {
575 using _VSTD::swap;
576 swap(comp, __y.comp);
577 }
Eric Fiseliercf8c0212017-01-05 06:06:18 +0000578
Marshall Clowebb57322013-08-13 22:18:47 +0000579#if _LIBCPP_STD_VER > 11
580 template <typename _K2>
581 _LIBCPP_INLINE_VISIBILITY
582 typename enable_if<__is_transparent<_Compare, _K2>::value, bool>::type
583 operator () ( const _K2& __x, const _CP& __y ) const
Erik Pilkingtond3fe2992018-06-04 20:38:23 +0000584 {return comp (__x, __y.__get_value().first);}
Marshall Clowebb57322013-08-13 22:18:47 +0000585
586 template <typename _K2>
587 _LIBCPP_INLINE_VISIBILITY
588 typename enable_if<__is_transparent<_Compare, _K2>::value, bool>::type
589 operator () (const _CP& __x, const _K2& __y) const
Erik Pilkingtond3fe2992018-06-04 20:38:23 +0000590 {return comp (__x.__get_value().first, __y);}
Marshall Clowebb57322013-08-13 22:18:47 +0000591#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000592};
593
Marshall Clow8982dcd2015-07-13 20:04:56 +0000594template <class _Key, class _CP, class _Compare, bool __b>
595inline _LIBCPP_INLINE_VISIBILITY
596void
597swap(__map_value_compare<_Key, _CP, _Compare, __b>& __x,
598 __map_value_compare<_Key, _CP, _Compare, __b>& __y)
599 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
600{
601 __x.swap(__y);
602}
603
Howard Hinnantc51e1022010-05-11 19:42:16 +0000604template <class _Allocator>
605class __map_node_destructor
606{
607 typedef _Allocator allocator_type;
608 typedef allocator_traits<allocator_type> __alloc_traits;
Eric Fiseliera00b4842016-02-20 05:28:30 +0000609
Howard Hinnantc51e1022010-05-11 19:42:16 +0000610public:
611 typedef typename __alloc_traits::pointer pointer;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000612
Eric Fiseliera00b4842016-02-20 05:28:30 +0000613private:
Howard Hinnantc51e1022010-05-11 19:42:16 +0000614 allocator_type& __na_;
615
616 __map_node_destructor& operator=(const __map_node_destructor&);
617
618public:
619 bool __first_constructed;
620 bool __second_constructed;
621
Howard Hinnant756c69b2010-09-22 16:48:34 +0000622 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000623 explicit __map_node_destructor(allocator_type& __na) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +0000624 : __na_(__na),
625 __first_constructed(false),
626 __second_constructed(false)
627 {}
628
Eric Fiseliera85b1282017-04-18 21:08:06 +0000629#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant756c69b2010-09-22 16:48:34 +0000630 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000631 __map_node_destructor(__tree_node_destructor<allocator_type>&& __x) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +0000632 : __na_(__x.__na_),
633 __first_constructed(__x.__value_constructed),
634 __second_constructed(__x.__value_constructed)
635 {
636 __x.__value_constructed = false;
637 }
Eric Fiseliera85b1282017-04-18 21:08:06 +0000638#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000639
Howard Hinnant756c69b2010-09-22 16:48:34 +0000640 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000641 void operator()(pointer __p) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +0000642 {
643 if (__second_constructed)
Erik Pilkingtond3fe2992018-06-04 20:38:23 +0000644 __alloc_traits::destroy(__na_, _VSTD::addressof(__p->__value_.__get_value().second));
Howard Hinnantc51e1022010-05-11 19:42:16 +0000645 if (__first_constructed)
Erik Pilkingtond3fe2992018-06-04 20:38:23 +0000646 __alloc_traits::destroy(__na_, _VSTD::addressof(__p->__value_.__get_value().first));
Howard Hinnantc51e1022010-05-11 19:42:16 +0000647 if (__p)
648 __alloc_traits::deallocate(__na_, __p, 1);
649 }
650};
651
Howard Hinnant944510a2011-06-14 19:58:17 +0000652template <class _Key, class _Tp, class _Compare, class _Allocator>
653 class map;
654template <class _Key, class _Tp, class _Compare, class _Allocator>
655 class multimap;
656template <class _TreeIterator> class __map_const_iterator;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000657
Eric Fiseliera00b4842016-02-20 05:28:30 +0000658#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant89f8b792013-09-30 19:08:22 +0000659
660template <class _Key, class _Tp>
Erik Pilkingtond3fe2992018-06-04 20:38:23 +0000661struct __value_type
Howard Hinnant89f8b792013-09-30 19:08:22 +0000662{
663 typedef _Key key_type;
664 typedef _Tp mapped_type;
665 typedef pair<const key_type, mapped_type> value_type;
Erik Pilkingtond3fe2992018-06-04 20:38:23 +0000666 typedef pair<key_type&, mapped_type&> __nc_ref_pair_type;
667 typedef pair<key_type&&, mapped_type&&> __nc_rref_pair_type;
Howard Hinnant89f8b792013-09-30 19:08:22 +0000668
Erik Pilkingtond3fe2992018-06-04 20:38:23 +0000669private:
Howard Hinnant89f8b792013-09-30 19:08:22 +0000670 value_type __cc;
Erik Pilkingtond3fe2992018-06-04 20:38:23 +0000671
672public:
673 _LIBCPP_INLINE_VISIBILITY
674 value_type& __get_value()
675 {
676#if _LIBCPP_STD_VER > 14
677 return *_VSTD::launder(_VSTD::addressof(__cc));
678#else
679 return __cc;
680#endif
681 }
682
683 _LIBCPP_INLINE_VISIBILITY
684 const value_type& __get_value() const
685 {
686#if _LIBCPP_STD_VER > 14
687 return *_VSTD::launder(_VSTD::addressof(__cc));
688#else
689 return __cc;
690#endif
691 }
692
693 _LIBCPP_INLINE_VISIBILITY
694 __nc_ref_pair_type __ref()
695 {
696 value_type& __v = __get_value();
697 return __nc_ref_pair_type(const_cast<key_type&>(__v.first), __v.second);
698 }
699
700 _LIBCPP_INLINE_VISIBILITY
701 __nc_rref_pair_type __move()
702 {
703 value_type& __v = __get_value();
704 return __nc_rref_pair_type(
705 _VSTD::move(const_cast<key_type&>(__v.first)),
706 _VSTD::move(__v.second));
707 }
Howard Hinnant89f8b792013-09-30 19:08:22 +0000708
Howard Hinnant89f8b792013-09-30 19:08:22 +0000709 _LIBCPP_INLINE_VISIBILITY
710 __value_type& operator=(const __value_type& __v)
Erik Pilkingtond3fe2992018-06-04 20:38:23 +0000711 {
712 __ref() = __v.__get_value();
713 return *this;
714 }
Howard Hinnant89f8b792013-09-30 19:08:22 +0000715
716 _LIBCPP_INLINE_VISIBILITY
717 __value_type& operator=(__value_type&& __v)
Erik Pilkingtond3fe2992018-06-04 20:38:23 +0000718 {
719 __ref() = __v.__move();
720 return *this;
721 }
Howard Hinnant89f8b792013-09-30 19:08:22 +0000722
Eric Fiselierd06276b2016-03-31 02:15:15 +0000723 template <class _ValueTp,
724 class = typename enable_if<
725 __is_same_uncvref<_ValueTp, value_type>::value
726 >::type
727 >
Howard Hinnant89f8b792013-09-30 19:08:22 +0000728 _LIBCPP_INLINE_VISIBILITY
Erik Pilkingtond3fe2992018-06-04 20:38:23 +0000729 __value_type& operator=(_ValueTp&& __v)
730 {
731 __ref() = _VSTD::forward<_ValueTp>(__v);
732 return *this;
Eric Fiselierd06276b2016-03-31 02:15:15 +0000733 }
734
735private:
736 __value_type() _LIBCPP_EQUAL_DELETE;
737 ~__value_type() _LIBCPP_EQUAL_DELETE;
738 __value_type(const __value_type& __v) _LIBCPP_EQUAL_DELETE;
739 __value_type(__value_type&& __v) _LIBCPP_EQUAL_DELETE;
Howard Hinnant89f8b792013-09-30 19:08:22 +0000740};
741
742#else
743
744template <class _Key, class _Tp>
745struct __value_type
746{
747 typedef _Key key_type;
748 typedef _Tp mapped_type;
749 typedef pair<const key_type, mapped_type> value_type;
750
Erik Pilkingtond3fe2992018-06-04 20:38:23 +0000751private:
Howard Hinnant89f8b792013-09-30 19:08:22 +0000752 value_type __cc;
753
Erik Pilkingtond3fe2992018-06-04 20:38:23 +0000754public:
755 _LIBCPP_INLINE_VISIBILITY
756 value_type& __get_value() { return __cc; }
757 _LIBCPP_INLINE_VISIBILITY
758 const value_type& __get_value() const { return __cc; }
759
Eric Fiselierd06276b2016-03-31 02:15:15 +0000760private:
761 __value_type();
762 __value_type(__value_type const&);
763 __value_type& operator=(__value_type const&);
764 ~__value_type();
Howard Hinnant89f8b792013-09-30 19:08:22 +0000765};
766
Eric Fiseliera85b1282017-04-18 21:08:06 +0000767#endif // _LIBCPP_CXX03_LANG
Howard Hinnant89f8b792013-09-30 19:08:22 +0000768
Eric Fiselier44f9fd02015-03-03 20:10:01 +0000769template <class _Tp>
770struct __extract_key_value_types;
771
772template <class _Key, class _Tp>
773struct __extract_key_value_types<__value_type<_Key, _Tp> >
774{
775 typedef _Key const __key_type;
776 typedef _Tp __mapped_type;
777};
778
Howard Hinnantc51e1022010-05-11 19:42:16 +0000779template <class _TreeIterator>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000780class _LIBCPP_TEMPLATE_VIS __map_iterator
Howard Hinnantc51e1022010-05-11 19:42:16 +0000781{
Eric Fiseliera00b4842016-02-20 05:28:30 +0000782 typedef typename _TreeIterator::_NodeTypes _NodeTypes;
783 typedef typename _TreeIterator::__pointer_traits __pointer_traits;
784
Howard Hinnantc51e1022010-05-11 19:42:16 +0000785 _TreeIterator __i_;
786
Howard Hinnantc51e1022010-05-11 19:42:16 +0000787public:
788 typedef bidirectional_iterator_tag iterator_category;
Eric Fiseliera00b4842016-02-20 05:28:30 +0000789 typedef typename _NodeTypes::__map_value_type value_type;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000790 typedef typename _TreeIterator::difference_type difference_type;
791 typedef value_type& reference;
Eric Fiseliera00b4842016-02-20 05:28:30 +0000792 typedef typename _NodeTypes::__map_value_type_pointer pointer;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000793
Howard Hinnant756c69b2010-09-22 16:48:34 +0000794 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000795 __map_iterator() _NOEXCEPT {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000796
Howard Hinnant756c69b2010-09-22 16:48:34 +0000797 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000798 __map_iterator(_TreeIterator __i) _NOEXCEPT : __i_(__i) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000799
Howard Hinnant756c69b2010-09-22 16:48:34 +0000800 _LIBCPP_INLINE_VISIBILITY
Erik Pilkingtond3fe2992018-06-04 20:38:23 +0000801 reference operator*() const {return __i_->__get_value();}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000802 _LIBCPP_INLINE_VISIBILITY
Erik Pilkingtond3fe2992018-06-04 20:38:23 +0000803 pointer operator->() const {return pointer_traits<pointer>::pointer_to(__i_->__get_value());}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000804
Howard Hinnant756c69b2010-09-22 16:48:34 +0000805 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000806 __map_iterator& operator++() {++__i_; return *this;}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000807 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000808 __map_iterator operator++(int)
809 {
810 __map_iterator __t(*this);
811 ++(*this);
812 return __t;
813 }
814
Howard Hinnant756c69b2010-09-22 16:48:34 +0000815 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000816 __map_iterator& operator--() {--__i_; return *this;}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000817 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000818 __map_iterator operator--(int)
819 {
820 __map_iterator __t(*this);
821 --(*this);
822 return __t;
823 }
824
Howard Hinnant756c69b2010-09-22 16:48:34 +0000825 friend _LIBCPP_INLINE_VISIBILITY
826 bool operator==(const __map_iterator& __x, const __map_iterator& __y)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000827 {return __x.__i_ == __y.__i_;}
Eric Fiseliercf8c0212017-01-05 06:06:18 +0000828 friend
Howard Hinnant756c69b2010-09-22 16:48:34 +0000829 _LIBCPP_INLINE_VISIBILITY
830 bool operator!=(const __map_iterator& __x, const __map_iterator& __y)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000831 {return __x.__i_ != __y.__i_;}
832
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000833 template <class, class, class, class> friend class _LIBCPP_TEMPLATE_VIS map;
834 template <class, class, class, class> friend class _LIBCPP_TEMPLATE_VIS multimap;
835 template <class> friend class _LIBCPP_TEMPLATE_VIS __map_const_iterator;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000836};
837
838template <class _TreeIterator>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000839class _LIBCPP_TEMPLATE_VIS __map_const_iterator
Howard Hinnantc51e1022010-05-11 19:42:16 +0000840{
Eric Fiseliera00b4842016-02-20 05:28:30 +0000841 typedef typename _TreeIterator::_NodeTypes _NodeTypes;
842 typedef typename _TreeIterator::__pointer_traits __pointer_traits;
843
Howard Hinnantc51e1022010-05-11 19:42:16 +0000844 _TreeIterator __i_;
845
Howard Hinnantc51e1022010-05-11 19:42:16 +0000846public:
847 typedef bidirectional_iterator_tag iterator_category;
Eric Fiseliera00b4842016-02-20 05:28:30 +0000848 typedef typename _NodeTypes::__map_value_type value_type;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000849 typedef typename _TreeIterator::difference_type difference_type;
850 typedef const value_type& reference;
Eric Fiseliera00b4842016-02-20 05:28:30 +0000851 typedef typename _NodeTypes::__const_map_value_type_pointer pointer;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000852
Howard Hinnant756c69b2010-09-22 16:48:34 +0000853 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000854 __map_const_iterator() _NOEXCEPT {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000855
Howard Hinnant756c69b2010-09-22 16:48:34 +0000856 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000857 __map_const_iterator(_TreeIterator __i) _NOEXCEPT : __i_(__i) {}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000858 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier44f9fd02015-03-03 20:10:01 +0000859 __map_const_iterator(__map_iterator<
860 typename _TreeIterator::__non_const_iterator> __i) _NOEXCEPT
861 : __i_(__i.__i_) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000862
Howard Hinnant756c69b2010-09-22 16:48:34 +0000863 _LIBCPP_INLINE_VISIBILITY
Erik Pilkingtond3fe2992018-06-04 20:38:23 +0000864 reference operator*() const {return __i_->__get_value();}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000865 _LIBCPP_INLINE_VISIBILITY
Erik Pilkingtond3fe2992018-06-04 20:38:23 +0000866 pointer operator->() const {return pointer_traits<pointer>::pointer_to(__i_->__get_value());}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000867
Howard Hinnant756c69b2010-09-22 16:48:34 +0000868 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000869 __map_const_iterator& operator++() {++__i_; return *this;}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000870 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000871 __map_const_iterator operator++(int)
872 {
873 __map_const_iterator __t(*this);
874 ++(*this);
875 return __t;
876 }
877
Howard Hinnant756c69b2010-09-22 16:48:34 +0000878 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000879 __map_const_iterator& operator--() {--__i_; return *this;}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000880 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000881 __map_const_iterator operator--(int)
882 {
883 __map_const_iterator __t(*this);
884 --(*this);
885 return __t;
886 }
887
Howard Hinnant756c69b2010-09-22 16:48:34 +0000888 friend _LIBCPP_INLINE_VISIBILITY
889 bool operator==(const __map_const_iterator& __x, const __map_const_iterator& __y)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000890 {return __x.__i_ == __y.__i_;}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000891 friend _LIBCPP_INLINE_VISIBILITY
892 bool operator!=(const __map_const_iterator& __x, const __map_const_iterator& __y)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000893 {return __x.__i_ != __y.__i_;}
894
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000895 template <class, class, class, class> friend class _LIBCPP_TEMPLATE_VIS map;
896 template <class, class, class, class> friend class _LIBCPP_TEMPLATE_VIS multimap;
897 template <class, class, class> friend class _LIBCPP_TEMPLATE_VIS __tree_const_iterator;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000898};
899
900template <class _Key, class _Tp, class _Compare = less<_Key>,
901 class _Allocator = allocator<pair<const _Key, _Tp> > >
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000902class _LIBCPP_TEMPLATE_VIS map
Howard Hinnantc51e1022010-05-11 19:42:16 +0000903{
904public:
905 // types:
906 typedef _Key key_type;
907 typedef _Tp mapped_type;
908 typedef pair<const key_type, mapped_type> value_type;
Arthur O'Dwyer6a752e12021-03-03 11:10:49 -0500909 typedef __identity_t<_Compare> key_compare;
910 typedef __identity_t<_Allocator> allocator_type;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000911 typedef value_type& reference;
912 typedef const value_type& const_reference;
913
Marshall Clow5128cf32015-11-26 01:24:04 +0000914 static_assert((is_same<typename allocator_type::value_type, value_type>::value),
915 "Allocator::value_type must be same type as value_type");
916
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000917 class _LIBCPP_TEMPLATE_VIS value_compare
Howard Hinnantc51e1022010-05-11 19:42:16 +0000918 : public binary_function<value_type, value_type, bool>
919 {
920 friend class map;
921 protected:
922 key_compare comp;
923
Howard Hinnant756c69b2010-09-22 16:48:34 +0000924 _LIBCPP_INLINE_VISIBILITY value_compare(key_compare c) : comp(c) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000925 public:
Howard Hinnant756c69b2010-09-22 16:48:34 +0000926 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000927 bool operator()(const value_type& __x, const value_type& __y) const
928 {return comp(__x.first, __y.first);}
929 };
930
931private:
Howard Hinnant2d0046b2013-06-19 21:29:40 +0000932
Howard Hinnant89f8b792013-09-30 19:08:22 +0000933 typedef _VSTD::__value_type<key_type, mapped_type> __value_type;
Howard Hinnant90b91592013-07-05 18:06:00 +0000934 typedef __map_value_compare<key_type, __value_type, key_compare> __vc;
Marshall Clow940e01c2015-04-07 05:21:38 +0000935 typedef typename __rebind_alloc_helper<allocator_traits<allocator_type>,
936 __value_type>::type __allocator_type;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000937 typedef __tree<__value_type, __vc, __allocator_type> __base;
938 typedef typename __base::__node_traits __node_traits;
939 typedef allocator_traits<allocator_type> __alloc_traits;
940
941 __base __tree_;
942
943public:
944 typedef typename __alloc_traits::pointer pointer;
945 typedef typename __alloc_traits::const_pointer const_pointer;
946 typedef typename __alloc_traits::size_type size_type;
947 typedef typename __alloc_traits::difference_type difference_type;
Eric Fiselier44f9fd02015-03-03 20:10:01 +0000948 typedef __map_iterator<typename __base::iterator> iterator;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000949 typedef __map_const_iterator<typename __base::const_iterator> const_iterator;
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000950 typedef _VSTD::reverse_iterator<iterator> reverse_iterator;
951 typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000952
Erik Pilkingtonc37a3d82018-08-01 01:33:38 +0000953#if _LIBCPP_STD_VER > 14
954 typedef __map_node_handle<typename __base::__node, allocator_type> node_type;
955 typedef __insert_return_type<iterator, node_type> insert_return_type;
956#endif
957
Erik Pilkington82a65ad2018-10-31 17:31:35 +0000958 template <class _Key2, class _Value2, class _Comp2, class _Alloc2>
959 friend class _LIBCPP_TEMPLATE_VIS map;
960 template <class _Key2, class _Value2, class _Comp2, class _Alloc2>
961 friend class _LIBCPP_TEMPLATE_VIS multimap;
962
Howard Hinnant756c69b2010-09-22 16:48:34 +0000963 _LIBCPP_INLINE_VISIBILITY
Marshall Clow7086a5a2014-03-10 04:50:10 +0000964 map()
965 _NOEXCEPT_(
966 is_nothrow_default_constructible<allocator_type>::value &&
967 is_nothrow_default_constructible<key_compare>::value &&
968 is_nothrow_copy_constructible<key_compare>::value)
969 : __tree_(__vc(key_compare())) {}
970
971 _LIBCPP_INLINE_VISIBILITY
972 explicit map(const key_compare& __comp)
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000973 _NOEXCEPT_(
974 is_nothrow_default_constructible<allocator_type>::value &&
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000975 is_nothrow_copy_constructible<key_compare>::value)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000976 : __tree_(__vc(__comp)) {}
977
Howard Hinnant756c69b2010-09-22 16:48:34 +0000978 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000979 explicit map(const key_compare& __comp, const allocator_type& __a)
Marshall Clow657cbc42016-08-17 05:58:40 +0000980 : __tree_(__vc(__comp), typename __base::allocator_type(__a)) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000981
982 template <class _InputIterator>
Howard Hinnant756c69b2010-09-22 16:48:34 +0000983 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000984 map(_InputIterator __f, _InputIterator __l,
985 const key_compare& __comp = key_compare())
986 : __tree_(__vc(__comp))
987 {
988 insert(__f, __l);
989 }
990
991 template <class _InputIterator>
Howard Hinnant756c69b2010-09-22 16:48:34 +0000992 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000993 map(_InputIterator __f, _InputIterator __l,
994 const key_compare& __comp, const allocator_type& __a)
Marshall Clow657cbc42016-08-17 05:58:40 +0000995 : __tree_(__vc(__comp), typename __base::allocator_type(__a))
Howard Hinnantc51e1022010-05-11 19:42:16 +0000996 {
997 insert(__f, __l);
998 }
999
Marshall Clow300abfb2013-09-11 01:15:47 +00001000#if _LIBCPP_STD_VER > 11
1001 template <class _InputIterator>
Eric Fiseliercf8c0212017-01-05 06:06:18 +00001002 _LIBCPP_INLINE_VISIBILITY
Marshall Clow300abfb2013-09-11 01:15:47 +00001003 map(_InputIterator __f, _InputIterator __l, const allocator_type& __a)
1004 : map(__f, __l, key_compare(), __a) {}
1005#endif
1006
Howard Hinnant756c69b2010-09-22 16:48:34 +00001007 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001008 map(const map& __m)
1009 : __tree_(__m.__tree_)
1010 {
1011 insert(__m.begin(), __m.end());
1012 }
1013
Howard Hinnantd3a657f2011-07-01 19:24:36 +00001014 _LIBCPP_INLINE_VISIBILITY
1015 map& operator=(const map& __m)
1016 {
Marshall Clow476d3f42016-07-18 13:19:00 +00001017#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantd3a657f2011-07-01 19:24:36 +00001018 __tree_ = __m.__tree_;
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001019#else
Marshall Clowdb3cfcb2014-02-08 04:03:14 +00001020 if (this != &__m) {
1021 __tree_.clear();
1022 __tree_.value_comp() = __m.__tree_.value_comp();
1023 __tree_.__copy_assign_alloc(__m.__tree_);
1024 insert(__m.begin(), __m.end());
1025 }
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001026#endif
Howard Hinnantd3a657f2011-07-01 19:24:36 +00001027 return *this;
1028 }
1029
Eric Fiseliera85b1282017-04-18 21:08:06 +00001030#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001031
Howard Hinnant756c69b2010-09-22 16:48:34 +00001032 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001033 map(map&& __m)
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001034 _NOEXCEPT_(is_nothrow_move_constructible<__base>::value)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001035 : __tree_(_VSTD::move(__m.__tree_))
Howard Hinnantc51e1022010-05-11 19:42:16 +00001036 {
1037 }
1038
1039 map(map&& __m, const allocator_type& __a);
1040
Howard Hinnant756c69b2010-09-22 16:48:34 +00001041 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant33711792011-08-12 21:56:02 +00001042 map& operator=(map&& __m)
1043 _NOEXCEPT_(is_nothrow_move_assignable<__base>::value)
1044 {
1045 __tree_ = _VSTD::move(__m.__tree_);
1046 return *this;
1047 }
1048
Howard Hinnant33711792011-08-12 21:56:02 +00001049 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001050 map(initializer_list<value_type> __il, const key_compare& __comp = key_compare())
1051 : __tree_(__vc(__comp))
1052 {
1053 insert(__il.begin(), __il.end());
1054 }
1055
Howard Hinnant756c69b2010-09-22 16:48:34 +00001056 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001057 map(initializer_list<value_type> __il, const key_compare& __comp, const allocator_type& __a)
Marshall Clow657cbc42016-08-17 05:58:40 +00001058 : __tree_(__vc(__comp), typename __base::allocator_type(__a))
Howard Hinnantc51e1022010-05-11 19:42:16 +00001059 {
1060 insert(__il.begin(), __il.end());
1061 }
1062
Marshall Clow300abfb2013-09-11 01:15:47 +00001063#if _LIBCPP_STD_VER > 11
Eric Fiseliercf8c0212017-01-05 06:06:18 +00001064 _LIBCPP_INLINE_VISIBILITY
Marshall Clow300abfb2013-09-11 01:15:47 +00001065 map(initializer_list<value_type> __il, const allocator_type& __a)
1066 : map(__il, key_compare(), __a) {}
1067#endif
1068
Howard Hinnant756c69b2010-09-22 16:48:34 +00001069 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001070 map& operator=(initializer_list<value_type> __il)
1071 {
1072 __tree_.__assign_unique(__il.begin(), __il.end());
1073 return *this;
1074 }
1075
Eric Fiseliera85b1282017-04-18 21:08:06 +00001076#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001077
Howard Hinnant756c69b2010-09-22 16:48:34 +00001078 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001079 explicit map(const allocator_type& __a)
Marshall Clow657cbc42016-08-17 05:58:40 +00001080 : __tree_(typename __base::allocator_type(__a))
Howard Hinnantc51e1022010-05-11 19:42:16 +00001081 {
1082 }
1083
Howard Hinnant756c69b2010-09-22 16:48:34 +00001084 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001085 map(const map& __m, const allocator_type& __a)
Marshall Clow657cbc42016-08-17 05:58:40 +00001086 : __tree_(__m.__tree_.value_comp(), typename __base::allocator_type(__a))
Howard Hinnantc51e1022010-05-11 19:42:16 +00001087 {
1088 insert(__m.begin(), __m.end());
1089 }
1090
Howard Hinnant756c69b2010-09-22 16:48:34 +00001091 _LIBCPP_INLINE_VISIBILITY
Louis Dionne69c42c02019-04-11 16:14:56 +00001092 ~map() {
1093 static_assert(sizeof(__diagnose_non_const_comparator<_Key, _Compare>()), "");
1094 }
1095
1096 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001097 iterator begin() _NOEXCEPT {return __tree_.begin();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001098 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001099 const_iterator begin() const _NOEXCEPT {return __tree_.begin();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001100 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001101 iterator end() _NOEXCEPT {return __tree_.end();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001102 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001103 const_iterator end() const _NOEXCEPT {return __tree_.end();}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001104
Howard Hinnant756c69b2010-09-22 16:48:34 +00001105 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001106 reverse_iterator rbegin() _NOEXCEPT {return reverse_iterator(end());}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001107 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001108 const_reverse_iterator rbegin() const _NOEXCEPT
1109 {return const_reverse_iterator(end());}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001110 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001111 reverse_iterator rend() _NOEXCEPT
1112 {return reverse_iterator(begin());}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001113 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001114 const_reverse_iterator rend() const _NOEXCEPT
1115 {return const_reverse_iterator(begin());}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001116
Howard Hinnant756c69b2010-09-22 16:48:34 +00001117 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001118 const_iterator cbegin() const _NOEXCEPT {return begin();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001119 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001120 const_iterator cend() const _NOEXCEPT {return end();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001121 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001122 const_reverse_iterator crbegin() const _NOEXCEPT {return rbegin();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001123 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001124 const_reverse_iterator crend() const _NOEXCEPT {return rend();}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001125
Marshall Clow425f5752017-11-15 05:51:26 +00001126 _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001127 bool empty() const _NOEXCEPT {return __tree_.size() == 0;}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001128 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001129 size_type size() const _NOEXCEPT {return __tree_.size();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001130 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001131 size_type max_size() const _NOEXCEPT {return __tree_.max_size();}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001132
1133 mapped_type& operator[](const key_type& __k);
Eric Fiselierd63f38e2016-03-31 03:13:37 +00001134#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001135 mapped_type& operator[](key_type&& __k);
1136#endif
1137
1138 mapped_type& at(const key_type& __k);
1139 const mapped_type& at(const key_type& __k) const;
1140
Howard Hinnant756c69b2010-09-22 16:48:34 +00001141 _LIBCPP_INLINE_VISIBILITY
Marshall Clow657cbc42016-08-17 05:58:40 +00001142 allocator_type get_allocator() const _NOEXCEPT {return allocator_type(__tree_.__alloc());}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001143 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001144 key_compare key_comp() const {return __tree_.value_comp().key_comp();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001145 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001146 value_compare value_comp() const {return value_compare(__tree_.value_comp().key_comp());}
1147
Eric Fiselierd06276b2016-03-31 02:15:15 +00001148#ifndef _LIBCPP_CXX03_LANG
1149 template <class ..._Args>
1150 _LIBCPP_INLINE_VISIBILITY
1151 pair<iterator, bool> emplace(_Args&& ...__args) {
1152 return __tree_.__emplace_unique(_VSTD::forward<_Args>(__args)...);
1153 }
Howard Hinnant74279a52010-09-04 23:28:19 +00001154
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001155 template <class ..._Args>
Eric Fiselierd06276b2016-03-31 02:15:15 +00001156 _LIBCPP_INLINE_VISIBILITY
1157 iterator emplace_hint(const_iterator __p, _Args&& ...__args) {
1158 return __tree_.__emplace_hint_unique(__p.__i_, _VSTD::forward<_Args>(__args)...);
1159 }
Howard Hinnant74279a52010-09-04 23:28:19 +00001160
Howard Hinnantc834c512011-11-29 18:15:50 +00001161 template <class _Pp,
1162 class = typename enable_if<is_constructible<value_type, _Pp>::value>::type>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001163 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc834c512011-11-29 18:15:50 +00001164 pair<iterator, bool> insert(_Pp&& __p)
1165 {return __tree_.__insert_unique(_VSTD::forward<_Pp>(__p));}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001166
Howard Hinnantc834c512011-11-29 18:15:50 +00001167 template <class _Pp,
1168 class = typename enable_if<is_constructible<value_type, _Pp>::value>::type>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001169 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc834c512011-11-29 18:15:50 +00001170 iterator insert(const_iterator __pos, _Pp&& __p)
1171 {return __tree_.__insert_unique(__pos.__i_, _VSTD::forward<_Pp>(__p));}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001172
Eric Fiselierd06276b2016-03-31 02:15:15 +00001173#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001174
Howard Hinnant756c69b2010-09-22 16:48:34 +00001175 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001176 pair<iterator, bool>
1177 insert(const value_type& __v) {return __tree_.__insert_unique(__v);}
1178
Howard Hinnant756c69b2010-09-22 16:48:34 +00001179 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001180 iterator
1181 insert(const_iterator __p, const value_type& __v)
1182 {return __tree_.__insert_unique(__p.__i_, __v);}
1183
Eric Fiselierd6143132016-04-18 01:40:45 +00001184#ifndef _LIBCPP_CXX03_LANG
Marshall Clowd430d022016-01-05 19:32:41 +00001185 _LIBCPP_INLINE_VISIBILITY
1186 pair<iterator, bool>
Eric Fiselierd06276b2016-03-31 02:15:15 +00001187 insert(value_type&& __v) {return __tree_.__insert_unique(_VSTD::move(__v));}
Marshall Clowd430d022016-01-05 19:32:41 +00001188
1189 _LIBCPP_INLINE_VISIBILITY
Eric Fiselierd06276b2016-03-31 02:15:15 +00001190 iterator insert(const_iterator __p, value_type&& __v)
1191 {return __tree_.__insert_unique(__p.__i_, _VSTD::move(__v));}
Eric Fiseliera85b1282017-04-18 21:08:06 +00001192
1193 _LIBCPP_INLINE_VISIBILITY
1194 void insert(initializer_list<value_type> __il)
1195 {insert(__il.begin(), __il.end());}
Marshall Clowd430d022016-01-05 19:32:41 +00001196#endif
1197
Howard Hinnantc51e1022010-05-11 19:42:16 +00001198 template <class _InputIterator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001199 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001200 void insert(_InputIterator __f, _InputIterator __l)
1201 {
1202 for (const_iterator __e = cend(); __f != __l; ++__f)
1203 insert(__e.__i_, *__f);
1204 }
1205
Marshall Clow3223db82015-07-07 03:37:33 +00001206#if _LIBCPP_STD_VER > 14
Eric Fiselierd63f38e2016-03-31 03:13:37 +00001207
Marshall Clow3223db82015-07-07 03:37:33 +00001208 template <class... _Args>
1209 _LIBCPP_INLINE_VISIBILITY
1210 pair<iterator, bool> try_emplace(const key_type& __k, _Args&&... __args)
1211 {
Eric Fiselierd63f38e2016-03-31 03:13:37 +00001212 return __tree_.__emplace_unique_key_args(__k,
1213 _VSTD::piecewise_construct,
1214 _VSTD::forward_as_tuple(__k),
1215 _VSTD::forward_as_tuple(_VSTD::forward<_Args>(__args)...));
Marshall Clow3223db82015-07-07 03:37:33 +00001216 }
1217
1218 template <class... _Args>
1219 _LIBCPP_INLINE_VISIBILITY
1220 pair<iterator, bool> try_emplace(key_type&& __k, _Args&&... __args)
1221 {
Eric Fiselierd63f38e2016-03-31 03:13:37 +00001222 return __tree_.__emplace_unique_key_args(__k,
1223 _VSTD::piecewise_construct,
1224 _VSTD::forward_as_tuple(_VSTD::move(__k)),
1225 _VSTD::forward_as_tuple(_VSTD::forward<_Args>(__args)...));
Marshall Clow3223db82015-07-07 03:37:33 +00001226 }
1227
1228 template <class... _Args>
1229 _LIBCPP_INLINE_VISIBILITY
1230 iterator try_emplace(const_iterator __h, const key_type& __k, _Args&&... __args)
1231 {
Eric Fiselierd63f38e2016-03-31 03:13:37 +00001232 return __tree_.__emplace_hint_unique_key_args(__h.__i_, __k,
1233 _VSTD::piecewise_construct,
1234 _VSTD::forward_as_tuple(__k),
Mark de Wever1ba476f2020-09-19 15:39:09 +02001235 _VSTD::forward_as_tuple(_VSTD::forward<_Args>(__args)...)).first;
Marshall Clow3223db82015-07-07 03:37:33 +00001236 }
1237
1238 template <class... _Args>
1239 _LIBCPP_INLINE_VISIBILITY
1240 iterator try_emplace(const_iterator __h, key_type&& __k, _Args&&... __args)
1241 {
Eric Fiselierd63f38e2016-03-31 03:13:37 +00001242 return __tree_.__emplace_hint_unique_key_args(__h.__i_, __k,
1243 _VSTD::piecewise_construct,
1244 _VSTD::forward_as_tuple(_VSTD::move(__k)),
Mark de Wever1ba476f2020-09-19 15:39:09 +02001245 _VSTD::forward_as_tuple(_VSTD::forward<_Args>(__args)...)).first;
Marshall Clow3223db82015-07-07 03:37:33 +00001246 }
1247
1248 template <class _Vp>
1249 _LIBCPP_INLINE_VISIBILITY
1250 pair<iterator, bool> insert_or_assign(const key_type& __k, _Vp&& __v)
1251 {
1252 iterator __p = lower_bound(__k);
1253 if ( __p != end() && !key_comp()(__k, __p->first))
1254 {
1255 __p->second = _VSTD::forward<_Vp>(__v);
1256 return _VSTD::make_pair(__p, false);
1257 }
1258 return _VSTD::make_pair(emplace_hint(__p, __k, _VSTD::forward<_Vp>(__v)), true);
1259 }
Eric Fiselierd63f38e2016-03-31 03:13:37 +00001260
Marshall Clow3223db82015-07-07 03:37:33 +00001261 template <class _Vp>
1262 _LIBCPP_INLINE_VISIBILITY
1263 pair<iterator, bool> insert_or_assign(key_type&& __k, _Vp&& __v)
1264 {
1265 iterator __p = lower_bound(__k);
1266 if ( __p != end() && !key_comp()(__k, __p->first))
1267 {
1268 __p->second = _VSTD::forward<_Vp>(__v);
1269 return _VSTD::make_pair(__p, false);
1270 }
1271 return _VSTD::make_pair(emplace_hint(__p, _VSTD::move(__k), _VSTD::forward<_Vp>(__v)), true);
1272 }
1273
1274 template <class _Vp>
Mark de Wever1ba476f2020-09-19 15:39:09 +02001275 _LIBCPP_INLINE_VISIBILITY iterator insert_or_assign(const_iterator __h,
1276 const key_type& __k,
1277 _Vp&& __v) {
1278 auto [__r, __inserted] = __tree_.__emplace_hint_unique_key_args(
1279 __h.__i_, __k, __k, _VSTD::forward<_Vp>(__v));
1280
1281 if (!__inserted)
1282 __r->__get_value().second = _VSTD::forward<_Vp>(__v);
1283
1284 return __r;
1285 }
Marshall Clow3223db82015-07-07 03:37:33 +00001286
1287 template <class _Vp>
Mark de Wever1ba476f2020-09-19 15:39:09 +02001288 _LIBCPP_INLINE_VISIBILITY iterator insert_or_assign(const_iterator __h,
1289 key_type&& __k,
1290 _Vp&& __v) {
1291 auto [__r, __inserted] = __tree_.__emplace_hint_unique_key_args(
1292 __h.__i_, __k, _VSTD::move(__k), _VSTD::forward<_Vp>(__v));
1293
1294 if (!__inserted)
1295 __r->__get_value().second = _VSTD::forward<_Vp>(__v);
1296
1297 return __r;
1298 }
Eric Fiselierd63f38e2016-03-31 03:13:37 +00001299
Eric Fiseliera85b1282017-04-18 21:08:06 +00001300#endif // _LIBCPP_STD_VER > 14
Marshall Clow3223db82015-07-07 03:37:33 +00001301
Howard Hinnant756c69b2010-09-22 16:48:34 +00001302 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001303 iterator erase(const_iterator __p) {return __tree_.erase(__p.__i_);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001304 _LIBCPP_INLINE_VISIBILITY
Marshall Clow22ea5b82015-05-10 13:35:00 +00001305 iterator erase(iterator __p) {return __tree_.erase(__p.__i_);}
1306 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001307 size_type erase(const key_type& __k)
1308 {return __tree_.__erase_unique(__k);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001309 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001310 iterator erase(const_iterator __f, const_iterator __l)
1311 {return __tree_.erase(__f.__i_, __l.__i_);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001312 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001313 void clear() _NOEXCEPT {__tree_.clear();}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001314
Erik Pilkingtonc37a3d82018-08-01 01:33:38 +00001315#if _LIBCPP_STD_VER > 14
1316 _LIBCPP_INLINE_VISIBILITY
1317 insert_return_type insert(node_type&& __nh)
1318 {
1319 _LIBCPP_ASSERT(__nh.empty() || __nh.get_allocator() == get_allocator(),
1320 "node_type with incompatible allocator passed to map::insert()");
1321 return __tree_.template __node_handle_insert_unique<
1322 node_type, insert_return_type>(_VSTD::move(__nh));
1323 }
1324 _LIBCPP_INLINE_VISIBILITY
1325 iterator insert(const_iterator __hint, node_type&& __nh)
1326 {
1327 _LIBCPP_ASSERT(__nh.empty() || __nh.get_allocator() == get_allocator(),
1328 "node_type with incompatible allocator passed to map::insert()");
1329 return __tree_.template __node_handle_insert_unique<node_type>(
1330 __hint.__i_, _VSTD::move(__nh));
1331 }
1332 _LIBCPP_INLINE_VISIBILITY
1333 node_type extract(key_type const& __key)
1334 {
1335 return __tree_.template __node_handle_extract<node_type>(__key);
1336 }
1337 _LIBCPP_INLINE_VISIBILITY
1338 node_type extract(const_iterator __it)
1339 {
1340 return __tree_.template __node_handle_extract<node_type>(__it.__i_);
1341 }
Louis Dionned2322c82018-11-01 14:41:37 +00001342 template <class _Compare2>
Erik Pilkington82a65ad2018-10-31 17:31:35 +00001343 _LIBCPP_INLINE_VISIBILITY
Louis Dionned2322c82018-11-01 14:41:37 +00001344 void merge(map<key_type, mapped_type, _Compare2, allocator_type>& __source)
Erik Pilkington82a65ad2018-10-31 17:31:35 +00001345 {
1346 _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
1347 "merging container with incompatible allocator");
1348 __tree_.__node_handle_merge_unique(__source.__tree_);
1349 }
Louis Dionned2322c82018-11-01 14:41:37 +00001350 template <class _Compare2>
Erik Pilkington82a65ad2018-10-31 17:31:35 +00001351 _LIBCPP_INLINE_VISIBILITY
Louis Dionned2322c82018-11-01 14:41:37 +00001352 void merge(map<key_type, mapped_type, _Compare2, allocator_type>&& __source)
Erik Pilkington82a65ad2018-10-31 17:31:35 +00001353 {
1354 _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
1355 "merging container with incompatible allocator");
1356 __tree_.__node_handle_merge_unique(__source.__tree_);
1357 }
Louis Dionned2322c82018-11-01 14:41:37 +00001358 template <class _Compare2>
Erik Pilkington82a65ad2018-10-31 17:31:35 +00001359 _LIBCPP_INLINE_VISIBILITY
Louis Dionned2322c82018-11-01 14:41:37 +00001360 void merge(multimap<key_type, mapped_type, _Compare2, allocator_type>& __source)
Erik Pilkington82a65ad2018-10-31 17:31:35 +00001361 {
1362 _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
1363 "merging container with incompatible allocator");
1364 __tree_.__node_handle_merge_unique(__source.__tree_);
1365 }
Louis Dionned2322c82018-11-01 14:41:37 +00001366 template <class _Compare2>
Erik Pilkington82a65ad2018-10-31 17:31:35 +00001367 _LIBCPP_INLINE_VISIBILITY
Louis Dionned2322c82018-11-01 14:41:37 +00001368 void merge(multimap<key_type, mapped_type, _Compare2, allocator_type>&& __source)
Erik Pilkington82a65ad2018-10-31 17:31:35 +00001369 {
1370 _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
1371 "merging container with incompatible allocator");
1372 __tree_.__node_handle_merge_unique(__source.__tree_);
1373 }
Erik Pilkingtonc37a3d82018-08-01 01:33:38 +00001374#endif
1375
Howard Hinnant756c69b2010-09-22 16:48:34 +00001376 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001377 void swap(map& __m)
1378 _NOEXCEPT_(__is_nothrow_swappable<__base>::value)
1379 {__tree_.swap(__m.__tree_);}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001380
Howard Hinnant756c69b2010-09-22 16:48:34 +00001381 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001382 iterator find(const key_type& __k) {return __tree_.find(__k);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001383 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001384 const_iterator find(const key_type& __k) const {return __tree_.find(__k);}
Marshall Clowebb57322013-08-13 22:18:47 +00001385#if _LIBCPP_STD_VER > 11
1386 template <typename _K2>
1387 _LIBCPP_INLINE_VISIBILITY
1388 typename enable_if<__is_transparent<_Compare, _K2>::value,iterator>::type
1389 find(const _K2& __k) {return __tree_.find(__k);}
1390 template <typename _K2>
1391 _LIBCPP_INLINE_VISIBILITY
1392 typename enable_if<__is_transparent<_Compare, _K2>::value,const_iterator>::type
1393 find(const _K2& __k) const {return __tree_.find(__k);}
1394#endif
1395
Howard Hinnant756c69b2010-09-22 16:48:34 +00001396 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001397 size_type count(const key_type& __k) const
1398 {return __tree_.__count_unique(__k);}
Marshall Clowe6a5f522014-08-24 23:54:16 +00001399#if _LIBCPP_STD_VER > 11
1400 template <typename _K2>
1401 _LIBCPP_INLINE_VISIBILITY
1402 typename enable_if<__is_transparent<_Compare, _K2>::value,size_type>::type
Eric Fiseliera85c9e92018-02-10 02:53:47 +00001403 count(const _K2& __k) const {return __tree_.__count_multi(__k);}
Marshall Clowe6a5f522014-08-24 23:54:16 +00001404#endif
Zoe Carver3ffbab12019-07-16 03:21:01 +00001405
1406#if _LIBCPP_STD_VER > 17
1407 _LIBCPP_INLINE_VISIBILITY
1408 bool contains(const key_type& __k) const {return find(__k) != end();}
1409#endif // _LIBCPP_STD_VER > 17
1410
Howard Hinnant756c69b2010-09-22 16:48:34 +00001411 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001412 iterator lower_bound(const key_type& __k)
1413 {return __tree_.lower_bound(__k);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001414 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001415 const_iterator lower_bound(const key_type& __k) const
1416 {return __tree_.lower_bound(__k);}
Marshall Clowebb57322013-08-13 22:18:47 +00001417#if _LIBCPP_STD_VER > 11
1418 template <typename _K2>
1419 _LIBCPP_INLINE_VISIBILITY
1420 typename enable_if<__is_transparent<_Compare, _K2>::value,iterator>::type
1421 lower_bound(const _K2& __k) {return __tree_.lower_bound(__k);}
1422
1423 template <typename _K2>
1424 _LIBCPP_INLINE_VISIBILITY
1425 typename enable_if<__is_transparent<_Compare, _K2>::value,const_iterator>::type
1426 lower_bound(const _K2& __k) const {return __tree_.lower_bound(__k);}
1427#endif
1428
Howard Hinnant756c69b2010-09-22 16:48:34 +00001429 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001430 iterator upper_bound(const key_type& __k)
1431 {return __tree_.upper_bound(__k);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001432 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001433 const_iterator upper_bound(const key_type& __k) const
1434 {return __tree_.upper_bound(__k);}
Marshall Clowebb57322013-08-13 22:18:47 +00001435#if _LIBCPP_STD_VER > 11
1436 template <typename _K2>
1437 _LIBCPP_INLINE_VISIBILITY
1438 typename enable_if<__is_transparent<_Compare, _K2>::value,iterator>::type
1439 upper_bound(const _K2& __k) {return __tree_.upper_bound(__k);}
1440 template <typename _K2>
1441 _LIBCPP_INLINE_VISIBILITY
1442 typename enable_if<__is_transparent<_Compare, _K2>::value,const_iterator>::type
1443 upper_bound(const _K2& __k) const {return __tree_.upper_bound(__k);}
1444#endif
1445
Howard Hinnant756c69b2010-09-22 16:48:34 +00001446 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001447 pair<iterator,iterator> equal_range(const key_type& __k)
1448 {return __tree_.__equal_range_unique(__k);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001449 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001450 pair<const_iterator,const_iterator> equal_range(const key_type& __k) const
1451 {return __tree_.__equal_range_unique(__k);}
Marshall Clowebb57322013-08-13 22:18:47 +00001452#if _LIBCPP_STD_VER > 11
1453 template <typename _K2>
1454 _LIBCPP_INLINE_VISIBILITY
1455 typename enable_if<__is_transparent<_Compare, _K2>::value,pair<iterator,iterator>>::type
Eric Fiseliera85c9e92018-02-10 02:53:47 +00001456 equal_range(const _K2& __k) {return __tree_.__equal_range_multi(__k);}
Marshall Clowebb57322013-08-13 22:18:47 +00001457 template <typename _K2>
1458 _LIBCPP_INLINE_VISIBILITY
1459 typename enable_if<__is_transparent<_Compare, _K2>::value,pair<const_iterator,const_iterator>>::type
Eric Fiseliera85c9e92018-02-10 02:53:47 +00001460 equal_range(const _K2& __k) const {return __tree_.__equal_range_multi(__k);}
Marshall Clowebb57322013-08-13 22:18:47 +00001461#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001462
1463private:
1464 typedef typename __base::__node __node;
1465 typedef typename __base::__node_allocator __node_allocator;
1466 typedef typename __base::__node_pointer __node_pointer;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001467 typedef typename __base::__node_base_pointer __node_base_pointer;
Eric Fiseliercf8c0212017-01-05 06:06:18 +00001468 typedef typename __base::__parent_pointer __parent_pointer;
Eric Fiseliera92b0732016-02-20 07:12:17 +00001469
Howard Hinnantc834c512011-11-29 18:15:50 +00001470 typedef __map_node_destructor<__node_allocator> _Dp;
1471 typedef unique_ptr<__node, _Dp> __node_holder;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001472
Eric Fiselierd63f38e2016-03-31 03:13:37 +00001473#ifdef _LIBCPP_CXX03_LANG
Howard Hinnantac7e7482013-07-04 20:59:16 +00001474 __node_holder __construct_node_with_key(const key_type& __k);
Eric Fiselierd63f38e2016-03-31 03:13:37 +00001475#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001476};
1477
Louis Dionned23a5f22019-06-20 19:32:00 +00001478#ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES
1479template<class _InputIterator, class _Compare = less<__iter_key_type<_InputIterator>>,
1480 class _Allocator = allocator<__iter_to_alloc_type<_InputIterator>>,
Louis Dionne6c7da9a2019-07-19 17:13:39 +00001481 class = _EnableIf<!__is_allocator<_Compare>::value, void>,
1482 class = _EnableIf<__is_allocator<_Allocator>::value, void>>
Louis Dionned23a5f22019-06-20 19:32:00 +00001483map(_InputIterator, _InputIterator, _Compare = _Compare(), _Allocator = _Allocator())
1484 -> map<__iter_key_type<_InputIterator>, __iter_mapped_type<_InputIterator>, _Compare, _Allocator>;
1485
1486template<class _Key, class _Tp, class _Compare = less<remove_const_t<_Key>>,
1487 class _Allocator = allocator<pair<const _Key, _Tp>>,
Louis Dionne6c7da9a2019-07-19 17:13:39 +00001488 class = _EnableIf<!__is_allocator<_Compare>::value, void>,
1489 class = _EnableIf<__is_allocator<_Allocator>::value, void>>
Louis Dionned23a5f22019-06-20 19:32:00 +00001490map(initializer_list<pair<_Key, _Tp>>, _Compare = _Compare(), _Allocator = _Allocator())
1491 -> map<remove_const_t<_Key>, _Tp, _Compare, _Allocator>;
1492
1493template<class _InputIterator, class _Allocator,
Louis Dionne6c7da9a2019-07-19 17:13:39 +00001494 class = _EnableIf<__is_allocator<_Allocator>::value, void>>
Louis Dionned23a5f22019-06-20 19:32:00 +00001495map(_InputIterator, _InputIterator, _Allocator)
1496 -> map<__iter_key_type<_InputIterator>, __iter_mapped_type<_InputIterator>,
1497 less<__iter_key_type<_InputIterator>>, _Allocator>;
1498
1499template<class _Key, class _Tp, class _Allocator,
Louis Dionne6c7da9a2019-07-19 17:13:39 +00001500 class = _EnableIf<__is_allocator<_Allocator>::value, void>>
Louis Dionned23a5f22019-06-20 19:32:00 +00001501map(initializer_list<pair<_Key, _Tp>>, _Allocator)
1502 -> map<remove_const_t<_Key>, _Tp, less<remove_const_t<_Key>>, _Allocator>;
1503#endif
Eric Fiseliera92b0732016-02-20 07:12:17 +00001504
Eric Fiselierd06276b2016-03-31 02:15:15 +00001505#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001506template <class _Key, class _Tp, class _Compare, class _Allocator>
1507map<_Key, _Tp, _Compare, _Allocator>::map(map&& __m, const allocator_type& __a)
Marshall Clow657cbc42016-08-17 05:58:40 +00001508 : __tree_(_VSTD::move(__m.__tree_), typename __base::allocator_type(__a))
Howard Hinnantc51e1022010-05-11 19:42:16 +00001509{
1510 if (__a != __m.get_allocator())
1511 {
1512 const_iterator __e = cend();
1513 while (!__m.empty())
1514 __tree_.__insert_unique(__e.__i_,
Erik Pilkingtond3fe2992018-06-04 20:38:23 +00001515 __m.__tree_.remove(__m.begin().__i_)->__value_.__move());
Howard Hinnantc51e1022010-05-11 19:42:16 +00001516 }
1517}
1518
Eric Fiseliera85b1282017-04-18 21:08:06 +00001519template <class _Key, class _Tp, class _Compare, class _Allocator>
1520_Tp&
1521map<_Key, _Tp, _Compare, _Allocator>::operator[](const key_type& __k)
1522{
1523 return __tree_.__emplace_unique_key_args(__k,
1524 _VSTD::piecewise_construct,
1525 _VSTD::forward_as_tuple(__k),
Erik Pilkingtond3fe2992018-06-04 20:38:23 +00001526 _VSTD::forward_as_tuple()).first->__get_value().second;
Eric Fiseliera85b1282017-04-18 21:08:06 +00001527}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001528
Eric Fiseliera85b1282017-04-18 21:08:06 +00001529template <class _Key, class _Tp, class _Compare, class _Allocator>
1530_Tp&
1531map<_Key, _Tp, _Compare, _Allocator>::operator[](key_type&& __k)
1532{
1533 return __tree_.__emplace_unique_key_args(__k,
1534 _VSTD::piecewise_construct,
1535 _VSTD::forward_as_tuple(_VSTD::move(__k)),
Erik Pilkingtond3fe2992018-06-04 20:38:23 +00001536 _VSTD::forward_as_tuple()).first->__get_value().second;
Eric Fiseliera85b1282017-04-18 21:08:06 +00001537}
Eric Fiselierd63f38e2016-03-31 03:13:37 +00001538
Eric Fiseliera85b1282017-04-18 21:08:06 +00001539#else // _LIBCPP_CXX03_LANG
Eric Fiselierd63f38e2016-03-31 03:13:37 +00001540
Howard Hinnantc51e1022010-05-11 19:42:16 +00001541template <class _Key, class _Tp, class _Compare, class _Allocator>
1542typename map<_Key, _Tp, _Compare, _Allocator>::__node_holder
Howard Hinnantac7e7482013-07-04 20:59:16 +00001543map<_Key, _Tp, _Compare, _Allocator>::__construct_node_with_key(const key_type& __k)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001544{
1545 __node_allocator& __na = __tree_.__node_alloc();
Howard Hinnantc834c512011-11-29 18:15:50 +00001546 __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
Erik Pilkingtond3fe2992018-06-04 20:38:23 +00001547 __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__get_value().first), __k);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001548 __h.get_deleter().__first_constructed = true;
Erik Pilkingtond3fe2992018-06-04 20:38:23 +00001549 __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__get_value().second));
Howard Hinnantc51e1022010-05-11 19:42:16 +00001550 __h.get_deleter().__second_constructed = true;
Louis Dionne7b844362020-07-30 09:42:23 -04001551 return __h;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001552}
1553
Howard Hinnantc51e1022010-05-11 19:42:16 +00001554template <class _Key, class _Tp, class _Compare, class _Allocator>
1555_Tp&
1556map<_Key, _Tp, _Compare, _Allocator>::operator[](const key_type& __k)
1557{
Eric Fiseliercf8c0212017-01-05 06:06:18 +00001558 __parent_pointer __parent;
1559 __node_base_pointer& __child = __tree_.__find_equal(__parent, __k);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001560 __node_pointer __r = static_cast<__node_pointer>(__child);
1561 if (__child == nullptr)
1562 {
Howard Hinnantac7e7482013-07-04 20:59:16 +00001563 __node_holder __h = __construct_node_with_key(__k);
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001564 __tree_.__insert_node_at(__parent, __child, static_cast<__node_base_pointer>(__h.get()));
Howard Hinnantc51e1022010-05-11 19:42:16 +00001565 __r = __h.release();
1566 }
Erik Pilkingtond3fe2992018-06-04 20:38:23 +00001567 return __r->__value_.__get_value().second;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001568}
1569
Eric Fiseliera85b1282017-04-18 21:08:06 +00001570#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001571
1572template <class _Key, class _Tp, class _Compare, class _Allocator>
1573_Tp&
1574map<_Key, _Tp, _Compare, _Allocator>::at(const key_type& __k)
1575{
Eric Fiseliercf8c0212017-01-05 06:06:18 +00001576 __parent_pointer __parent;
1577 __node_base_pointer& __child = __tree_.__find_equal(__parent, __k);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001578 if (__child == nullptr)
Louis Dionne2b239162019-02-12 16:06:02 +00001579 __throw_out_of_range("map::at: key not found");
Erik Pilkingtond3fe2992018-06-04 20:38:23 +00001580 return static_cast<__node_pointer>(__child)->__value_.__get_value().second;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001581}
1582
1583template <class _Key, class _Tp, class _Compare, class _Allocator>
1584const _Tp&
1585map<_Key, _Tp, _Compare, _Allocator>::at(const key_type& __k) const
1586{
Eric Fiseliercf8c0212017-01-05 06:06:18 +00001587 __parent_pointer __parent;
1588 __node_base_pointer __child = __tree_.__find_equal(__parent, __k);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001589 if (__child == nullptr)
Louis Dionne2b239162019-02-12 16:06:02 +00001590 __throw_out_of_range("map::at: key not found");
Erik Pilkingtond3fe2992018-06-04 20:38:23 +00001591 return static_cast<__node_pointer>(__child)->__value_.__get_value().second;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001592}
1593
Howard Hinnantc51e1022010-05-11 19:42:16 +00001594
1595template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001596inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001597bool
1598operator==(const map<_Key, _Tp, _Compare, _Allocator>& __x,
1599 const map<_Key, _Tp, _Compare, _Allocator>& __y)
1600{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001601 return __x.size() == __y.size() && _VSTD::equal(__x.begin(), __x.end(), __y.begin());
Howard Hinnantc51e1022010-05-11 19:42:16 +00001602}
1603
1604template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001605inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001606bool
1607operator< (const map<_Key, _Tp, _Compare, _Allocator>& __x,
1608 const map<_Key, _Tp, _Compare, _Allocator>& __y)
1609{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001610 return _VSTD::lexicographical_compare(__x.begin(), __x.end(), __y.begin(), __y.end());
Howard Hinnantc51e1022010-05-11 19:42:16 +00001611}
1612
1613template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001614inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001615bool
1616operator!=(const map<_Key, _Tp, _Compare, _Allocator>& __x,
1617 const map<_Key, _Tp, _Compare, _Allocator>& __y)
1618{
1619 return !(__x == __y);
1620}
1621
1622template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001623inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001624bool
1625operator> (const map<_Key, _Tp, _Compare, _Allocator>& __x,
1626 const map<_Key, _Tp, _Compare, _Allocator>& __y)
1627{
1628 return __y < __x;
1629}
1630
1631template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001632inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001633bool
1634operator>=(const map<_Key, _Tp, _Compare, _Allocator>& __x,
1635 const map<_Key, _Tp, _Compare, _Allocator>& __y)
1636{
1637 return !(__x < __y);
1638}
1639
1640template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001641inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001642bool
1643operator<=(const map<_Key, _Tp, _Compare, _Allocator>& __x,
1644 const map<_Key, _Tp, _Compare, _Allocator>& __y)
1645{
1646 return !(__y < __x);
1647}
1648
1649template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001650inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001651void
1652swap(map<_Key, _Tp, _Compare, _Allocator>& __x,
1653 map<_Key, _Tp, _Compare, _Allocator>& __y)
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001654 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
Howard Hinnantc51e1022010-05-11 19:42:16 +00001655{
1656 __x.swap(__y);
1657}
1658
Marshall Clow29b53f22018-12-14 18:49:35 +00001659#if _LIBCPP_STD_VER > 17
Marek Kurdeja98b1412020-05-02 13:58:03 +02001660template <class _Key, class _Tp, class _Compare, class _Allocator,
1661 class _Predicate>
Marshall Clow29b53f22018-12-14 18:49:35 +00001662inline _LIBCPP_INLINE_VISIBILITY
Marek Kurdeja98b1412020-05-02 13:58:03 +02001663 typename map<_Key, _Tp, _Compare, _Allocator>::size_type
1664 erase_if(map<_Key, _Tp, _Compare, _Allocator>& __c, _Predicate __pred) {
Arthur O'Dwyerb6738bd2021-03-21 16:53:09 -04001665 return _VSTD::__libcpp_erase_if_container(__c, __pred);
Marek Kurdeja98b1412020-05-02 13:58:03 +02001666}
Marshall Clow29b53f22018-12-14 18:49:35 +00001667#endif
1668
1669
Howard Hinnantc51e1022010-05-11 19:42:16 +00001670template <class _Key, class _Tp, class _Compare = less<_Key>,
1671 class _Allocator = allocator<pair<const _Key, _Tp> > >
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00001672class _LIBCPP_TEMPLATE_VIS multimap
Howard Hinnantc51e1022010-05-11 19:42:16 +00001673{
1674public:
1675 // types:
1676 typedef _Key key_type;
1677 typedef _Tp mapped_type;
1678 typedef pair<const key_type, mapped_type> value_type;
Arthur O'Dwyer6a752e12021-03-03 11:10:49 -05001679 typedef __identity_t<_Compare> key_compare;
1680 typedef __identity_t<_Allocator> allocator_type;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001681 typedef value_type& reference;
1682 typedef const value_type& const_reference;
1683
Marshall Clow5128cf32015-11-26 01:24:04 +00001684 static_assert((is_same<typename allocator_type::value_type, value_type>::value),
1685 "Allocator::value_type must be same type as value_type");
1686
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00001687 class _LIBCPP_TEMPLATE_VIS value_compare
Howard Hinnantc51e1022010-05-11 19:42:16 +00001688 : public binary_function<value_type, value_type, bool>
1689 {
1690 friend class multimap;
1691 protected:
1692 key_compare comp;
1693
Howard Hinnant756c69b2010-09-22 16:48:34 +00001694 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001695 value_compare(key_compare c) : comp(c) {}
1696 public:
Howard Hinnant756c69b2010-09-22 16:48:34 +00001697 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001698 bool operator()(const value_type& __x, const value_type& __y) const
1699 {return comp(__x.first, __y.first);}
1700 };
1701
1702private:
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001703
Howard Hinnant89f8b792013-09-30 19:08:22 +00001704 typedef _VSTD::__value_type<key_type, mapped_type> __value_type;
Howard Hinnant90b91592013-07-05 18:06:00 +00001705 typedef __map_value_compare<key_type, __value_type, key_compare> __vc;
Marshall Clow940e01c2015-04-07 05:21:38 +00001706 typedef typename __rebind_alloc_helper<allocator_traits<allocator_type>,
1707 __value_type>::type __allocator_type;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001708 typedef __tree<__value_type, __vc, __allocator_type> __base;
1709 typedef typename __base::__node_traits __node_traits;
1710 typedef allocator_traits<allocator_type> __alloc_traits;
1711
1712 __base __tree_;
1713
1714public:
1715 typedef typename __alloc_traits::pointer pointer;
1716 typedef typename __alloc_traits::const_pointer const_pointer;
1717 typedef typename __alloc_traits::size_type size_type;
1718 typedef typename __alloc_traits::difference_type difference_type;
1719 typedef __map_iterator<typename __base::iterator> iterator;
1720 typedef __map_const_iterator<typename __base::const_iterator> const_iterator;
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001721 typedef _VSTD::reverse_iterator<iterator> reverse_iterator;
1722 typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001723
Erik Pilkingtonc37a3d82018-08-01 01:33:38 +00001724#if _LIBCPP_STD_VER > 14
1725 typedef __map_node_handle<typename __base::__node, allocator_type> node_type;
1726#endif
1727
Erik Pilkington82a65ad2018-10-31 17:31:35 +00001728 template <class _Key2, class _Value2, class _Comp2, class _Alloc2>
1729 friend class _LIBCPP_TEMPLATE_VIS map;
1730 template <class _Key2, class _Value2, class _Comp2, class _Alloc2>
1731 friend class _LIBCPP_TEMPLATE_VIS multimap;
1732
Howard Hinnant756c69b2010-09-22 16:48:34 +00001733 _LIBCPP_INLINE_VISIBILITY
Marshall Clow7086a5a2014-03-10 04:50:10 +00001734 multimap()
1735 _NOEXCEPT_(
1736 is_nothrow_default_constructible<allocator_type>::value &&
1737 is_nothrow_default_constructible<key_compare>::value &&
1738 is_nothrow_copy_constructible<key_compare>::value)
1739 : __tree_(__vc(key_compare())) {}
1740
1741 _LIBCPP_INLINE_VISIBILITY
1742 explicit multimap(const key_compare& __comp)
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001743 _NOEXCEPT_(
1744 is_nothrow_default_constructible<allocator_type>::value &&
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001745 is_nothrow_copy_constructible<key_compare>::value)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001746 : __tree_(__vc(__comp)) {}
1747
Howard Hinnant756c69b2010-09-22 16:48:34 +00001748 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001749 explicit multimap(const key_compare& __comp, const allocator_type& __a)
Marshall Clow657cbc42016-08-17 05:58:40 +00001750 : __tree_(__vc(__comp), typename __base::allocator_type(__a)) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001751
1752 template <class _InputIterator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001753 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001754 multimap(_InputIterator __f, _InputIterator __l,
1755 const key_compare& __comp = key_compare())
1756 : __tree_(__vc(__comp))
1757 {
1758 insert(__f, __l);
1759 }
1760
1761 template <class _InputIterator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001762 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001763 multimap(_InputIterator __f, _InputIterator __l,
1764 const key_compare& __comp, const allocator_type& __a)
Marshall Clow657cbc42016-08-17 05:58:40 +00001765 : __tree_(__vc(__comp), typename __base::allocator_type(__a))
Howard Hinnantc51e1022010-05-11 19:42:16 +00001766 {
1767 insert(__f, __l);
1768 }
1769
Marshall Clow300abfb2013-09-11 01:15:47 +00001770#if _LIBCPP_STD_VER > 11
1771 template <class _InputIterator>
Eric Fiseliercf8c0212017-01-05 06:06:18 +00001772 _LIBCPP_INLINE_VISIBILITY
Marshall Clow300abfb2013-09-11 01:15:47 +00001773 multimap(_InputIterator __f, _InputIterator __l, const allocator_type& __a)
1774 : multimap(__f, __l, key_compare(), __a) {}
1775#endif
1776
Howard Hinnant756c69b2010-09-22 16:48:34 +00001777 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001778 multimap(const multimap& __m)
1779 : __tree_(__m.__tree_.value_comp(),
1780 __alloc_traits::select_on_container_copy_construction(__m.__tree_.__alloc()))
1781 {
1782 insert(__m.begin(), __m.end());
1783 }
1784
Howard Hinnantd3a657f2011-07-01 19:24:36 +00001785 _LIBCPP_INLINE_VISIBILITY
1786 multimap& operator=(const multimap& __m)
1787 {
Marshall Clow476d3f42016-07-18 13:19:00 +00001788#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantd3a657f2011-07-01 19:24:36 +00001789 __tree_ = __m.__tree_;
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001790#else
Marshall Clowdb3cfcb2014-02-08 04:03:14 +00001791 if (this != &__m) {
1792 __tree_.clear();
1793 __tree_.value_comp() = __m.__tree_.value_comp();
1794 __tree_.__copy_assign_alloc(__m.__tree_);
1795 insert(__m.begin(), __m.end());
1796 }
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001797#endif
Howard Hinnantd3a657f2011-07-01 19:24:36 +00001798 return *this;
1799 }
1800
Eric Fiseliera85b1282017-04-18 21:08:06 +00001801#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001802
Howard Hinnant756c69b2010-09-22 16:48:34 +00001803 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001804 multimap(multimap&& __m)
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001805 _NOEXCEPT_(is_nothrow_move_constructible<__base>::value)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001806 : __tree_(_VSTD::move(__m.__tree_))
Howard Hinnantc51e1022010-05-11 19:42:16 +00001807 {
1808 }
1809
1810 multimap(multimap&& __m, const allocator_type& __a);
1811
Howard Hinnant756c69b2010-09-22 16:48:34 +00001812 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant33711792011-08-12 21:56:02 +00001813 multimap& operator=(multimap&& __m)
1814 _NOEXCEPT_(is_nothrow_move_assignable<__base>::value)
1815 {
1816 __tree_ = _VSTD::move(__m.__tree_);
1817 return *this;
1818 }
1819
Howard Hinnant33711792011-08-12 21:56:02 +00001820 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001821 multimap(initializer_list<value_type> __il, const key_compare& __comp = key_compare())
1822 : __tree_(__vc(__comp))
1823 {
1824 insert(__il.begin(), __il.end());
1825 }
1826
Howard Hinnant756c69b2010-09-22 16:48:34 +00001827 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001828 multimap(initializer_list<value_type> __il, const key_compare& __comp, const allocator_type& __a)
Marshall Clow657cbc42016-08-17 05:58:40 +00001829 : __tree_(__vc(__comp), typename __base::allocator_type(__a))
Howard Hinnantc51e1022010-05-11 19:42:16 +00001830 {
1831 insert(__il.begin(), __il.end());
1832 }
1833
Marshall Clow300abfb2013-09-11 01:15:47 +00001834#if _LIBCPP_STD_VER > 11
Eric Fiseliercf8c0212017-01-05 06:06:18 +00001835 _LIBCPP_INLINE_VISIBILITY
Marshall Clow300abfb2013-09-11 01:15:47 +00001836 multimap(initializer_list<value_type> __il, const allocator_type& __a)
1837 : multimap(__il, key_compare(), __a) {}
1838#endif
1839
Howard Hinnant756c69b2010-09-22 16:48:34 +00001840 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001841 multimap& operator=(initializer_list<value_type> __il)
1842 {
1843 __tree_.__assign_multi(__il.begin(), __il.end());
1844 return *this;
1845 }
Howard Hinnant33711792011-08-12 21:56:02 +00001846
Eric Fiseliera85b1282017-04-18 21:08:06 +00001847#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001848
Howard Hinnant756c69b2010-09-22 16:48:34 +00001849 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001850 explicit multimap(const allocator_type& __a)
Marshall Clow657cbc42016-08-17 05:58:40 +00001851 : __tree_(typename __base::allocator_type(__a))
Howard Hinnantc51e1022010-05-11 19:42:16 +00001852 {
1853 }
1854
Howard Hinnant756c69b2010-09-22 16:48:34 +00001855 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001856 multimap(const multimap& __m, const allocator_type& __a)
Marshall Clow657cbc42016-08-17 05:58:40 +00001857 : __tree_(__m.__tree_.value_comp(), typename __base::allocator_type(__a))
Howard Hinnantc51e1022010-05-11 19:42:16 +00001858 {
1859 insert(__m.begin(), __m.end());
1860 }
1861
Howard Hinnant756c69b2010-09-22 16:48:34 +00001862 _LIBCPP_INLINE_VISIBILITY
Louis Dionne69c42c02019-04-11 16:14:56 +00001863 ~multimap() {
1864 static_assert(sizeof(__diagnose_non_const_comparator<_Key, _Compare>()), "");
1865 }
1866
1867 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001868 iterator begin() _NOEXCEPT {return __tree_.begin();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001869 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001870 const_iterator begin() const _NOEXCEPT {return __tree_.begin();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001871 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001872 iterator end() _NOEXCEPT {return __tree_.end();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001873 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001874 const_iterator end() const _NOEXCEPT {return __tree_.end();}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001875
Howard Hinnant756c69b2010-09-22 16:48:34 +00001876 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001877 reverse_iterator rbegin() _NOEXCEPT {return reverse_iterator(end());}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001878 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001879 const_reverse_iterator rbegin() const _NOEXCEPT
1880 {return const_reverse_iterator(end());}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001881 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001882 reverse_iterator rend() _NOEXCEPT {return reverse_iterator(begin());}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001883 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001884 const_reverse_iterator rend() const _NOEXCEPT
1885 {return const_reverse_iterator(begin());}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001886
Howard Hinnant756c69b2010-09-22 16:48:34 +00001887 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001888 const_iterator cbegin() const _NOEXCEPT {return begin();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001889 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001890 const_iterator cend() const _NOEXCEPT {return end();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001891 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001892 const_reverse_iterator crbegin() const _NOEXCEPT {return rbegin();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001893 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001894 const_reverse_iterator crend() const _NOEXCEPT {return rend();}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001895
Marshall Clow425f5752017-11-15 05:51:26 +00001896 _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001897 bool empty() const _NOEXCEPT {return __tree_.size() == 0;}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001898 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001899 size_type size() const _NOEXCEPT {return __tree_.size();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001900 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001901 size_type max_size() const _NOEXCEPT {return __tree_.max_size();}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001902
Howard Hinnant756c69b2010-09-22 16:48:34 +00001903 _LIBCPP_INLINE_VISIBILITY
Marshall Clow657cbc42016-08-17 05:58:40 +00001904 allocator_type get_allocator() const _NOEXCEPT {return allocator_type(__tree_.__alloc());}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001905 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001906 key_compare key_comp() const {return __tree_.value_comp().key_comp();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001907 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001908 value_compare value_comp() const
1909 {return value_compare(__tree_.value_comp().key_comp());}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001910
Eric Fiselierd06276b2016-03-31 02:15:15 +00001911#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant74279a52010-09-04 23:28:19 +00001912
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001913 template <class ..._Args>
Eric Fiselierd06276b2016-03-31 02:15:15 +00001914 _LIBCPP_INLINE_VISIBILITY
1915 iterator emplace(_Args&& ...__args) {
1916 return __tree_.__emplace_multi(_VSTD::forward<_Args>(__args)...);
1917 }
Howard Hinnantc51e1022010-05-11 19:42:16 +00001918
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001919 template <class ..._Args>
Eric Fiselierd06276b2016-03-31 02:15:15 +00001920 _LIBCPP_INLINE_VISIBILITY
1921 iterator emplace_hint(const_iterator __p, _Args&& ...__args) {
1922 return __tree_.__emplace_hint_multi(__p.__i_, _VSTD::forward<_Args>(__args)...);
1923 }
Howard Hinnant74279a52010-09-04 23:28:19 +00001924
Howard Hinnantc834c512011-11-29 18:15:50 +00001925 template <class _Pp,
1926 class = typename enable_if<is_constructible<value_type, _Pp>::value>::type>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001927 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc834c512011-11-29 18:15:50 +00001928 iterator insert(_Pp&& __p)
1929 {return __tree_.__insert_multi(_VSTD::forward<_Pp>(__p));}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001930
Howard Hinnantc834c512011-11-29 18:15:50 +00001931 template <class _Pp,
1932 class = typename enable_if<is_constructible<value_type, _Pp>::value>::type>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001933 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc834c512011-11-29 18:15:50 +00001934 iterator insert(const_iterator __pos, _Pp&& __p)
1935 {return __tree_.__insert_multi(__pos.__i_, _VSTD::forward<_Pp>(__p));}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001936
Eric Fiselierd6143132016-04-18 01:40:45 +00001937 _LIBCPP_INLINE_VISIBILITY
1938 iterator insert(value_type&& __v)
1939 {return __tree_.__insert_multi(_VSTD::move(__v));}
1940
1941 _LIBCPP_INLINE_VISIBILITY
1942 iterator insert(const_iterator __p, value_type&& __v)
1943 {return __tree_.__insert_multi(__p.__i_, _VSTD::move(__v));}
1944
Eric Fiseliera85b1282017-04-18 21:08:06 +00001945
1946 _LIBCPP_INLINE_VISIBILITY
1947 void insert(initializer_list<value_type> __il)
1948 {insert(__il.begin(), __il.end());}
1949
Eric Fiselierd06276b2016-03-31 02:15:15 +00001950#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001951
Howard Hinnant756c69b2010-09-22 16:48:34 +00001952 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001953 iterator insert(const value_type& __v) {return __tree_.__insert_multi(__v);}
1954
Howard Hinnant756c69b2010-09-22 16:48:34 +00001955 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001956 iterator insert(const_iterator __p, const value_type& __v)
1957 {return __tree_.__insert_multi(__p.__i_, __v);}
1958
1959 template <class _InputIterator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001960 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001961 void insert(_InputIterator __f, _InputIterator __l)
1962 {
1963 for (const_iterator __e = cend(); __f != __l; ++__f)
1964 __tree_.__insert_multi(__e.__i_, *__f);
1965 }
1966
Howard Hinnant756c69b2010-09-22 16:48:34 +00001967 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001968 iterator erase(const_iterator __p) {return __tree_.erase(__p.__i_);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001969 _LIBCPP_INLINE_VISIBILITY
Marshall Clow22ea5b82015-05-10 13:35:00 +00001970 iterator erase(iterator __p) {return __tree_.erase(__p.__i_);}
1971 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001972 size_type erase(const key_type& __k) {return __tree_.__erase_multi(__k);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001973 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001974 iterator erase(const_iterator __f, const_iterator __l)
1975 {return __tree_.erase(__f.__i_, __l.__i_);}
Erik Pilkingtonc37a3d82018-08-01 01:33:38 +00001976
1977#if _LIBCPP_STD_VER > 14
1978 _LIBCPP_INLINE_VISIBILITY
1979 iterator insert(node_type&& __nh)
1980 {
1981 _LIBCPP_ASSERT(__nh.empty() || __nh.get_allocator() == get_allocator(),
1982 "node_type with incompatible allocator passed to multimap::insert()");
1983 return __tree_.template __node_handle_insert_multi<node_type>(
1984 _VSTD::move(__nh));
1985 }
1986 _LIBCPP_INLINE_VISIBILITY
1987 iterator insert(const_iterator __hint, node_type&& __nh)
1988 {
1989 _LIBCPP_ASSERT(__nh.empty() || __nh.get_allocator() == get_allocator(),
1990 "node_type with incompatible allocator passed to multimap::insert()");
1991 return __tree_.template __node_handle_insert_multi<node_type>(
1992 __hint.__i_, _VSTD::move(__nh));
1993 }
1994 _LIBCPP_INLINE_VISIBILITY
1995 node_type extract(key_type const& __key)
1996 {
1997 return __tree_.template __node_handle_extract<node_type>(__key);
1998 }
1999 _LIBCPP_INLINE_VISIBILITY
2000 node_type extract(const_iterator __it)
2001 {
2002 return __tree_.template __node_handle_extract<node_type>(
2003 __it.__i_);
2004 }
Louis Dionned2322c82018-11-01 14:41:37 +00002005 template <class _Compare2>
Erik Pilkington82a65ad2018-10-31 17:31:35 +00002006 _LIBCPP_INLINE_VISIBILITY
Louis Dionned2322c82018-11-01 14:41:37 +00002007 void merge(multimap<key_type, mapped_type, _Compare2, allocator_type>& __source)
Erik Pilkington82a65ad2018-10-31 17:31:35 +00002008 {
2009 _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
2010 "merging container with incompatible allocator");
2011 return __tree_.__node_handle_merge_multi(__source.__tree_);
2012 }
Louis Dionned2322c82018-11-01 14:41:37 +00002013 template <class _Compare2>
Erik Pilkington82a65ad2018-10-31 17:31:35 +00002014 _LIBCPP_INLINE_VISIBILITY
Louis Dionned2322c82018-11-01 14:41:37 +00002015 void merge(multimap<key_type, mapped_type, _Compare2, allocator_type>&& __source)
Erik Pilkington82a65ad2018-10-31 17:31:35 +00002016 {
2017 _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
2018 "merging container with incompatible allocator");
2019 return __tree_.__node_handle_merge_multi(__source.__tree_);
2020 }
Louis Dionned2322c82018-11-01 14:41:37 +00002021 template <class _Compare2>
Erik Pilkington82a65ad2018-10-31 17:31:35 +00002022 _LIBCPP_INLINE_VISIBILITY
Louis Dionned2322c82018-11-01 14:41:37 +00002023 void merge(map<key_type, mapped_type, _Compare2, allocator_type>& __source)
Erik Pilkington82a65ad2018-10-31 17:31:35 +00002024 {
2025 _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
2026 "merging container with incompatible allocator");
2027 return __tree_.__node_handle_merge_multi(__source.__tree_);
2028 }
Louis Dionned2322c82018-11-01 14:41:37 +00002029 template <class _Compare2>
Erik Pilkington82a65ad2018-10-31 17:31:35 +00002030 _LIBCPP_INLINE_VISIBILITY
Louis Dionned2322c82018-11-01 14:41:37 +00002031 void merge(map<key_type, mapped_type, _Compare2, allocator_type>&& __source)
Erik Pilkington82a65ad2018-10-31 17:31:35 +00002032 {
2033 _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
2034 "merging container with incompatible allocator");
2035 return __tree_.__node_handle_merge_multi(__source.__tree_);
2036 }
Erik Pilkingtonc37a3d82018-08-01 01:33:38 +00002037#endif
2038
Howard Hinnant756c69b2010-09-22 16:48:34 +00002039 _LIBCPP_INLINE_VISIBILITY
Marshall Clowde1312a2018-08-22 04:28:43 +00002040 void clear() _NOEXCEPT {__tree_.clear();}
Howard Hinnantc51e1022010-05-11 19:42:16 +00002041
Howard Hinnant756c69b2010-09-22 16:48:34 +00002042 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00002043 void swap(multimap& __m)
2044 _NOEXCEPT_(__is_nothrow_swappable<__base>::value)
2045 {__tree_.swap(__m.__tree_);}
Howard Hinnantc51e1022010-05-11 19:42:16 +00002046
Howard Hinnant756c69b2010-09-22 16:48:34 +00002047 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002048 iterator find(const key_type& __k) {return __tree_.find(__k);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00002049 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002050 const_iterator find(const key_type& __k) const {return __tree_.find(__k);}
Marshall Clowebb57322013-08-13 22:18:47 +00002051#if _LIBCPP_STD_VER > 11
2052 template <typename _K2>
2053 _LIBCPP_INLINE_VISIBILITY
2054 typename enable_if<__is_transparent<_Compare, _K2>::value,iterator>::type
2055 find(const _K2& __k) {return __tree_.find(__k);}
2056 template <typename _K2>
2057 _LIBCPP_INLINE_VISIBILITY
2058 typename enable_if<__is_transparent<_Compare, _K2>::value,const_iterator>::type
2059 find(const _K2& __k) const {return __tree_.find(__k);}
2060#endif
2061
Howard Hinnant756c69b2010-09-22 16:48:34 +00002062 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002063 size_type count(const key_type& __k) const
2064 {return __tree_.__count_multi(__k);}
Marshall Clowe6a5f522014-08-24 23:54:16 +00002065#if _LIBCPP_STD_VER > 11
2066 template <typename _K2>
2067 _LIBCPP_INLINE_VISIBILITY
2068 typename enable_if<__is_transparent<_Compare, _K2>::value,size_type>::type
Marshall Clow141e47b2015-06-30 18:15:41 +00002069 count(const _K2& __k) const {return __tree_.__count_multi(__k);}
Marshall Clowe6a5f522014-08-24 23:54:16 +00002070#endif
Zoe Carver3ffbab12019-07-16 03:21:01 +00002071
2072#if _LIBCPP_STD_VER > 17
2073 _LIBCPP_INLINE_VISIBILITY
2074 bool contains(const key_type& __k) const {return find(__k) != end();}
2075#endif // _LIBCPP_STD_VER > 17
2076
Howard Hinnant756c69b2010-09-22 16:48:34 +00002077 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002078 iterator lower_bound(const key_type& __k)
2079 {return __tree_.lower_bound(__k);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00002080 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002081 const_iterator lower_bound(const key_type& __k) const
2082 {return __tree_.lower_bound(__k);}
Marshall Clowebb57322013-08-13 22:18:47 +00002083#if _LIBCPP_STD_VER > 11
2084 template <typename _K2>
2085 _LIBCPP_INLINE_VISIBILITY
2086 typename enable_if<__is_transparent<_Compare, _K2>::value,iterator>::type
2087 lower_bound(const _K2& __k) {return __tree_.lower_bound(__k);}
2088
2089 template <typename _K2>
2090 _LIBCPP_INLINE_VISIBILITY
2091 typename enable_if<__is_transparent<_Compare, _K2>::value,const_iterator>::type
2092 lower_bound(const _K2& __k) const {return __tree_.lower_bound(__k);}
2093#endif
2094
Howard Hinnant756c69b2010-09-22 16:48:34 +00002095 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002096 iterator upper_bound(const key_type& __k)
2097 {return __tree_.upper_bound(__k);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00002098 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002099 const_iterator upper_bound(const key_type& __k) const
2100 {return __tree_.upper_bound(__k);}
Marshall Clowebb57322013-08-13 22:18:47 +00002101#if _LIBCPP_STD_VER > 11
2102 template <typename _K2>
2103 _LIBCPP_INLINE_VISIBILITY
2104 typename enable_if<__is_transparent<_Compare, _K2>::value,iterator>::type
2105 upper_bound(const _K2& __k) {return __tree_.upper_bound(__k);}
2106 template <typename _K2>
2107 _LIBCPP_INLINE_VISIBILITY
2108 typename enable_if<__is_transparent<_Compare, _K2>::value,const_iterator>::type
2109 upper_bound(const _K2& __k) const {return __tree_.upper_bound(__k);}
2110#endif
2111
Howard Hinnant756c69b2010-09-22 16:48:34 +00002112 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002113 pair<iterator,iterator> equal_range(const key_type& __k)
2114 {return __tree_.__equal_range_multi(__k);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00002115 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002116 pair<const_iterator,const_iterator> equal_range(const key_type& __k) const
2117 {return __tree_.__equal_range_multi(__k);}
Marshall Clowebb57322013-08-13 22:18:47 +00002118#if _LIBCPP_STD_VER > 11
2119 template <typename _K2>
2120 _LIBCPP_INLINE_VISIBILITY
2121 typename enable_if<__is_transparent<_Compare, _K2>::value,pair<iterator,iterator>>::type
2122 equal_range(const _K2& __k) {return __tree_.__equal_range_multi(__k);}
2123 template <typename _K2>
2124 _LIBCPP_INLINE_VISIBILITY
2125 typename enable_if<__is_transparent<_Compare, _K2>::value,pair<const_iterator,const_iterator>>::type
2126 equal_range(const _K2& __k) const {return __tree_.__equal_range_multi(__k);}
2127#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00002128
2129private:
2130 typedef typename __base::__node __node;
2131 typedef typename __base::__node_allocator __node_allocator;
2132 typedef typename __base::__node_pointer __node_pointer;
Eric Fiseliera92b0732016-02-20 07:12:17 +00002133
Howard Hinnantc834c512011-11-29 18:15:50 +00002134 typedef __map_node_destructor<__node_allocator> _Dp;
2135 typedef unique_ptr<__node, _Dp> __node_holder;
Howard Hinnantc51e1022010-05-11 19:42:16 +00002136};
2137
Louis Dionned23a5f22019-06-20 19:32:00 +00002138#ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES
2139template<class _InputIterator, class _Compare = less<__iter_key_type<_InputIterator>>,
2140 class _Allocator = allocator<__iter_to_alloc_type<_InputIterator>>,
Louis Dionne6c7da9a2019-07-19 17:13:39 +00002141 class = _EnableIf<!__is_allocator<_Compare>::value, void>,
2142 class = _EnableIf<__is_allocator<_Allocator>::value, void>>
Louis Dionned23a5f22019-06-20 19:32:00 +00002143multimap(_InputIterator, _InputIterator, _Compare = _Compare(), _Allocator = _Allocator())
2144 -> multimap<__iter_key_type<_InputIterator>, __iter_mapped_type<_InputIterator>, _Compare, _Allocator>;
2145
2146template<class _Key, class _Tp, class _Compare = less<remove_const_t<_Key>>,
2147 class _Allocator = allocator<pair<const _Key, _Tp>>,
Louis Dionne6c7da9a2019-07-19 17:13:39 +00002148 class = _EnableIf<!__is_allocator<_Compare>::value, void>,
2149 class = _EnableIf<__is_allocator<_Allocator>::value, void>>
Louis Dionned23a5f22019-06-20 19:32:00 +00002150multimap(initializer_list<pair<_Key, _Tp>>, _Compare = _Compare(), _Allocator = _Allocator())
2151 -> multimap<remove_const_t<_Key>, _Tp, _Compare, _Allocator>;
2152
2153template<class _InputIterator, class _Allocator,
Louis Dionne6c7da9a2019-07-19 17:13:39 +00002154 class = _EnableIf<__is_allocator<_Allocator>::value, void>>
Louis Dionned23a5f22019-06-20 19:32:00 +00002155multimap(_InputIterator, _InputIterator, _Allocator)
2156 -> multimap<__iter_key_type<_InputIterator>, __iter_mapped_type<_InputIterator>,
2157 less<__iter_key_type<_InputIterator>>, _Allocator>;
2158
2159template<class _Key, class _Tp, class _Allocator,
Louis Dionne6c7da9a2019-07-19 17:13:39 +00002160 class = _EnableIf<__is_allocator<_Allocator>::value, void>>
Louis Dionned23a5f22019-06-20 19:32:00 +00002161multimap(initializer_list<pair<_Key, _Tp>>, _Allocator)
2162 -> multimap<remove_const_t<_Key>, _Tp, less<remove_const_t<_Key>>, _Allocator>;
2163#endif
2164
Eric Fiselierd06276b2016-03-31 02:15:15 +00002165#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00002166template <class _Key, class _Tp, class _Compare, class _Allocator>
2167multimap<_Key, _Tp, _Compare, _Allocator>::multimap(multimap&& __m, const allocator_type& __a)
Marshall Clow657cbc42016-08-17 05:58:40 +00002168 : __tree_(_VSTD::move(__m.__tree_), typename __base::allocator_type(__a))
Howard Hinnantc51e1022010-05-11 19:42:16 +00002169{
2170 if (__a != __m.get_allocator())
2171 {
2172 const_iterator __e = cend();
2173 while (!__m.empty())
2174 __tree_.__insert_multi(__e.__i_,
Erik Pilkingtond3fe2992018-06-04 20:38:23 +00002175 _VSTD::move(__m.__tree_.remove(__m.begin().__i_)->__value_.__move()));
Howard Hinnantc51e1022010-05-11 19:42:16 +00002176 }
2177}
Eric Fiselierd06276b2016-03-31 02:15:15 +00002178#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00002179
2180template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00002181inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002182bool
2183operator==(const multimap<_Key, _Tp, _Compare, _Allocator>& __x,
2184 const multimap<_Key, _Tp, _Compare, _Allocator>& __y)
2185{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00002186 return __x.size() == __y.size() && _VSTD::equal(__x.begin(), __x.end(), __y.begin());
Howard Hinnantc51e1022010-05-11 19:42:16 +00002187}
2188
2189template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00002190inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002191bool
2192operator< (const multimap<_Key, _Tp, _Compare, _Allocator>& __x,
2193 const multimap<_Key, _Tp, _Compare, _Allocator>& __y)
2194{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00002195 return _VSTD::lexicographical_compare(__x.begin(), __x.end(), __y.begin(), __y.end());
Howard Hinnantc51e1022010-05-11 19:42:16 +00002196}
2197
2198template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00002199inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002200bool
2201operator!=(const multimap<_Key, _Tp, _Compare, _Allocator>& __x,
2202 const multimap<_Key, _Tp, _Compare, _Allocator>& __y)
2203{
2204 return !(__x == __y);
2205}
2206
2207template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00002208inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002209bool
2210operator> (const multimap<_Key, _Tp, _Compare, _Allocator>& __x,
2211 const multimap<_Key, _Tp, _Compare, _Allocator>& __y)
2212{
2213 return __y < __x;
2214}
2215
2216template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00002217inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002218bool
2219operator>=(const multimap<_Key, _Tp, _Compare, _Allocator>& __x,
2220 const multimap<_Key, _Tp, _Compare, _Allocator>& __y)
2221{
2222 return !(__x < __y);
2223}
2224
2225template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00002226inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002227bool
2228operator<=(const multimap<_Key, _Tp, _Compare, _Allocator>& __x,
2229 const multimap<_Key, _Tp, _Compare, _Allocator>& __y)
2230{
2231 return !(__y < __x);
2232}
2233
2234template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00002235inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002236void
2237swap(multimap<_Key, _Tp, _Compare, _Allocator>& __x,
2238 multimap<_Key, _Tp, _Compare, _Allocator>& __y)
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00002239 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
Howard Hinnantc51e1022010-05-11 19:42:16 +00002240{
2241 __x.swap(__y);
2242}
2243
Marshall Clow29b53f22018-12-14 18:49:35 +00002244#if _LIBCPP_STD_VER > 17
Marek Kurdeja98b1412020-05-02 13:58:03 +02002245template <class _Key, class _Tp, class _Compare, class _Allocator,
2246 class _Predicate>
Marshall Clow29b53f22018-12-14 18:49:35 +00002247inline _LIBCPP_INLINE_VISIBILITY
Marek Kurdeja98b1412020-05-02 13:58:03 +02002248 typename multimap<_Key, _Tp, _Compare, _Allocator>::size_type
2249 erase_if(multimap<_Key, _Tp, _Compare, _Allocator>& __c,
2250 _Predicate __pred) {
Arthur O'Dwyerb6738bd2021-03-21 16:53:09 -04002251 return _VSTD::__libcpp_erase_if_container(__c, __pred);
Marek Kurdeja98b1412020-05-02 13:58:03 +02002252}
Marshall Clow29b53f22018-12-14 18:49:35 +00002253#endif
2254
Howard Hinnantc51e1022010-05-11 19:42:16 +00002255_LIBCPP_END_NAMESPACE_STD
2256
2257#endif // _LIBCPP_MAP