blob: d2b82591368baa1eca2aa027ac182923d43bad35 [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>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000483#include <iterator>
484#include <memory>
485#include <utility>
486#include <functional>
487#include <initializer_list>
Eric Fiselierf7394302015-06-13 07:08:02 +0000488#include <type_traits>
Marshall Clow0a1e7502018-09-12 19:41:40 +0000489#include <version>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000490
Howard Hinnantaaaa52b2011-10-17 20:05:10 +0000491#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000492#pragma GCC system_header
Howard Hinnantaaaa52b2011-10-17 20:05:10 +0000493#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000494
495_LIBCPP_BEGIN_NAMESPACE_STD
496
Louis Dionne878a3a82018-12-06 21:46:17 +0000497template <class _Key, class _CP, class _Compare,
498 bool = is_empty<_Compare>::value && !__libcpp_is_final<_Compare>::value>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000499class __map_value_compare
500 : private _Compare
501{
Howard Hinnantc51e1022010-05-11 19:42:16 +0000502public:
Howard Hinnant756c69b2010-09-22 16:48:34 +0000503 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000504 __map_value_compare()
505 _NOEXCEPT_(is_nothrow_default_constructible<_Compare>::value)
506 : _Compare() {}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000507 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000508 __map_value_compare(_Compare c)
509 _NOEXCEPT_(is_nothrow_copy_constructible<_Compare>::value)
510 : _Compare(c) {}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000511 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000512 const _Compare& key_comp() const _NOEXCEPT {return *this;}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000513 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000514 bool operator()(const _CP& __x, const _CP& __y) const
Erik Pilkingtond3fe2992018-06-04 20:38:23 +0000515 {return static_cast<const _Compare&>(*this)(__x.__get_value().first, __y.__get_value().first);}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000516 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000517 bool operator()(const _CP& __x, const _Key& __y) const
Erik Pilkingtond3fe2992018-06-04 20:38:23 +0000518 {return static_cast<const _Compare&>(*this)(__x.__get_value().first, __y);}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000519 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000520 bool operator()(const _Key& __x, const _CP& __y) const
Erik Pilkingtond3fe2992018-06-04 20:38:23 +0000521 {return static_cast<const _Compare&>(*this)(__x, __y.__get_value().first);}
Marshall Clow8982dcd2015-07-13 20:04:56 +0000522 void swap(__map_value_compare&__y)
523 _NOEXCEPT_(__is_nothrow_swappable<_Compare>::value)
524 {
Eric Fiselier68b5f0b2017-04-13 00:34:24 +0000525 using _VSTD::swap;
526 swap(static_cast<_Compare&>(*this), static_cast<_Compare&>(__y));
Marshall Clow8982dcd2015-07-13 20:04:56 +0000527 }
Marshall Clowebb57322013-08-13 22:18:47 +0000528
529#if _LIBCPP_STD_VER > 11
530 template <typename _K2>
531 _LIBCPP_INLINE_VISIBILITY
532 typename enable_if<__is_transparent<_Compare, _K2>::value, bool>::type
533 operator () ( const _K2& __x, const _CP& __y ) const
Erik Pilkingtond3fe2992018-06-04 20:38:23 +0000534 {return static_cast<const _Compare&>(*this) (__x, __y.__get_value().first);}
Marshall Clowebb57322013-08-13 22:18:47 +0000535
536 template <typename _K2>
537 _LIBCPP_INLINE_VISIBILITY
538 typename enable_if<__is_transparent<_Compare, _K2>::value, bool>::type
539 operator () (const _CP& __x, const _K2& __y) const
Erik Pilkingtond3fe2992018-06-04 20:38:23 +0000540 {return static_cast<const _Compare&>(*this) (__x.__get_value().first, __y);}
Marshall Clowebb57322013-08-13 22:18:47 +0000541#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000542};
543
Howard Hinnant90b91592013-07-05 18:06:00 +0000544template <class _Key, class _CP, class _Compare>
545class __map_value_compare<_Key, _CP, _Compare, false>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000546{
547 _Compare comp;
548
Howard Hinnantc51e1022010-05-11 19:42:16 +0000549public:
Howard Hinnant756c69b2010-09-22 16:48:34 +0000550 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000551 __map_value_compare()
552 _NOEXCEPT_(is_nothrow_default_constructible<_Compare>::value)
553 : comp() {}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000554 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000555 __map_value_compare(_Compare c)
556 _NOEXCEPT_(is_nothrow_copy_constructible<_Compare>::value)
557 : comp(c) {}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000558 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000559 const _Compare& key_comp() const _NOEXCEPT {return comp;}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000560
Howard Hinnant756c69b2010-09-22 16:48:34 +0000561 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000562 bool operator()(const _CP& __x, const _CP& __y) const
Erik Pilkingtond3fe2992018-06-04 20:38:23 +0000563 {return comp(__x.__get_value().first, __y.__get_value().first);}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000564 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000565 bool operator()(const _CP& __x, const _Key& __y) const
Erik Pilkingtond3fe2992018-06-04 20:38:23 +0000566 {return comp(__x.__get_value().first, __y);}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000567 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000568 bool operator()(const _Key& __x, const _CP& __y) const
Erik Pilkingtond3fe2992018-06-04 20:38:23 +0000569 {return comp(__x, __y.__get_value().first);}
Marshall Clow8982dcd2015-07-13 20:04:56 +0000570 void swap(__map_value_compare&__y)
571 _NOEXCEPT_(__is_nothrow_swappable<_Compare>::value)
572 {
573 using _VSTD::swap;
574 swap(comp, __y.comp);
575 }
Eric Fiseliercf8c0212017-01-05 06:06:18 +0000576
Marshall Clowebb57322013-08-13 22:18:47 +0000577#if _LIBCPP_STD_VER > 11
578 template <typename _K2>
579 _LIBCPP_INLINE_VISIBILITY
580 typename enable_if<__is_transparent<_Compare, _K2>::value, bool>::type
581 operator () ( const _K2& __x, const _CP& __y ) const
Erik Pilkingtond3fe2992018-06-04 20:38:23 +0000582 {return comp (__x, __y.__get_value().first);}
Marshall Clowebb57322013-08-13 22:18:47 +0000583
584 template <typename _K2>
585 _LIBCPP_INLINE_VISIBILITY
586 typename enable_if<__is_transparent<_Compare, _K2>::value, bool>::type
587 operator () (const _CP& __x, const _K2& __y) const
Erik Pilkingtond3fe2992018-06-04 20:38:23 +0000588 {return comp (__x.__get_value().first, __y);}
Marshall Clowebb57322013-08-13 22:18:47 +0000589#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000590};
591
Marshall Clow8982dcd2015-07-13 20:04:56 +0000592template <class _Key, class _CP, class _Compare, bool __b>
593inline _LIBCPP_INLINE_VISIBILITY
594void
595swap(__map_value_compare<_Key, _CP, _Compare, __b>& __x,
596 __map_value_compare<_Key, _CP, _Compare, __b>& __y)
597 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
598{
599 __x.swap(__y);
600}
601
Howard Hinnantc51e1022010-05-11 19:42:16 +0000602template <class _Allocator>
603class __map_node_destructor
604{
605 typedef _Allocator allocator_type;
606 typedef allocator_traits<allocator_type> __alloc_traits;
Eric Fiseliera00b4842016-02-20 05:28:30 +0000607
Howard Hinnantc51e1022010-05-11 19:42:16 +0000608public:
609 typedef typename __alloc_traits::pointer pointer;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000610
Eric Fiseliera00b4842016-02-20 05:28:30 +0000611private:
Howard Hinnantc51e1022010-05-11 19:42:16 +0000612 allocator_type& __na_;
613
614 __map_node_destructor& operator=(const __map_node_destructor&);
615
616public:
617 bool __first_constructed;
618 bool __second_constructed;
619
Howard Hinnant756c69b2010-09-22 16:48:34 +0000620 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000621 explicit __map_node_destructor(allocator_type& __na) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +0000622 : __na_(__na),
623 __first_constructed(false),
624 __second_constructed(false)
625 {}
626
Eric Fiseliera85b1282017-04-18 21:08:06 +0000627#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant756c69b2010-09-22 16:48:34 +0000628 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000629 __map_node_destructor(__tree_node_destructor<allocator_type>&& __x) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +0000630 : __na_(__x.__na_),
631 __first_constructed(__x.__value_constructed),
632 __second_constructed(__x.__value_constructed)
633 {
634 __x.__value_constructed = false;
635 }
Eric Fiseliera85b1282017-04-18 21:08:06 +0000636#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000637
Howard Hinnant756c69b2010-09-22 16:48:34 +0000638 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000639 void operator()(pointer __p) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +0000640 {
641 if (__second_constructed)
Erik Pilkingtond3fe2992018-06-04 20:38:23 +0000642 __alloc_traits::destroy(__na_, _VSTD::addressof(__p->__value_.__get_value().second));
Howard Hinnantc51e1022010-05-11 19:42:16 +0000643 if (__first_constructed)
Erik Pilkingtond3fe2992018-06-04 20:38:23 +0000644 __alloc_traits::destroy(__na_, _VSTD::addressof(__p->__value_.__get_value().first));
Howard Hinnantc51e1022010-05-11 19:42:16 +0000645 if (__p)
646 __alloc_traits::deallocate(__na_, __p, 1);
647 }
648};
649
Howard Hinnant944510a2011-06-14 19:58:17 +0000650template <class _Key, class _Tp, class _Compare, class _Allocator>
651 class map;
652template <class _Key, class _Tp, class _Compare, class _Allocator>
653 class multimap;
654template <class _TreeIterator> class __map_const_iterator;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000655
Eric Fiseliera00b4842016-02-20 05:28:30 +0000656#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant89f8b792013-09-30 19:08:22 +0000657
658template <class _Key, class _Tp>
Erik Pilkingtond3fe2992018-06-04 20:38:23 +0000659struct __value_type
Howard Hinnant89f8b792013-09-30 19:08:22 +0000660{
661 typedef _Key key_type;
662 typedef _Tp mapped_type;
663 typedef pair<const key_type, mapped_type> value_type;
Erik Pilkingtond3fe2992018-06-04 20:38:23 +0000664 typedef pair<key_type&, mapped_type&> __nc_ref_pair_type;
665 typedef pair<key_type&&, mapped_type&&> __nc_rref_pair_type;
Howard Hinnant89f8b792013-09-30 19:08:22 +0000666
Erik Pilkingtond3fe2992018-06-04 20:38:23 +0000667private:
Howard Hinnant89f8b792013-09-30 19:08:22 +0000668 value_type __cc;
Erik Pilkingtond3fe2992018-06-04 20:38:23 +0000669
670public:
671 _LIBCPP_INLINE_VISIBILITY
672 value_type& __get_value()
673 {
674#if _LIBCPP_STD_VER > 14
675 return *_VSTD::launder(_VSTD::addressof(__cc));
676#else
677 return __cc;
678#endif
679 }
680
681 _LIBCPP_INLINE_VISIBILITY
682 const value_type& __get_value() const
683 {
684#if _LIBCPP_STD_VER > 14
685 return *_VSTD::launder(_VSTD::addressof(__cc));
686#else
687 return __cc;
688#endif
689 }
690
691 _LIBCPP_INLINE_VISIBILITY
692 __nc_ref_pair_type __ref()
693 {
694 value_type& __v = __get_value();
695 return __nc_ref_pair_type(const_cast<key_type&>(__v.first), __v.second);
696 }
697
698 _LIBCPP_INLINE_VISIBILITY
699 __nc_rref_pair_type __move()
700 {
701 value_type& __v = __get_value();
702 return __nc_rref_pair_type(
703 _VSTD::move(const_cast<key_type&>(__v.first)),
704 _VSTD::move(__v.second));
705 }
Howard Hinnant89f8b792013-09-30 19:08:22 +0000706
Howard Hinnant89f8b792013-09-30 19:08:22 +0000707 _LIBCPP_INLINE_VISIBILITY
708 __value_type& operator=(const __value_type& __v)
Erik Pilkingtond3fe2992018-06-04 20:38:23 +0000709 {
710 __ref() = __v.__get_value();
711 return *this;
712 }
Howard Hinnant89f8b792013-09-30 19:08:22 +0000713
714 _LIBCPP_INLINE_VISIBILITY
715 __value_type& operator=(__value_type&& __v)
Erik Pilkingtond3fe2992018-06-04 20:38:23 +0000716 {
717 __ref() = __v.__move();
718 return *this;
719 }
Howard Hinnant89f8b792013-09-30 19:08:22 +0000720
Eric Fiselierd06276b2016-03-31 02:15:15 +0000721 template <class _ValueTp,
722 class = typename enable_if<
723 __is_same_uncvref<_ValueTp, value_type>::value
724 >::type
725 >
Howard Hinnant89f8b792013-09-30 19:08:22 +0000726 _LIBCPP_INLINE_VISIBILITY
Erik Pilkingtond3fe2992018-06-04 20:38:23 +0000727 __value_type& operator=(_ValueTp&& __v)
728 {
729 __ref() = _VSTD::forward<_ValueTp>(__v);
730 return *this;
Eric Fiselierd06276b2016-03-31 02:15:15 +0000731 }
732
733private:
734 __value_type() _LIBCPP_EQUAL_DELETE;
735 ~__value_type() _LIBCPP_EQUAL_DELETE;
736 __value_type(const __value_type& __v) _LIBCPP_EQUAL_DELETE;
737 __value_type(__value_type&& __v) _LIBCPP_EQUAL_DELETE;
Howard Hinnant89f8b792013-09-30 19:08:22 +0000738};
739
740#else
741
742template <class _Key, class _Tp>
743struct __value_type
744{
745 typedef _Key key_type;
746 typedef _Tp mapped_type;
747 typedef pair<const key_type, mapped_type> value_type;
748
Erik Pilkingtond3fe2992018-06-04 20:38:23 +0000749private:
Howard Hinnant89f8b792013-09-30 19:08:22 +0000750 value_type __cc;
751
Erik Pilkingtond3fe2992018-06-04 20:38:23 +0000752public:
753 _LIBCPP_INLINE_VISIBILITY
754 value_type& __get_value() { return __cc; }
755 _LIBCPP_INLINE_VISIBILITY
756 const value_type& __get_value() const { return __cc; }
757
Eric Fiselierd06276b2016-03-31 02:15:15 +0000758private:
759 __value_type();
760 __value_type(__value_type const&);
761 __value_type& operator=(__value_type const&);
762 ~__value_type();
Howard Hinnant89f8b792013-09-30 19:08:22 +0000763};
764
Eric Fiseliera85b1282017-04-18 21:08:06 +0000765#endif // _LIBCPP_CXX03_LANG
Howard Hinnant89f8b792013-09-30 19:08:22 +0000766
Eric Fiselier44f9fd02015-03-03 20:10:01 +0000767template <class _Tp>
768struct __extract_key_value_types;
769
770template <class _Key, class _Tp>
771struct __extract_key_value_types<__value_type<_Key, _Tp> >
772{
773 typedef _Key const __key_type;
774 typedef _Tp __mapped_type;
775};
776
Howard Hinnantc51e1022010-05-11 19:42:16 +0000777template <class _TreeIterator>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000778class _LIBCPP_TEMPLATE_VIS __map_iterator
Howard Hinnantc51e1022010-05-11 19:42:16 +0000779{
Eric Fiseliera00b4842016-02-20 05:28:30 +0000780 typedef typename _TreeIterator::_NodeTypes _NodeTypes;
781 typedef typename _TreeIterator::__pointer_traits __pointer_traits;
782
Howard Hinnantc51e1022010-05-11 19:42:16 +0000783 _TreeIterator __i_;
784
Howard Hinnantc51e1022010-05-11 19:42:16 +0000785public:
786 typedef bidirectional_iterator_tag iterator_category;
Eric Fiseliera00b4842016-02-20 05:28:30 +0000787 typedef typename _NodeTypes::__map_value_type value_type;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000788 typedef typename _TreeIterator::difference_type difference_type;
789 typedef value_type& reference;
Eric Fiseliera00b4842016-02-20 05:28:30 +0000790 typedef typename _NodeTypes::__map_value_type_pointer pointer;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000791
Howard Hinnant756c69b2010-09-22 16:48:34 +0000792 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000793 __map_iterator() _NOEXCEPT {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000794
Howard Hinnant756c69b2010-09-22 16:48:34 +0000795 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000796 __map_iterator(_TreeIterator __i) _NOEXCEPT : __i_(__i) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000797
Howard Hinnant756c69b2010-09-22 16:48:34 +0000798 _LIBCPP_INLINE_VISIBILITY
Erik Pilkingtond3fe2992018-06-04 20:38:23 +0000799 reference operator*() const {return __i_->__get_value();}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000800 _LIBCPP_INLINE_VISIBILITY
Erik Pilkingtond3fe2992018-06-04 20:38:23 +0000801 pointer operator->() const {return pointer_traits<pointer>::pointer_to(__i_->__get_value());}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000802
Howard Hinnant756c69b2010-09-22 16:48:34 +0000803 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000804 __map_iterator& operator++() {++__i_; return *this;}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000805 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000806 __map_iterator operator++(int)
807 {
808 __map_iterator __t(*this);
809 ++(*this);
810 return __t;
811 }
812
Howard Hinnant756c69b2010-09-22 16:48:34 +0000813 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000814 __map_iterator& operator--() {--__i_; return *this;}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000815 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000816 __map_iterator operator--(int)
817 {
818 __map_iterator __t(*this);
819 --(*this);
820 return __t;
821 }
822
Howard Hinnant756c69b2010-09-22 16:48:34 +0000823 friend _LIBCPP_INLINE_VISIBILITY
824 bool operator==(const __map_iterator& __x, const __map_iterator& __y)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000825 {return __x.__i_ == __y.__i_;}
Eric Fiseliercf8c0212017-01-05 06:06:18 +0000826 friend
Howard Hinnant756c69b2010-09-22 16:48:34 +0000827 _LIBCPP_INLINE_VISIBILITY
828 bool operator!=(const __map_iterator& __x, const __map_iterator& __y)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000829 {return __x.__i_ != __y.__i_;}
830
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000831 template <class, class, class, class> friend class _LIBCPP_TEMPLATE_VIS map;
832 template <class, class, class, class> friend class _LIBCPP_TEMPLATE_VIS multimap;
833 template <class> friend class _LIBCPP_TEMPLATE_VIS __map_const_iterator;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000834};
835
836template <class _TreeIterator>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000837class _LIBCPP_TEMPLATE_VIS __map_const_iterator
Howard Hinnantc51e1022010-05-11 19:42:16 +0000838{
Eric Fiseliera00b4842016-02-20 05:28:30 +0000839 typedef typename _TreeIterator::_NodeTypes _NodeTypes;
840 typedef typename _TreeIterator::__pointer_traits __pointer_traits;
841
Howard Hinnantc51e1022010-05-11 19:42:16 +0000842 _TreeIterator __i_;
843
Howard Hinnantc51e1022010-05-11 19:42:16 +0000844public:
845 typedef bidirectional_iterator_tag iterator_category;
Eric Fiseliera00b4842016-02-20 05:28:30 +0000846 typedef typename _NodeTypes::__map_value_type value_type;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000847 typedef typename _TreeIterator::difference_type difference_type;
848 typedef const value_type& reference;
Eric Fiseliera00b4842016-02-20 05:28:30 +0000849 typedef typename _NodeTypes::__const_map_value_type_pointer pointer;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000850
Howard Hinnant756c69b2010-09-22 16:48:34 +0000851 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000852 __map_const_iterator() _NOEXCEPT {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000853
Howard Hinnant756c69b2010-09-22 16:48:34 +0000854 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000855 __map_const_iterator(_TreeIterator __i) _NOEXCEPT : __i_(__i) {}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000856 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier44f9fd02015-03-03 20:10:01 +0000857 __map_const_iterator(__map_iterator<
858 typename _TreeIterator::__non_const_iterator> __i) _NOEXCEPT
859 : __i_(__i.__i_) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000860
Howard Hinnant756c69b2010-09-22 16:48:34 +0000861 _LIBCPP_INLINE_VISIBILITY
Erik Pilkingtond3fe2992018-06-04 20:38:23 +0000862 reference operator*() const {return __i_->__get_value();}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000863 _LIBCPP_INLINE_VISIBILITY
Erik Pilkingtond3fe2992018-06-04 20:38:23 +0000864 pointer operator->() const {return pointer_traits<pointer>::pointer_to(__i_->__get_value());}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000865
Howard Hinnant756c69b2010-09-22 16:48:34 +0000866 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000867 __map_const_iterator& operator++() {++__i_; return *this;}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000868 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000869 __map_const_iterator operator++(int)
870 {
871 __map_const_iterator __t(*this);
872 ++(*this);
873 return __t;
874 }
875
Howard Hinnant756c69b2010-09-22 16:48:34 +0000876 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000877 __map_const_iterator& operator--() {--__i_; return *this;}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000878 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000879 __map_const_iterator operator--(int)
880 {
881 __map_const_iterator __t(*this);
882 --(*this);
883 return __t;
884 }
885
Howard Hinnant756c69b2010-09-22 16:48:34 +0000886 friend _LIBCPP_INLINE_VISIBILITY
887 bool operator==(const __map_const_iterator& __x, const __map_const_iterator& __y)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000888 {return __x.__i_ == __y.__i_;}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000889 friend _LIBCPP_INLINE_VISIBILITY
890 bool operator!=(const __map_const_iterator& __x, const __map_const_iterator& __y)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000891 {return __x.__i_ != __y.__i_;}
892
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000893 template <class, class, class, class> friend class _LIBCPP_TEMPLATE_VIS map;
894 template <class, class, class, class> friend class _LIBCPP_TEMPLATE_VIS multimap;
895 template <class, class, class> friend class _LIBCPP_TEMPLATE_VIS __tree_const_iterator;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000896};
897
898template <class _Key, class _Tp, class _Compare = less<_Key>,
899 class _Allocator = allocator<pair<const _Key, _Tp> > >
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000900class _LIBCPP_TEMPLATE_VIS map
Howard Hinnantc51e1022010-05-11 19:42:16 +0000901{
902public:
903 // types:
904 typedef _Key key_type;
905 typedef _Tp mapped_type;
906 typedef pair<const key_type, mapped_type> value_type;
Louis Dionned23a5f22019-06-20 19:32:00 +0000907 typedef typename __identity<_Compare>::type key_compare;
908 typedef typename __identity<_Allocator>::type allocator_type;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000909 typedef value_type& reference;
910 typedef const value_type& const_reference;
911
Marshall Clow5128cf32015-11-26 01:24:04 +0000912 static_assert((is_same<typename allocator_type::value_type, value_type>::value),
913 "Allocator::value_type must be same type as value_type");
914
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000915 class _LIBCPP_TEMPLATE_VIS value_compare
Howard Hinnantc51e1022010-05-11 19:42:16 +0000916 : public binary_function<value_type, value_type, bool>
917 {
918 friend class map;
919 protected:
920 key_compare comp;
921
Howard Hinnant756c69b2010-09-22 16:48:34 +0000922 _LIBCPP_INLINE_VISIBILITY value_compare(key_compare c) : comp(c) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000923 public:
Howard Hinnant756c69b2010-09-22 16:48:34 +0000924 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000925 bool operator()(const value_type& __x, const value_type& __y) const
926 {return comp(__x.first, __y.first);}
927 };
928
929private:
Howard Hinnant2d0046b2013-06-19 21:29:40 +0000930
Howard Hinnant89f8b792013-09-30 19:08:22 +0000931 typedef _VSTD::__value_type<key_type, mapped_type> __value_type;
Howard Hinnant90b91592013-07-05 18:06:00 +0000932 typedef __map_value_compare<key_type, __value_type, key_compare> __vc;
Marshall Clow940e01c2015-04-07 05:21:38 +0000933 typedef typename __rebind_alloc_helper<allocator_traits<allocator_type>,
934 __value_type>::type __allocator_type;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000935 typedef __tree<__value_type, __vc, __allocator_type> __base;
936 typedef typename __base::__node_traits __node_traits;
937 typedef allocator_traits<allocator_type> __alloc_traits;
938
939 __base __tree_;
940
941public:
942 typedef typename __alloc_traits::pointer pointer;
943 typedef typename __alloc_traits::const_pointer const_pointer;
944 typedef typename __alloc_traits::size_type size_type;
945 typedef typename __alloc_traits::difference_type difference_type;
Eric Fiselier44f9fd02015-03-03 20:10:01 +0000946 typedef __map_iterator<typename __base::iterator> iterator;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000947 typedef __map_const_iterator<typename __base::const_iterator> const_iterator;
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000948 typedef _VSTD::reverse_iterator<iterator> reverse_iterator;
949 typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000950
Erik Pilkingtonc37a3d82018-08-01 01:33:38 +0000951#if _LIBCPP_STD_VER > 14
952 typedef __map_node_handle<typename __base::__node, allocator_type> node_type;
953 typedef __insert_return_type<iterator, node_type> insert_return_type;
954#endif
955
Erik Pilkington82a65ad2018-10-31 17:31:35 +0000956 template <class _Key2, class _Value2, class _Comp2, class _Alloc2>
957 friend class _LIBCPP_TEMPLATE_VIS map;
958 template <class _Key2, class _Value2, class _Comp2, class _Alloc2>
959 friend class _LIBCPP_TEMPLATE_VIS multimap;
960
Howard Hinnant756c69b2010-09-22 16:48:34 +0000961 _LIBCPP_INLINE_VISIBILITY
Marshall Clow7086a5a2014-03-10 04:50:10 +0000962 map()
963 _NOEXCEPT_(
964 is_nothrow_default_constructible<allocator_type>::value &&
965 is_nothrow_default_constructible<key_compare>::value &&
966 is_nothrow_copy_constructible<key_compare>::value)
967 : __tree_(__vc(key_compare())) {}
968
969 _LIBCPP_INLINE_VISIBILITY
970 explicit map(const key_compare& __comp)
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000971 _NOEXCEPT_(
972 is_nothrow_default_constructible<allocator_type>::value &&
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000973 is_nothrow_copy_constructible<key_compare>::value)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000974 : __tree_(__vc(__comp)) {}
975
Howard Hinnant756c69b2010-09-22 16:48:34 +0000976 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000977 explicit map(const key_compare& __comp, const allocator_type& __a)
Marshall Clow657cbc42016-08-17 05:58:40 +0000978 : __tree_(__vc(__comp), typename __base::allocator_type(__a)) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000979
980 template <class _InputIterator>
Howard Hinnant756c69b2010-09-22 16:48:34 +0000981 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000982 map(_InputIterator __f, _InputIterator __l,
983 const key_compare& __comp = key_compare())
984 : __tree_(__vc(__comp))
985 {
986 insert(__f, __l);
987 }
988
989 template <class _InputIterator>
Howard Hinnant756c69b2010-09-22 16:48:34 +0000990 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000991 map(_InputIterator __f, _InputIterator __l,
992 const key_compare& __comp, const allocator_type& __a)
Marshall Clow657cbc42016-08-17 05:58:40 +0000993 : __tree_(__vc(__comp), typename __base::allocator_type(__a))
Howard Hinnantc51e1022010-05-11 19:42:16 +0000994 {
995 insert(__f, __l);
996 }
997
Marshall Clow300abfb2013-09-11 01:15:47 +0000998#if _LIBCPP_STD_VER > 11
999 template <class _InputIterator>
Eric Fiseliercf8c0212017-01-05 06:06:18 +00001000 _LIBCPP_INLINE_VISIBILITY
Marshall Clow300abfb2013-09-11 01:15:47 +00001001 map(_InputIterator __f, _InputIterator __l, const allocator_type& __a)
1002 : map(__f, __l, key_compare(), __a) {}
1003#endif
1004
Howard Hinnant756c69b2010-09-22 16:48:34 +00001005 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001006 map(const map& __m)
1007 : __tree_(__m.__tree_)
1008 {
1009 insert(__m.begin(), __m.end());
1010 }
1011
Howard Hinnantd3a657f2011-07-01 19:24:36 +00001012 _LIBCPP_INLINE_VISIBILITY
1013 map& operator=(const map& __m)
1014 {
Marshall Clow476d3f42016-07-18 13:19:00 +00001015#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantd3a657f2011-07-01 19:24:36 +00001016 __tree_ = __m.__tree_;
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001017#else
Marshall Clowdb3cfcb2014-02-08 04:03:14 +00001018 if (this != &__m) {
1019 __tree_.clear();
1020 __tree_.value_comp() = __m.__tree_.value_comp();
1021 __tree_.__copy_assign_alloc(__m.__tree_);
1022 insert(__m.begin(), __m.end());
1023 }
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001024#endif
Howard Hinnantd3a657f2011-07-01 19:24:36 +00001025 return *this;
1026 }
1027
Eric Fiseliera85b1282017-04-18 21:08:06 +00001028#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001029
Howard Hinnant756c69b2010-09-22 16:48:34 +00001030 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001031 map(map&& __m)
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001032 _NOEXCEPT_(is_nothrow_move_constructible<__base>::value)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001033 : __tree_(_VSTD::move(__m.__tree_))
Howard Hinnantc51e1022010-05-11 19:42:16 +00001034 {
1035 }
1036
1037 map(map&& __m, const allocator_type& __a);
1038
Howard Hinnant756c69b2010-09-22 16:48:34 +00001039 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant33711792011-08-12 21:56:02 +00001040 map& operator=(map&& __m)
1041 _NOEXCEPT_(is_nothrow_move_assignable<__base>::value)
1042 {
1043 __tree_ = _VSTD::move(__m.__tree_);
1044 return *this;
1045 }
1046
Howard Hinnant33711792011-08-12 21:56:02 +00001047 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001048 map(initializer_list<value_type> __il, const key_compare& __comp = key_compare())
1049 : __tree_(__vc(__comp))
1050 {
1051 insert(__il.begin(), __il.end());
1052 }
1053
Howard Hinnant756c69b2010-09-22 16:48:34 +00001054 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001055 map(initializer_list<value_type> __il, const key_compare& __comp, const allocator_type& __a)
Marshall Clow657cbc42016-08-17 05:58:40 +00001056 : __tree_(__vc(__comp), typename __base::allocator_type(__a))
Howard Hinnantc51e1022010-05-11 19:42:16 +00001057 {
1058 insert(__il.begin(), __il.end());
1059 }
1060
Marshall Clow300abfb2013-09-11 01:15:47 +00001061#if _LIBCPP_STD_VER > 11
Eric Fiseliercf8c0212017-01-05 06:06:18 +00001062 _LIBCPP_INLINE_VISIBILITY
Marshall Clow300abfb2013-09-11 01:15:47 +00001063 map(initializer_list<value_type> __il, const allocator_type& __a)
1064 : map(__il, key_compare(), __a) {}
1065#endif
1066
Howard Hinnant756c69b2010-09-22 16:48:34 +00001067 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001068 map& operator=(initializer_list<value_type> __il)
1069 {
1070 __tree_.__assign_unique(__il.begin(), __il.end());
1071 return *this;
1072 }
1073
Eric Fiseliera85b1282017-04-18 21:08:06 +00001074#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001075
Howard Hinnant756c69b2010-09-22 16:48:34 +00001076 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001077 explicit map(const allocator_type& __a)
Marshall Clow657cbc42016-08-17 05:58:40 +00001078 : __tree_(typename __base::allocator_type(__a))
Howard Hinnantc51e1022010-05-11 19:42:16 +00001079 {
1080 }
1081
Howard Hinnant756c69b2010-09-22 16:48:34 +00001082 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001083 map(const map& __m, const allocator_type& __a)
Marshall Clow657cbc42016-08-17 05:58:40 +00001084 : __tree_(__m.__tree_.value_comp(), typename __base::allocator_type(__a))
Howard Hinnantc51e1022010-05-11 19:42:16 +00001085 {
1086 insert(__m.begin(), __m.end());
1087 }
1088
Howard Hinnant756c69b2010-09-22 16:48:34 +00001089 _LIBCPP_INLINE_VISIBILITY
Louis Dionne69c42c02019-04-11 16:14:56 +00001090 ~map() {
1091 static_assert(sizeof(__diagnose_non_const_comparator<_Key, _Compare>()), "");
1092 }
1093
1094 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001095 iterator begin() _NOEXCEPT {return __tree_.begin();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001096 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001097 const_iterator begin() const _NOEXCEPT {return __tree_.begin();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001098 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001099 iterator end() _NOEXCEPT {return __tree_.end();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001100 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001101 const_iterator end() const _NOEXCEPT {return __tree_.end();}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001102
Howard Hinnant756c69b2010-09-22 16:48:34 +00001103 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001104 reverse_iterator rbegin() _NOEXCEPT {return reverse_iterator(end());}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001105 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001106 const_reverse_iterator rbegin() const _NOEXCEPT
1107 {return const_reverse_iterator(end());}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001108 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001109 reverse_iterator rend() _NOEXCEPT
1110 {return reverse_iterator(begin());}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001111 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001112 const_reverse_iterator rend() const _NOEXCEPT
1113 {return const_reverse_iterator(begin());}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001114
Howard Hinnant756c69b2010-09-22 16:48:34 +00001115 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001116 const_iterator cbegin() const _NOEXCEPT {return begin();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001117 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001118 const_iterator cend() const _NOEXCEPT {return end();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001119 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001120 const_reverse_iterator crbegin() const _NOEXCEPT {return rbegin();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001121 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001122 const_reverse_iterator crend() const _NOEXCEPT {return rend();}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001123
Marshall Clow425f5752017-11-15 05:51:26 +00001124 _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001125 bool empty() const _NOEXCEPT {return __tree_.size() == 0;}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001126 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001127 size_type size() const _NOEXCEPT {return __tree_.size();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001128 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001129 size_type max_size() const _NOEXCEPT {return __tree_.max_size();}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001130
1131 mapped_type& operator[](const key_type& __k);
Eric Fiselierd63f38e2016-03-31 03:13:37 +00001132#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001133 mapped_type& operator[](key_type&& __k);
1134#endif
1135
1136 mapped_type& at(const key_type& __k);
1137 const mapped_type& at(const key_type& __k) const;
1138
Howard Hinnant756c69b2010-09-22 16:48:34 +00001139 _LIBCPP_INLINE_VISIBILITY
Marshall Clow657cbc42016-08-17 05:58:40 +00001140 allocator_type get_allocator() const _NOEXCEPT {return allocator_type(__tree_.__alloc());}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001141 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001142 key_compare key_comp() const {return __tree_.value_comp().key_comp();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001143 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001144 value_compare value_comp() const {return value_compare(__tree_.value_comp().key_comp());}
1145
Eric Fiselierd06276b2016-03-31 02:15:15 +00001146#ifndef _LIBCPP_CXX03_LANG
1147 template <class ..._Args>
1148 _LIBCPP_INLINE_VISIBILITY
1149 pair<iterator, bool> emplace(_Args&& ...__args) {
1150 return __tree_.__emplace_unique(_VSTD::forward<_Args>(__args)...);
1151 }
Howard Hinnant74279a52010-09-04 23:28:19 +00001152
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001153 template <class ..._Args>
Eric Fiselierd06276b2016-03-31 02:15:15 +00001154 _LIBCPP_INLINE_VISIBILITY
1155 iterator emplace_hint(const_iterator __p, _Args&& ...__args) {
1156 return __tree_.__emplace_hint_unique(__p.__i_, _VSTD::forward<_Args>(__args)...);
1157 }
Howard Hinnant74279a52010-09-04 23:28:19 +00001158
Howard Hinnantc834c512011-11-29 18:15:50 +00001159 template <class _Pp,
1160 class = typename enable_if<is_constructible<value_type, _Pp>::value>::type>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001161 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc834c512011-11-29 18:15:50 +00001162 pair<iterator, bool> insert(_Pp&& __p)
1163 {return __tree_.__insert_unique(_VSTD::forward<_Pp>(__p));}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001164
Howard Hinnantc834c512011-11-29 18:15:50 +00001165 template <class _Pp,
1166 class = typename enable_if<is_constructible<value_type, _Pp>::value>::type>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001167 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc834c512011-11-29 18:15:50 +00001168 iterator insert(const_iterator __pos, _Pp&& __p)
1169 {return __tree_.__insert_unique(__pos.__i_, _VSTD::forward<_Pp>(__p));}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001170
Eric Fiselierd06276b2016-03-31 02:15:15 +00001171#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001172
Howard Hinnant756c69b2010-09-22 16:48:34 +00001173 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001174 pair<iterator, bool>
1175 insert(const value_type& __v) {return __tree_.__insert_unique(__v);}
1176
Howard Hinnant756c69b2010-09-22 16:48:34 +00001177 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001178 iterator
1179 insert(const_iterator __p, const value_type& __v)
1180 {return __tree_.__insert_unique(__p.__i_, __v);}
1181
Eric Fiselierd6143132016-04-18 01:40:45 +00001182#ifndef _LIBCPP_CXX03_LANG
Marshall Clowd430d022016-01-05 19:32:41 +00001183 _LIBCPP_INLINE_VISIBILITY
1184 pair<iterator, bool>
Eric Fiselierd06276b2016-03-31 02:15:15 +00001185 insert(value_type&& __v) {return __tree_.__insert_unique(_VSTD::move(__v));}
Marshall Clowd430d022016-01-05 19:32:41 +00001186
1187 _LIBCPP_INLINE_VISIBILITY
Eric Fiselierd06276b2016-03-31 02:15:15 +00001188 iterator insert(const_iterator __p, value_type&& __v)
1189 {return __tree_.__insert_unique(__p.__i_, _VSTD::move(__v));}
Eric Fiseliera85b1282017-04-18 21:08:06 +00001190
1191 _LIBCPP_INLINE_VISIBILITY
1192 void insert(initializer_list<value_type> __il)
1193 {insert(__il.begin(), __il.end());}
Marshall Clowd430d022016-01-05 19:32:41 +00001194#endif
1195
Howard Hinnantc51e1022010-05-11 19:42:16 +00001196 template <class _InputIterator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001197 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001198 void insert(_InputIterator __f, _InputIterator __l)
1199 {
1200 for (const_iterator __e = cend(); __f != __l; ++__f)
1201 insert(__e.__i_, *__f);
1202 }
1203
Marshall Clow3223db82015-07-07 03:37:33 +00001204#if _LIBCPP_STD_VER > 14
Eric Fiselierd63f38e2016-03-31 03:13:37 +00001205
Marshall Clow3223db82015-07-07 03:37:33 +00001206 template <class... _Args>
1207 _LIBCPP_INLINE_VISIBILITY
1208 pair<iterator, bool> try_emplace(const key_type& __k, _Args&&... __args)
1209 {
Eric Fiselierd63f38e2016-03-31 03:13:37 +00001210 return __tree_.__emplace_unique_key_args(__k,
1211 _VSTD::piecewise_construct,
1212 _VSTD::forward_as_tuple(__k),
1213 _VSTD::forward_as_tuple(_VSTD::forward<_Args>(__args)...));
Marshall Clow3223db82015-07-07 03:37:33 +00001214 }
1215
1216 template <class... _Args>
1217 _LIBCPP_INLINE_VISIBILITY
1218 pair<iterator, bool> try_emplace(key_type&& __k, _Args&&... __args)
1219 {
Eric Fiselierd63f38e2016-03-31 03:13:37 +00001220 return __tree_.__emplace_unique_key_args(__k,
1221 _VSTD::piecewise_construct,
1222 _VSTD::forward_as_tuple(_VSTD::move(__k)),
1223 _VSTD::forward_as_tuple(_VSTD::forward<_Args>(__args)...));
Marshall Clow3223db82015-07-07 03:37:33 +00001224 }
1225
1226 template <class... _Args>
1227 _LIBCPP_INLINE_VISIBILITY
1228 iterator try_emplace(const_iterator __h, const key_type& __k, _Args&&... __args)
1229 {
Eric Fiselierd63f38e2016-03-31 03:13:37 +00001230 return __tree_.__emplace_hint_unique_key_args(__h.__i_, __k,
1231 _VSTD::piecewise_construct,
1232 _VSTD::forward_as_tuple(__k),
1233 _VSTD::forward_as_tuple(_VSTD::forward<_Args>(__args)...));
Marshall Clow3223db82015-07-07 03:37:33 +00001234 }
1235
1236 template <class... _Args>
1237 _LIBCPP_INLINE_VISIBILITY
1238 iterator try_emplace(const_iterator __h, key_type&& __k, _Args&&... __args)
1239 {
Eric Fiselierd63f38e2016-03-31 03:13:37 +00001240 return __tree_.__emplace_hint_unique_key_args(__h.__i_, __k,
1241 _VSTD::piecewise_construct,
1242 _VSTD::forward_as_tuple(_VSTD::move(__k)),
1243 _VSTD::forward_as_tuple(_VSTD::forward<_Args>(__args)...));
Marshall Clow3223db82015-07-07 03:37:33 +00001244 }
1245
1246 template <class _Vp>
1247 _LIBCPP_INLINE_VISIBILITY
1248 pair<iterator, bool> insert_or_assign(const key_type& __k, _Vp&& __v)
1249 {
1250 iterator __p = lower_bound(__k);
1251 if ( __p != end() && !key_comp()(__k, __p->first))
1252 {
1253 __p->second = _VSTD::forward<_Vp>(__v);
1254 return _VSTD::make_pair(__p, false);
1255 }
1256 return _VSTD::make_pair(emplace_hint(__p, __k, _VSTD::forward<_Vp>(__v)), true);
1257 }
Eric Fiselierd63f38e2016-03-31 03:13:37 +00001258
Marshall Clow3223db82015-07-07 03:37:33 +00001259 template <class _Vp>
1260 _LIBCPP_INLINE_VISIBILITY
1261 pair<iterator, bool> insert_or_assign(key_type&& __k, _Vp&& __v)
1262 {
1263 iterator __p = lower_bound(__k);
1264 if ( __p != end() && !key_comp()(__k, __p->first))
1265 {
1266 __p->second = _VSTD::forward<_Vp>(__v);
1267 return _VSTD::make_pair(__p, false);
1268 }
1269 return _VSTD::make_pair(emplace_hint(__p, _VSTD::move(__k), _VSTD::forward<_Vp>(__v)), true);
1270 }
1271
1272 template <class _Vp>
1273 _LIBCPP_INLINE_VISIBILITY
1274 iterator insert_or_assign(const_iterator __h, const key_type& __k, _Vp&& __v)
1275 {
1276 iterator __p = lower_bound(__k);
1277 if ( __p != end() && !key_comp()(__k, __p->first))
1278 {
1279 __p->second = _VSTD::forward<_Vp>(__v);
1280 return __p;
1281 }
1282 return emplace_hint(__h, __k, _VSTD::forward<_Vp>(__v));
1283 }
1284
1285 template <class _Vp>
1286 _LIBCPP_INLINE_VISIBILITY
1287 iterator insert_or_assign(const_iterator __h, key_type&& __k, _Vp&& __v)
1288 {
1289 iterator __p = lower_bound(__k);
1290 if ( __p != end() && !key_comp()(__k, __p->first))
1291 {
1292 __p->second = _VSTD::forward<_Vp>(__v);
1293 return __p;
1294 }
1295 return emplace_hint(__h, _VSTD::move(__k), _VSTD::forward<_Vp>(__v));
1296 }
Eric Fiselierd63f38e2016-03-31 03:13:37 +00001297
Eric Fiseliera85b1282017-04-18 21:08:06 +00001298#endif // _LIBCPP_STD_VER > 14
Marshall Clow3223db82015-07-07 03:37:33 +00001299
Howard Hinnant756c69b2010-09-22 16:48:34 +00001300 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001301 iterator erase(const_iterator __p) {return __tree_.erase(__p.__i_);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001302 _LIBCPP_INLINE_VISIBILITY
Marshall Clow22ea5b82015-05-10 13:35:00 +00001303 iterator erase(iterator __p) {return __tree_.erase(__p.__i_);}
1304 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001305 size_type erase(const key_type& __k)
1306 {return __tree_.__erase_unique(__k);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001307 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001308 iterator erase(const_iterator __f, const_iterator __l)
1309 {return __tree_.erase(__f.__i_, __l.__i_);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001310 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001311 void clear() _NOEXCEPT {__tree_.clear();}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001312
Erik Pilkingtonc37a3d82018-08-01 01:33:38 +00001313#if _LIBCPP_STD_VER > 14
1314 _LIBCPP_INLINE_VISIBILITY
1315 insert_return_type insert(node_type&& __nh)
1316 {
1317 _LIBCPP_ASSERT(__nh.empty() || __nh.get_allocator() == get_allocator(),
1318 "node_type with incompatible allocator passed to map::insert()");
1319 return __tree_.template __node_handle_insert_unique<
1320 node_type, insert_return_type>(_VSTD::move(__nh));
1321 }
1322 _LIBCPP_INLINE_VISIBILITY
1323 iterator insert(const_iterator __hint, node_type&& __nh)
1324 {
1325 _LIBCPP_ASSERT(__nh.empty() || __nh.get_allocator() == get_allocator(),
1326 "node_type with incompatible allocator passed to map::insert()");
1327 return __tree_.template __node_handle_insert_unique<node_type>(
1328 __hint.__i_, _VSTD::move(__nh));
1329 }
1330 _LIBCPP_INLINE_VISIBILITY
1331 node_type extract(key_type const& __key)
1332 {
1333 return __tree_.template __node_handle_extract<node_type>(__key);
1334 }
1335 _LIBCPP_INLINE_VISIBILITY
1336 node_type extract(const_iterator __it)
1337 {
1338 return __tree_.template __node_handle_extract<node_type>(__it.__i_);
1339 }
Louis Dionned2322c82018-11-01 14:41:37 +00001340 template <class _Compare2>
Erik Pilkington82a65ad2018-10-31 17:31:35 +00001341 _LIBCPP_INLINE_VISIBILITY
Louis Dionned2322c82018-11-01 14:41:37 +00001342 void merge(map<key_type, mapped_type, _Compare2, allocator_type>& __source)
Erik Pilkington82a65ad2018-10-31 17:31:35 +00001343 {
1344 _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
1345 "merging container with incompatible allocator");
1346 __tree_.__node_handle_merge_unique(__source.__tree_);
1347 }
Louis Dionned2322c82018-11-01 14:41:37 +00001348 template <class _Compare2>
Erik Pilkington82a65ad2018-10-31 17:31:35 +00001349 _LIBCPP_INLINE_VISIBILITY
Louis Dionned2322c82018-11-01 14:41:37 +00001350 void merge(map<key_type, mapped_type, _Compare2, allocator_type>&& __source)
Erik Pilkington82a65ad2018-10-31 17:31:35 +00001351 {
1352 _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
1353 "merging container with incompatible allocator");
1354 __tree_.__node_handle_merge_unique(__source.__tree_);
1355 }
Louis Dionned2322c82018-11-01 14:41:37 +00001356 template <class _Compare2>
Erik Pilkington82a65ad2018-10-31 17:31:35 +00001357 _LIBCPP_INLINE_VISIBILITY
Louis Dionned2322c82018-11-01 14:41:37 +00001358 void merge(multimap<key_type, mapped_type, _Compare2, allocator_type>& __source)
Erik Pilkington82a65ad2018-10-31 17:31:35 +00001359 {
1360 _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
1361 "merging container with incompatible allocator");
1362 __tree_.__node_handle_merge_unique(__source.__tree_);
1363 }
Louis Dionned2322c82018-11-01 14:41:37 +00001364 template <class _Compare2>
Erik Pilkington82a65ad2018-10-31 17:31:35 +00001365 _LIBCPP_INLINE_VISIBILITY
Louis Dionned2322c82018-11-01 14:41:37 +00001366 void merge(multimap<key_type, mapped_type, _Compare2, allocator_type>&& __source)
Erik Pilkington82a65ad2018-10-31 17:31:35 +00001367 {
1368 _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
1369 "merging container with incompatible allocator");
1370 __tree_.__node_handle_merge_unique(__source.__tree_);
1371 }
Erik Pilkingtonc37a3d82018-08-01 01:33:38 +00001372#endif
1373
Howard Hinnant756c69b2010-09-22 16:48:34 +00001374 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001375 void swap(map& __m)
1376 _NOEXCEPT_(__is_nothrow_swappable<__base>::value)
1377 {__tree_.swap(__m.__tree_);}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001378
Howard Hinnant756c69b2010-09-22 16:48:34 +00001379 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001380 iterator find(const key_type& __k) {return __tree_.find(__k);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001381 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001382 const_iterator find(const key_type& __k) const {return __tree_.find(__k);}
Marshall Clowebb57322013-08-13 22:18:47 +00001383#if _LIBCPP_STD_VER > 11
1384 template <typename _K2>
1385 _LIBCPP_INLINE_VISIBILITY
1386 typename enable_if<__is_transparent<_Compare, _K2>::value,iterator>::type
1387 find(const _K2& __k) {return __tree_.find(__k);}
1388 template <typename _K2>
1389 _LIBCPP_INLINE_VISIBILITY
1390 typename enable_if<__is_transparent<_Compare, _K2>::value,const_iterator>::type
1391 find(const _K2& __k) const {return __tree_.find(__k);}
1392#endif
1393
Howard Hinnant756c69b2010-09-22 16:48:34 +00001394 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001395 size_type count(const key_type& __k) const
1396 {return __tree_.__count_unique(__k);}
Marshall Clowe6a5f522014-08-24 23:54:16 +00001397#if _LIBCPP_STD_VER > 11
1398 template <typename _K2>
1399 _LIBCPP_INLINE_VISIBILITY
1400 typename enable_if<__is_transparent<_Compare, _K2>::value,size_type>::type
Eric Fiseliera85c9e92018-02-10 02:53:47 +00001401 count(const _K2& __k) const {return __tree_.__count_multi(__k);}
Marshall Clowe6a5f522014-08-24 23:54:16 +00001402#endif
Zoe Carver3ffbab12019-07-16 03:21:01 +00001403
1404#if _LIBCPP_STD_VER > 17
1405 _LIBCPP_INLINE_VISIBILITY
1406 bool contains(const key_type& __k) const {return find(__k) != end();}
1407#endif // _LIBCPP_STD_VER > 17
1408
Howard Hinnant756c69b2010-09-22 16:48:34 +00001409 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001410 iterator lower_bound(const key_type& __k)
1411 {return __tree_.lower_bound(__k);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001412 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001413 const_iterator lower_bound(const key_type& __k) const
1414 {return __tree_.lower_bound(__k);}
Marshall Clowebb57322013-08-13 22:18:47 +00001415#if _LIBCPP_STD_VER > 11
1416 template <typename _K2>
1417 _LIBCPP_INLINE_VISIBILITY
1418 typename enable_if<__is_transparent<_Compare, _K2>::value,iterator>::type
1419 lower_bound(const _K2& __k) {return __tree_.lower_bound(__k);}
1420
1421 template <typename _K2>
1422 _LIBCPP_INLINE_VISIBILITY
1423 typename enable_if<__is_transparent<_Compare, _K2>::value,const_iterator>::type
1424 lower_bound(const _K2& __k) const {return __tree_.lower_bound(__k);}
1425#endif
1426
Howard Hinnant756c69b2010-09-22 16:48:34 +00001427 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001428 iterator upper_bound(const key_type& __k)
1429 {return __tree_.upper_bound(__k);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001430 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001431 const_iterator upper_bound(const key_type& __k) const
1432 {return __tree_.upper_bound(__k);}
Marshall Clowebb57322013-08-13 22:18:47 +00001433#if _LIBCPP_STD_VER > 11
1434 template <typename _K2>
1435 _LIBCPP_INLINE_VISIBILITY
1436 typename enable_if<__is_transparent<_Compare, _K2>::value,iterator>::type
1437 upper_bound(const _K2& __k) {return __tree_.upper_bound(__k);}
1438 template <typename _K2>
1439 _LIBCPP_INLINE_VISIBILITY
1440 typename enable_if<__is_transparent<_Compare, _K2>::value,const_iterator>::type
1441 upper_bound(const _K2& __k) const {return __tree_.upper_bound(__k);}
1442#endif
1443
Howard Hinnant756c69b2010-09-22 16:48:34 +00001444 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001445 pair<iterator,iterator> equal_range(const key_type& __k)
1446 {return __tree_.__equal_range_unique(__k);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001447 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001448 pair<const_iterator,const_iterator> equal_range(const key_type& __k) const
1449 {return __tree_.__equal_range_unique(__k);}
Marshall Clowebb57322013-08-13 22:18:47 +00001450#if _LIBCPP_STD_VER > 11
1451 template <typename _K2>
1452 _LIBCPP_INLINE_VISIBILITY
1453 typename enable_if<__is_transparent<_Compare, _K2>::value,pair<iterator,iterator>>::type
Eric Fiseliera85c9e92018-02-10 02:53:47 +00001454 equal_range(const _K2& __k) {return __tree_.__equal_range_multi(__k);}
Marshall Clowebb57322013-08-13 22:18:47 +00001455 template <typename _K2>
1456 _LIBCPP_INLINE_VISIBILITY
1457 typename enable_if<__is_transparent<_Compare, _K2>::value,pair<const_iterator,const_iterator>>::type
Eric Fiseliera85c9e92018-02-10 02:53:47 +00001458 equal_range(const _K2& __k) const {return __tree_.__equal_range_multi(__k);}
Marshall Clowebb57322013-08-13 22:18:47 +00001459#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001460
1461private:
1462 typedef typename __base::__node __node;
1463 typedef typename __base::__node_allocator __node_allocator;
1464 typedef typename __base::__node_pointer __node_pointer;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001465 typedef typename __base::__node_base_pointer __node_base_pointer;
Eric Fiseliercf8c0212017-01-05 06:06:18 +00001466 typedef typename __base::__parent_pointer __parent_pointer;
Eric Fiseliera92b0732016-02-20 07:12:17 +00001467
Howard Hinnantc834c512011-11-29 18:15:50 +00001468 typedef __map_node_destructor<__node_allocator> _Dp;
1469 typedef unique_ptr<__node, _Dp> __node_holder;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001470
Eric Fiselierd63f38e2016-03-31 03:13:37 +00001471#ifdef _LIBCPP_CXX03_LANG
Howard Hinnantac7e7482013-07-04 20:59:16 +00001472 __node_holder __construct_node_with_key(const key_type& __k);
Eric Fiselierd63f38e2016-03-31 03:13:37 +00001473#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001474};
1475
Louis Dionned23a5f22019-06-20 19:32:00 +00001476#ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES
1477template<class _InputIterator, class _Compare = less<__iter_key_type<_InputIterator>>,
1478 class _Allocator = allocator<__iter_to_alloc_type<_InputIterator>>,
Louis Dionne6c7da9a2019-07-19 17:13:39 +00001479 class = _EnableIf<!__is_allocator<_Compare>::value, void>,
1480 class = _EnableIf<__is_allocator<_Allocator>::value, void>>
Louis Dionned23a5f22019-06-20 19:32:00 +00001481map(_InputIterator, _InputIterator, _Compare = _Compare(), _Allocator = _Allocator())
1482 -> map<__iter_key_type<_InputIterator>, __iter_mapped_type<_InputIterator>, _Compare, _Allocator>;
1483
1484template<class _Key, class _Tp, class _Compare = less<remove_const_t<_Key>>,
1485 class _Allocator = allocator<pair<const _Key, _Tp>>,
Louis Dionne6c7da9a2019-07-19 17:13:39 +00001486 class = _EnableIf<!__is_allocator<_Compare>::value, void>,
1487 class = _EnableIf<__is_allocator<_Allocator>::value, void>>
Louis Dionned23a5f22019-06-20 19:32:00 +00001488map(initializer_list<pair<_Key, _Tp>>, _Compare = _Compare(), _Allocator = _Allocator())
1489 -> map<remove_const_t<_Key>, _Tp, _Compare, _Allocator>;
1490
1491template<class _InputIterator, class _Allocator,
Louis Dionne6c7da9a2019-07-19 17:13:39 +00001492 class = _EnableIf<__is_allocator<_Allocator>::value, void>>
Louis Dionned23a5f22019-06-20 19:32:00 +00001493map(_InputIterator, _InputIterator, _Allocator)
1494 -> map<__iter_key_type<_InputIterator>, __iter_mapped_type<_InputIterator>,
1495 less<__iter_key_type<_InputIterator>>, _Allocator>;
1496
1497template<class _Key, class _Tp, class _Allocator,
Louis Dionne6c7da9a2019-07-19 17:13:39 +00001498 class = _EnableIf<__is_allocator<_Allocator>::value, void>>
Louis Dionned23a5f22019-06-20 19:32:00 +00001499map(initializer_list<pair<_Key, _Tp>>, _Allocator)
1500 -> map<remove_const_t<_Key>, _Tp, less<remove_const_t<_Key>>, _Allocator>;
1501#endif
Eric Fiseliera92b0732016-02-20 07:12:17 +00001502
Eric Fiselierd06276b2016-03-31 02:15:15 +00001503#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001504template <class _Key, class _Tp, class _Compare, class _Allocator>
1505map<_Key, _Tp, _Compare, _Allocator>::map(map&& __m, const allocator_type& __a)
Marshall Clow657cbc42016-08-17 05:58:40 +00001506 : __tree_(_VSTD::move(__m.__tree_), typename __base::allocator_type(__a))
Howard Hinnantc51e1022010-05-11 19:42:16 +00001507{
1508 if (__a != __m.get_allocator())
1509 {
1510 const_iterator __e = cend();
1511 while (!__m.empty())
1512 __tree_.__insert_unique(__e.__i_,
Erik Pilkingtond3fe2992018-06-04 20:38:23 +00001513 __m.__tree_.remove(__m.begin().__i_)->__value_.__move());
Howard Hinnantc51e1022010-05-11 19:42:16 +00001514 }
1515}
1516
Eric Fiseliera85b1282017-04-18 21:08:06 +00001517template <class _Key, class _Tp, class _Compare, class _Allocator>
1518_Tp&
1519map<_Key, _Tp, _Compare, _Allocator>::operator[](const key_type& __k)
1520{
1521 return __tree_.__emplace_unique_key_args(__k,
1522 _VSTD::piecewise_construct,
1523 _VSTD::forward_as_tuple(__k),
Erik Pilkingtond3fe2992018-06-04 20:38:23 +00001524 _VSTD::forward_as_tuple()).first->__get_value().second;
Eric Fiseliera85b1282017-04-18 21:08:06 +00001525}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001526
Eric Fiseliera85b1282017-04-18 21:08:06 +00001527template <class _Key, class _Tp, class _Compare, class _Allocator>
1528_Tp&
1529map<_Key, _Tp, _Compare, _Allocator>::operator[](key_type&& __k)
1530{
1531 return __tree_.__emplace_unique_key_args(__k,
1532 _VSTD::piecewise_construct,
1533 _VSTD::forward_as_tuple(_VSTD::move(__k)),
Erik Pilkingtond3fe2992018-06-04 20:38:23 +00001534 _VSTD::forward_as_tuple()).first->__get_value().second;
Eric Fiseliera85b1282017-04-18 21:08:06 +00001535}
Eric Fiselierd63f38e2016-03-31 03:13:37 +00001536
Eric Fiseliera85b1282017-04-18 21:08:06 +00001537#else // _LIBCPP_CXX03_LANG
Eric Fiselierd63f38e2016-03-31 03:13:37 +00001538
Howard Hinnantc51e1022010-05-11 19:42:16 +00001539template <class _Key, class _Tp, class _Compare, class _Allocator>
1540typename map<_Key, _Tp, _Compare, _Allocator>::__node_holder
Howard Hinnantac7e7482013-07-04 20:59:16 +00001541map<_Key, _Tp, _Compare, _Allocator>::__construct_node_with_key(const key_type& __k)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001542{
1543 __node_allocator& __na = __tree_.__node_alloc();
Howard Hinnantc834c512011-11-29 18:15:50 +00001544 __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
Erik Pilkingtond3fe2992018-06-04 20:38:23 +00001545 __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__get_value().first), __k);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001546 __h.get_deleter().__first_constructed = true;
Erik Pilkingtond3fe2992018-06-04 20:38:23 +00001547 __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__get_value().second));
Howard Hinnantc51e1022010-05-11 19:42:16 +00001548 __h.get_deleter().__second_constructed = true;
Dimitry Andric830fb602015-08-19 06:43:33 +00001549 return _LIBCPP_EXPLICIT_MOVE(__h); // explicitly moved for C++03
Howard Hinnantc51e1022010-05-11 19:42:16 +00001550}
1551
Howard Hinnantc51e1022010-05-11 19:42:16 +00001552template <class _Key, class _Tp, class _Compare, class _Allocator>
1553_Tp&
1554map<_Key, _Tp, _Compare, _Allocator>::operator[](const key_type& __k)
1555{
Eric Fiseliercf8c0212017-01-05 06:06:18 +00001556 __parent_pointer __parent;
1557 __node_base_pointer& __child = __tree_.__find_equal(__parent, __k);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001558 __node_pointer __r = static_cast<__node_pointer>(__child);
1559 if (__child == nullptr)
1560 {
Howard Hinnantac7e7482013-07-04 20:59:16 +00001561 __node_holder __h = __construct_node_with_key(__k);
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001562 __tree_.__insert_node_at(__parent, __child, static_cast<__node_base_pointer>(__h.get()));
Howard Hinnantc51e1022010-05-11 19:42:16 +00001563 __r = __h.release();
1564 }
Erik Pilkingtond3fe2992018-06-04 20:38:23 +00001565 return __r->__value_.__get_value().second;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001566}
1567
Eric Fiseliera85b1282017-04-18 21:08:06 +00001568#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001569
1570template <class _Key, class _Tp, class _Compare, class _Allocator>
1571_Tp&
1572map<_Key, _Tp, _Compare, _Allocator>::at(const key_type& __k)
1573{
Eric Fiseliercf8c0212017-01-05 06:06:18 +00001574 __parent_pointer __parent;
1575 __node_base_pointer& __child = __tree_.__find_equal(__parent, __k);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001576 if (__child == nullptr)
Louis Dionne2b239162019-02-12 16:06:02 +00001577 __throw_out_of_range("map::at: key not found");
Erik Pilkingtond3fe2992018-06-04 20:38:23 +00001578 return static_cast<__node_pointer>(__child)->__value_.__get_value().second;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001579}
1580
1581template <class _Key, class _Tp, class _Compare, class _Allocator>
1582const _Tp&
1583map<_Key, _Tp, _Compare, _Allocator>::at(const key_type& __k) const
1584{
Eric Fiseliercf8c0212017-01-05 06:06:18 +00001585 __parent_pointer __parent;
1586 __node_base_pointer __child = __tree_.__find_equal(__parent, __k);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001587 if (__child == nullptr)
Louis Dionne2b239162019-02-12 16:06:02 +00001588 __throw_out_of_range("map::at: key not found");
Erik Pilkingtond3fe2992018-06-04 20:38:23 +00001589 return static_cast<__node_pointer>(__child)->__value_.__get_value().second;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001590}
1591
Howard Hinnantc51e1022010-05-11 19:42:16 +00001592
1593template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001594inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001595bool
1596operator==(const map<_Key, _Tp, _Compare, _Allocator>& __x,
1597 const map<_Key, _Tp, _Compare, _Allocator>& __y)
1598{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001599 return __x.size() == __y.size() && _VSTD::equal(__x.begin(), __x.end(), __y.begin());
Howard Hinnantc51e1022010-05-11 19:42:16 +00001600}
1601
1602template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001603inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001604bool
1605operator< (const map<_Key, _Tp, _Compare, _Allocator>& __x,
1606 const map<_Key, _Tp, _Compare, _Allocator>& __y)
1607{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001608 return _VSTD::lexicographical_compare(__x.begin(), __x.end(), __y.begin(), __y.end());
Howard Hinnantc51e1022010-05-11 19:42:16 +00001609}
1610
1611template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001612inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001613bool
1614operator!=(const map<_Key, _Tp, _Compare, _Allocator>& __x,
1615 const map<_Key, _Tp, _Compare, _Allocator>& __y)
1616{
1617 return !(__x == __y);
1618}
1619
1620template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001621inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001622bool
1623operator> (const map<_Key, _Tp, _Compare, _Allocator>& __x,
1624 const map<_Key, _Tp, _Compare, _Allocator>& __y)
1625{
1626 return __y < __x;
1627}
1628
1629template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001630inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001631bool
1632operator>=(const map<_Key, _Tp, _Compare, _Allocator>& __x,
1633 const map<_Key, _Tp, _Compare, _Allocator>& __y)
1634{
1635 return !(__x < __y);
1636}
1637
1638template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001639inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001640bool
1641operator<=(const map<_Key, _Tp, _Compare, _Allocator>& __x,
1642 const map<_Key, _Tp, _Compare, _Allocator>& __y)
1643{
1644 return !(__y < __x);
1645}
1646
1647template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001648inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001649void
1650swap(map<_Key, _Tp, _Compare, _Allocator>& __x,
1651 map<_Key, _Tp, _Compare, _Allocator>& __y)
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001652 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
Howard Hinnantc51e1022010-05-11 19:42:16 +00001653{
1654 __x.swap(__y);
1655}
1656
Marshall Clow29b53f22018-12-14 18:49:35 +00001657#if _LIBCPP_STD_VER > 17
Marek Kurdeja98b1412020-05-02 13:58:03 +02001658template <class _Key, class _Tp, class _Compare, class _Allocator,
1659 class _Predicate>
Marshall Clow29b53f22018-12-14 18:49:35 +00001660inline _LIBCPP_INLINE_VISIBILITY
Marek Kurdeja98b1412020-05-02 13:58:03 +02001661 typename map<_Key, _Tp, _Compare, _Allocator>::size_type
1662 erase_if(map<_Key, _Tp, _Compare, _Allocator>& __c, _Predicate __pred) {
1663 return __libcpp_erase_if_container(__c, __pred);
1664}
Marshall Clow29b53f22018-12-14 18:49:35 +00001665#endif
1666
1667
Howard Hinnantc51e1022010-05-11 19:42:16 +00001668template <class _Key, class _Tp, class _Compare = less<_Key>,
1669 class _Allocator = allocator<pair<const _Key, _Tp> > >
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00001670class _LIBCPP_TEMPLATE_VIS multimap
Howard Hinnantc51e1022010-05-11 19:42:16 +00001671{
1672public:
1673 // types:
1674 typedef _Key key_type;
1675 typedef _Tp mapped_type;
1676 typedef pair<const key_type, mapped_type> value_type;
Louis Dionned23a5f22019-06-20 19:32:00 +00001677 typedef typename __identity<_Compare>::type key_compare;
1678 typedef typename __identity<_Allocator>::type allocator_type;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001679 typedef value_type& reference;
1680 typedef const value_type& const_reference;
1681
Marshall Clow5128cf32015-11-26 01:24:04 +00001682 static_assert((is_same<typename allocator_type::value_type, value_type>::value),
1683 "Allocator::value_type must be same type as value_type");
1684
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00001685 class _LIBCPP_TEMPLATE_VIS value_compare
Howard Hinnantc51e1022010-05-11 19:42:16 +00001686 : public binary_function<value_type, value_type, bool>
1687 {
1688 friend class multimap;
1689 protected:
1690 key_compare comp;
1691
Howard Hinnant756c69b2010-09-22 16:48:34 +00001692 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001693 value_compare(key_compare c) : comp(c) {}
1694 public:
Howard Hinnant756c69b2010-09-22 16:48:34 +00001695 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001696 bool operator()(const value_type& __x, const value_type& __y) const
1697 {return comp(__x.first, __y.first);}
1698 };
1699
1700private:
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001701
Howard Hinnant89f8b792013-09-30 19:08:22 +00001702 typedef _VSTD::__value_type<key_type, mapped_type> __value_type;
Howard Hinnant90b91592013-07-05 18:06:00 +00001703 typedef __map_value_compare<key_type, __value_type, key_compare> __vc;
Marshall Clow940e01c2015-04-07 05:21:38 +00001704 typedef typename __rebind_alloc_helper<allocator_traits<allocator_type>,
1705 __value_type>::type __allocator_type;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001706 typedef __tree<__value_type, __vc, __allocator_type> __base;
1707 typedef typename __base::__node_traits __node_traits;
1708 typedef allocator_traits<allocator_type> __alloc_traits;
1709
1710 __base __tree_;
1711
1712public:
1713 typedef typename __alloc_traits::pointer pointer;
1714 typedef typename __alloc_traits::const_pointer const_pointer;
1715 typedef typename __alloc_traits::size_type size_type;
1716 typedef typename __alloc_traits::difference_type difference_type;
1717 typedef __map_iterator<typename __base::iterator> iterator;
1718 typedef __map_const_iterator<typename __base::const_iterator> const_iterator;
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001719 typedef _VSTD::reverse_iterator<iterator> reverse_iterator;
1720 typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001721
Erik Pilkingtonc37a3d82018-08-01 01:33:38 +00001722#if _LIBCPP_STD_VER > 14
1723 typedef __map_node_handle<typename __base::__node, allocator_type> node_type;
1724#endif
1725
Erik Pilkington82a65ad2018-10-31 17:31:35 +00001726 template <class _Key2, class _Value2, class _Comp2, class _Alloc2>
1727 friend class _LIBCPP_TEMPLATE_VIS map;
1728 template <class _Key2, class _Value2, class _Comp2, class _Alloc2>
1729 friend class _LIBCPP_TEMPLATE_VIS multimap;
1730
Howard Hinnant756c69b2010-09-22 16:48:34 +00001731 _LIBCPP_INLINE_VISIBILITY
Marshall Clow7086a5a2014-03-10 04:50:10 +00001732 multimap()
1733 _NOEXCEPT_(
1734 is_nothrow_default_constructible<allocator_type>::value &&
1735 is_nothrow_default_constructible<key_compare>::value &&
1736 is_nothrow_copy_constructible<key_compare>::value)
1737 : __tree_(__vc(key_compare())) {}
1738
1739 _LIBCPP_INLINE_VISIBILITY
1740 explicit multimap(const key_compare& __comp)
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001741 _NOEXCEPT_(
1742 is_nothrow_default_constructible<allocator_type>::value &&
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001743 is_nothrow_copy_constructible<key_compare>::value)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001744 : __tree_(__vc(__comp)) {}
1745
Howard Hinnant756c69b2010-09-22 16:48:34 +00001746 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001747 explicit multimap(const key_compare& __comp, const allocator_type& __a)
Marshall Clow657cbc42016-08-17 05:58:40 +00001748 : __tree_(__vc(__comp), typename __base::allocator_type(__a)) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001749
1750 template <class _InputIterator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001751 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001752 multimap(_InputIterator __f, _InputIterator __l,
1753 const key_compare& __comp = key_compare())
1754 : __tree_(__vc(__comp))
1755 {
1756 insert(__f, __l);
1757 }
1758
1759 template <class _InputIterator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001760 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001761 multimap(_InputIterator __f, _InputIterator __l,
1762 const key_compare& __comp, const allocator_type& __a)
Marshall Clow657cbc42016-08-17 05:58:40 +00001763 : __tree_(__vc(__comp), typename __base::allocator_type(__a))
Howard Hinnantc51e1022010-05-11 19:42:16 +00001764 {
1765 insert(__f, __l);
1766 }
1767
Marshall Clow300abfb2013-09-11 01:15:47 +00001768#if _LIBCPP_STD_VER > 11
1769 template <class _InputIterator>
Eric Fiseliercf8c0212017-01-05 06:06:18 +00001770 _LIBCPP_INLINE_VISIBILITY
Marshall Clow300abfb2013-09-11 01:15:47 +00001771 multimap(_InputIterator __f, _InputIterator __l, const allocator_type& __a)
1772 : multimap(__f, __l, key_compare(), __a) {}
1773#endif
1774
Howard Hinnant756c69b2010-09-22 16:48:34 +00001775 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001776 multimap(const multimap& __m)
1777 : __tree_(__m.__tree_.value_comp(),
1778 __alloc_traits::select_on_container_copy_construction(__m.__tree_.__alloc()))
1779 {
1780 insert(__m.begin(), __m.end());
1781 }
1782
Howard Hinnantd3a657f2011-07-01 19:24:36 +00001783 _LIBCPP_INLINE_VISIBILITY
1784 multimap& operator=(const multimap& __m)
1785 {
Marshall Clow476d3f42016-07-18 13:19:00 +00001786#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantd3a657f2011-07-01 19:24:36 +00001787 __tree_ = __m.__tree_;
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001788#else
Marshall Clowdb3cfcb2014-02-08 04:03:14 +00001789 if (this != &__m) {
1790 __tree_.clear();
1791 __tree_.value_comp() = __m.__tree_.value_comp();
1792 __tree_.__copy_assign_alloc(__m.__tree_);
1793 insert(__m.begin(), __m.end());
1794 }
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001795#endif
Howard Hinnantd3a657f2011-07-01 19:24:36 +00001796 return *this;
1797 }
1798
Eric Fiseliera85b1282017-04-18 21:08:06 +00001799#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001800
Howard Hinnant756c69b2010-09-22 16:48:34 +00001801 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001802 multimap(multimap&& __m)
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001803 _NOEXCEPT_(is_nothrow_move_constructible<__base>::value)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001804 : __tree_(_VSTD::move(__m.__tree_))
Howard Hinnantc51e1022010-05-11 19:42:16 +00001805 {
1806 }
1807
1808 multimap(multimap&& __m, const allocator_type& __a);
1809
Howard Hinnant756c69b2010-09-22 16:48:34 +00001810 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant33711792011-08-12 21:56:02 +00001811 multimap& operator=(multimap&& __m)
1812 _NOEXCEPT_(is_nothrow_move_assignable<__base>::value)
1813 {
1814 __tree_ = _VSTD::move(__m.__tree_);
1815 return *this;
1816 }
1817
Howard Hinnant33711792011-08-12 21:56:02 +00001818 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001819 multimap(initializer_list<value_type> __il, const key_compare& __comp = key_compare())
1820 : __tree_(__vc(__comp))
1821 {
1822 insert(__il.begin(), __il.end());
1823 }
1824
Howard Hinnant756c69b2010-09-22 16:48:34 +00001825 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001826 multimap(initializer_list<value_type> __il, const key_compare& __comp, const allocator_type& __a)
Marshall Clow657cbc42016-08-17 05:58:40 +00001827 : __tree_(__vc(__comp), typename __base::allocator_type(__a))
Howard Hinnantc51e1022010-05-11 19:42:16 +00001828 {
1829 insert(__il.begin(), __il.end());
1830 }
1831
Marshall Clow300abfb2013-09-11 01:15:47 +00001832#if _LIBCPP_STD_VER > 11
Eric Fiseliercf8c0212017-01-05 06:06:18 +00001833 _LIBCPP_INLINE_VISIBILITY
Marshall Clow300abfb2013-09-11 01:15:47 +00001834 multimap(initializer_list<value_type> __il, const allocator_type& __a)
1835 : multimap(__il, key_compare(), __a) {}
1836#endif
1837
Howard Hinnant756c69b2010-09-22 16:48:34 +00001838 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001839 multimap& operator=(initializer_list<value_type> __il)
1840 {
1841 __tree_.__assign_multi(__il.begin(), __il.end());
1842 return *this;
1843 }
Howard Hinnant33711792011-08-12 21:56:02 +00001844
Eric Fiseliera85b1282017-04-18 21:08:06 +00001845#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001846
Howard Hinnant756c69b2010-09-22 16:48:34 +00001847 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001848 explicit multimap(const allocator_type& __a)
Marshall Clow657cbc42016-08-17 05:58:40 +00001849 : __tree_(typename __base::allocator_type(__a))
Howard Hinnantc51e1022010-05-11 19:42:16 +00001850 {
1851 }
1852
Howard Hinnant756c69b2010-09-22 16:48:34 +00001853 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001854 multimap(const multimap& __m, const allocator_type& __a)
Marshall Clow657cbc42016-08-17 05:58:40 +00001855 : __tree_(__m.__tree_.value_comp(), typename __base::allocator_type(__a))
Howard Hinnantc51e1022010-05-11 19:42:16 +00001856 {
1857 insert(__m.begin(), __m.end());
1858 }
1859
Howard Hinnant756c69b2010-09-22 16:48:34 +00001860 _LIBCPP_INLINE_VISIBILITY
Louis Dionne69c42c02019-04-11 16:14:56 +00001861 ~multimap() {
1862 static_assert(sizeof(__diagnose_non_const_comparator<_Key, _Compare>()), "");
1863 }
1864
1865 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001866 iterator begin() _NOEXCEPT {return __tree_.begin();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001867 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001868 const_iterator begin() const _NOEXCEPT {return __tree_.begin();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001869 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001870 iterator end() _NOEXCEPT {return __tree_.end();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001871 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001872 const_iterator end() const _NOEXCEPT {return __tree_.end();}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001873
Howard Hinnant756c69b2010-09-22 16:48:34 +00001874 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001875 reverse_iterator rbegin() _NOEXCEPT {return reverse_iterator(end());}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001876 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001877 const_reverse_iterator rbegin() const _NOEXCEPT
1878 {return const_reverse_iterator(end());}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001879 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001880 reverse_iterator rend() _NOEXCEPT {return reverse_iterator(begin());}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001881 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001882 const_reverse_iterator rend() const _NOEXCEPT
1883 {return const_reverse_iterator(begin());}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001884
Howard Hinnant756c69b2010-09-22 16:48:34 +00001885 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001886 const_iterator cbegin() const _NOEXCEPT {return begin();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001887 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001888 const_iterator cend() const _NOEXCEPT {return end();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001889 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001890 const_reverse_iterator crbegin() const _NOEXCEPT {return rbegin();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001891 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001892 const_reverse_iterator crend() const _NOEXCEPT {return rend();}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001893
Marshall Clow425f5752017-11-15 05:51:26 +00001894 _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001895 bool empty() const _NOEXCEPT {return __tree_.size() == 0;}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001896 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001897 size_type size() const _NOEXCEPT {return __tree_.size();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001898 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001899 size_type max_size() const _NOEXCEPT {return __tree_.max_size();}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001900
Howard Hinnant756c69b2010-09-22 16:48:34 +00001901 _LIBCPP_INLINE_VISIBILITY
Marshall Clow657cbc42016-08-17 05:58:40 +00001902 allocator_type get_allocator() const _NOEXCEPT {return allocator_type(__tree_.__alloc());}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001903 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001904 key_compare key_comp() const {return __tree_.value_comp().key_comp();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001905 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001906 value_compare value_comp() const
1907 {return value_compare(__tree_.value_comp().key_comp());}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001908
Eric Fiselierd06276b2016-03-31 02:15:15 +00001909#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant74279a52010-09-04 23:28:19 +00001910
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001911 template <class ..._Args>
Eric Fiselierd06276b2016-03-31 02:15:15 +00001912 _LIBCPP_INLINE_VISIBILITY
1913 iterator emplace(_Args&& ...__args) {
1914 return __tree_.__emplace_multi(_VSTD::forward<_Args>(__args)...);
1915 }
Howard Hinnantc51e1022010-05-11 19:42:16 +00001916
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001917 template <class ..._Args>
Eric Fiselierd06276b2016-03-31 02:15:15 +00001918 _LIBCPP_INLINE_VISIBILITY
1919 iterator emplace_hint(const_iterator __p, _Args&& ...__args) {
1920 return __tree_.__emplace_hint_multi(__p.__i_, _VSTD::forward<_Args>(__args)...);
1921 }
Howard Hinnant74279a52010-09-04 23:28:19 +00001922
Howard Hinnantc834c512011-11-29 18:15:50 +00001923 template <class _Pp,
1924 class = typename enable_if<is_constructible<value_type, _Pp>::value>::type>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001925 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc834c512011-11-29 18:15:50 +00001926 iterator insert(_Pp&& __p)
1927 {return __tree_.__insert_multi(_VSTD::forward<_Pp>(__p));}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001928
Howard Hinnantc834c512011-11-29 18:15:50 +00001929 template <class _Pp,
1930 class = typename enable_if<is_constructible<value_type, _Pp>::value>::type>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001931 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc834c512011-11-29 18:15:50 +00001932 iterator insert(const_iterator __pos, _Pp&& __p)
1933 {return __tree_.__insert_multi(__pos.__i_, _VSTD::forward<_Pp>(__p));}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001934
Eric Fiselierd6143132016-04-18 01:40:45 +00001935 _LIBCPP_INLINE_VISIBILITY
1936 iterator insert(value_type&& __v)
1937 {return __tree_.__insert_multi(_VSTD::move(__v));}
1938
1939 _LIBCPP_INLINE_VISIBILITY
1940 iterator insert(const_iterator __p, value_type&& __v)
1941 {return __tree_.__insert_multi(__p.__i_, _VSTD::move(__v));}
1942
Eric Fiseliera85b1282017-04-18 21:08:06 +00001943
1944 _LIBCPP_INLINE_VISIBILITY
1945 void insert(initializer_list<value_type> __il)
1946 {insert(__il.begin(), __il.end());}
1947
Eric Fiselierd06276b2016-03-31 02:15:15 +00001948#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001949
Howard Hinnant756c69b2010-09-22 16:48:34 +00001950 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001951 iterator insert(const value_type& __v) {return __tree_.__insert_multi(__v);}
1952
Howard Hinnant756c69b2010-09-22 16:48:34 +00001953 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001954 iterator insert(const_iterator __p, const value_type& __v)
1955 {return __tree_.__insert_multi(__p.__i_, __v);}
1956
1957 template <class _InputIterator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001958 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001959 void insert(_InputIterator __f, _InputIterator __l)
1960 {
1961 for (const_iterator __e = cend(); __f != __l; ++__f)
1962 __tree_.__insert_multi(__e.__i_, *__f);
1963 }
1964
Howard Hinnant756c69b2010-09-22 16:48:34 +00001965 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001966 iterator erase(const_iterator __p) {return __tree_.erase(__p.__i_);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001967 _LIBCPP_INLINE_VISIBILITY
Marshall Clow22ea5b82015-05-10 13:35:00 +00001968 iterator erase(iterator __p) {return __tree_.erase(__p.__i_);}
1969 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001970 size_type erase(const key_type& __k) {return __tree_.__erase_multi(__k);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001971 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001972 iterator erase(const_iterator __f, const_iterator __l)
1973 {return __tree_.erase(__f.__i_, __l.__i_);}
Erik Pilkingtonc37a3d82018-08-01 01:33:38 +00001974
1975#if _LIBCPP_STD_VER > 14
1976 _LIBCPP_INLINE_VISIBILITY
1977 iterator insert(node_type&& __nh)
1978 {
1979 _LIBCPP_ASSERT(__nh.empty() || __nh.get_allocator() == get_allocator(),
1980 "node_type with incompatible allocator passed to multimap::insert()");
1981 return __tree_.template __node_handle_insert_multi<node_type>(
1982 _VSTD::move(__nh));
1983 }
1984 _LIBCPP_INLINE_VISIBILITY
1985 iterator insert(const_iterator __hint, node_type&& __nh)
1986 {
1987 _LIBCPP_ASSERT(__nh.empty() || __nh.get_allocator() == get_allocator(),
1988 "node_type with incompatible allocator passed to multimap::insert()");
1989 return __tree_.template __node_handle_insert_multi<node_type>(
1990 __hint.__i_, _VSTD::move(__nh));
1991 }
1992 _LIBCPP_INLINE_VISIBILITY
1993 node_type extract(key_type const& __key)
1994 {
1995 return __tree_.template __node_handle_extract<node_type>(__key);
1996 }
1997 _LIBCPP_INLINE_VISIBILITY
1998 node_type extract(const_iterator __it)
1999 {
2000 return __tree_.template __node_handle_extract<node_type>(
2001 __it.__i_);
2002 }
Louis Dionned2322c82018-11-01 14:41:37 +00002003 template <class _Compare2>
Erik Pilkington82a65ad2018-10-31 17:31:35 +00002004 _LIBCPP_INLINE_VISIBILITY
Louis Dionned2322c82018-11-01 14:41:37 +00002005 void merge(multimap<key_type, mapped_type, _Compare2, allocator_type>& __source)
Erik Pilkington82a65ad2018-10-31 17:31:35 +00002006 {
2007 _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
2008 "merging container with incompatible allocator");
2009 return __tree_.__node_handle_merge_multi(__source.__tree_);
2010 }
Louis Dionned2322c82018-11-01 14:41:37 +00002011 template <class _Compare2>
Erik Pilkington82a65ad2018-10-31 17:31:35 +00002012 _LIBCPP_INLINE_VISIBILITY
Louis Dionned2322c82018-11-01 14:41:37 +00002013 void merge(multimap<key_type, mapped_type, _Compare2, allocator_type>&& __source)
Erik Pilkington82a65ad2018-10-31 17:31:35 +00002014 {
2015 _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
2016 "merging container with incompatible allocator");
2017 return __tree_.__node_handle_merge_multi(__source.__tree_);
2018 }
Louis Dionned2322c82018-11-01 14:41:37 +00002019 template <class _Compare2>
Erik Pilkington82a65ad2018-10-31 17:31:35 +00002020 _LIBCPP_INLINE_VISIBILITY
Louis Dionned2322c82018-11-01 14:41:37 +00002021 void merge(map<key_type, mapped_type, _Compare2, allocator_type>& __source)
Erik Pilkington82a65ad2018-10-31 17:31:35 +00002022 {
2023 _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
2024 "merging container with incompatible allocator");
2025 return __tree_.__node_handle_merge_multi(__source.__tree_);
2026 }
Louis Dionned2322c82018-11-01 14:41:37 +00002027 template <class _Compare2>
Erik Pilkington82a65ad2018-10-31 17:31:35 +00002028 _LIBCPP_INLINE_VISIBILITY
Louis Dionned2322c82018-11-01 14:41:37 +00002029 void merge(map<key_type, mapped_type, _Compare2, allocator_type>&& __source)
Erik Pilkington82a65ad2018-10-31 17:31:35 +00002030 {
2031 _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
2032 "merging container with incompatible allocator");
2033 return __tree_.__node_handle_merge_multi(__source.__tree_);
2034 }
Erik Pilkingtonc37a3d82018-08-01 01:33:38 +00002035#endif
2036
Howard Hinnant756c69b2010-09-22 16:48:34 +00002037 _LIBCPP_INLINE_VISIBILITY
Marshall Clowde1312a2018-08-22 04:28:43 +00002038 void clear() _NOEXCEPT {__tree_.clear();}
Howard Hinnantc51e1022010-05-11 19:42:16 +00002039
Howard Hinnant756c69b2010-09-22 16:48:34 +00002040 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00002041 void swap(multimap& __m)
2042 _NOEXCEPT_(__is_nothrow_swappable<__base>::value)
2043 {__tree_.swap(__m.__tree_);}
Howard Hinnantc51e1022010-05-11 19:42:16 +00002044
Howard Hinnant756c69b2010-09-22 16:48:34 +00002045 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002046 iterator find(const key_type& __k) {return __tree_.find(__k);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00002047 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002048 const_iterator find(const key_type& __k) const {return __tree_.find(__k);}
Marshall Clowebb57322013-08-13 22:18:47 +00002049#if _LIBCPP_STD_VER > 11
2050 template <typename _K2>
2051 _LIBCPP_INLINE_VISIBILITY
2052 typename enable_if<__is_transparent<_Compare, _K2>::value,iterator>::type
2053 find(const _K2& __k) {return __tree_.find(__k);}
2054 template <typename _K2>
2055 _LIBCPP_INLINE_VISIBILITY
2056 typename enable_if<__is_transparent<_Compare, _K2>::value,const_iterator>::type
2057 find(const _K2& __k) const {return __tree_.find(__k);}
2058#endif
2059
Howard Hinnant756c69b2010-09-22 16:48:34 +00002060 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002061 size_type count(const key_type& __k) const
2062 {return __tree_.__count_multi(__k);}
Marshall Clowe6a5f522014-08-24 23:54:16 +00002063#if _LIBCPP_STD_VER > 11
2064 template <typename _K2>
2065 _LIBCPP_INLINE_VISIBILITY
2066 typename enable_if<__is_transparent<_Compare, _K2>::value,size_type>::type
Marshall Clow141e47b2015-06-30 18:15:41 +00002067 count(const _K2& __k) const {return __tree_.__count_multi(__k);}
Marshall Clowe6a5f522014-08-24 23:54:16 +00002068#endif
Zoe Carver3ffbab12019-07-16 03:21:01 +00002069
2070#if _LIBCPP_STD_VER > 17
2071 _LIBCPP_INLINE_VISIBILITY
2072 bool contains(const key_type& __k) const {return find(__k) != end();}
2073#endif // _LIBCPP_STD_VER > 17
2074
Howard Hinnant756c69b2010-09-22 16:48:34 +00002075 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002076 iterator lower_bound(const key_type& __k)
2077 {return __tree_.lower_bound(__k);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00002078 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002079 const_iterator lower_bound(const key_type& __k) const
2080 {return __tree_.lower_bound(__k);}
Marshall Clowebb57322013-08-13 22:18:47 +00002081#if _LIBCPP_STD_VER > 11
2082 template <typename _K2>
2083 _LIBCPP_INLINE_VISIBILITY
2084 typename enable_if<__is_transparent<_Compare, _K2>::value,iterator>::type
2085 lower_bound(const _K2& __k) {return __tree_.lower_bound(__k);}
2086
2087 template <typename _K2>
2088 _LIBCPP_INLINE_VISIBILITY
2089 typename enable_if<__is_transparent<_Compare, _K2>::value,const_iterator>::type
2090 lower_bound(const _K2& __k) const {return __tree_.lower_bound(__k);}
2091#endif
2092
Howard Hinnant756c69b2010-09-22 16:48:34 +00002093 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002094 iterator upper_bound(const key_type& __k)
2095 {return __tree_.upper_bound(__k);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00002096 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002097 const_iterator upper_bound(const key_type& __k) const
2098 {return __tree_.upper_bound(__k);}
Marshall Clowebb57322013-08-13 22:18:47 +00002099#if _LIBCPP_STD_VER > 11
2100 template <typename _K2>
2101 _LIBCPP_INLINE_VISIBILITY
2102 typename enable_if<__is_transparent<_Compare, _K2>::value,iterator>::type
2103 upper_bound(const _K2& __k) {return __tree_.upper_bound(__k);}
2104 template <typename _K2>
2105 _LIBCPP_INLINE_VISIBILITY
2106 typename enable_if<__is_transparent<_Compare, _K2>::value,const_iterator>::type
2107 upper_bound(const _K2& __k) const {return __tree_.upper_bound(__k);}
2108#endif
2109
Howard Hinnant756c69b2010-09-22 16:48:34 +00002110 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002111 pair<iterator,iterator> equal_range(const key_type& __k)
2112 {return __tree_.__equal_range_multi(__k);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00002113 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002114 pair<const_iterator,const_iterator> equal_range(const key_type& __k) const
2115 {return __tree_.__equal_range_multi(__k);}
Marshall Clowebb57322013-08-13 22:18:47 +00002116#if _LIBCPP_STD_VER > 11
2117 template <typename _K2>
2118 _LIBCPP_INLINE_VISIBILITY
2119 typename enable_if<__is_transparent<_Compare, _K2>::value,pair<iterator,iterator>>::type
2120 equal_range(const _K2& __k) {return __tree_.__equal_range_multi(__k);}
2121 template <typename _K2>
2122 _LIBCPP_INLINE_VISIBILITY
2123 typename enable_if<__is_transparent<_Compare, _K2>::value,pair<const_iterator,const_iterator>>::type
2124 equal_range(const _K2& __k) const {return __tree_.__equal_range_multi(__k);}
2125#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00002126
2127private:
2128 typedef typename __base::__node __node;
2129 typedef typename __base::__node_allocator __node_allocator;
2130 typedef typename __base::__node_pointer __node_pointer;
Eric Fiseliera92b0732016-02-20 07:12:17 +00002131
Howard Hinnantc834c512011-11-29 18:15:50 +00002132 typedef __map_node_destructor<__node_allocator> _Dp;
2133 typedef unique_ptr<__node, _Dp> __node_holder;
Howard Hinnantc51e1022010-05-11 19:42:16 +00002134};
2135
Louis Dionned23a5f22019-06-20 19:32:00 +00002136#ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES
2137template<class _InputIterator, class _Compare = less<__iter_key_type<_InputIterator>>,
2138 class _Allocator = allocator<__iter_to_alloc_type<_InputIterator>>,
Louis Dionne6c7da9a2019-07-19 17:13:39 +00002139 class = _EnableIf<!__is_allocator<_Compare>::value, void>,
2140 class = _EnableIf<__is_allocator<_Allocator>::value, void>>
Louis Dionned23a5f22019-06-20 19:32:00 +00002141multimap(_InputIterator, _InputIterator, _Compare = _Compare(), _Allocator = _Allocator())
2142 -> multimap<__iter_key_type<_InputIterator>, __iter_mapped_type<_InputIterator>, _Compare, _Allocator>;
2143
2144template<class _Key, class _Tp, class _Compare = less<remove_const_t<_Key>>,
2145 class _Allocator = allocator<pair<const _Key, _Tp>>,
Louis Dionne6c7da9a2019-07-19 17:13:39 +00002146 class = _EnableIf<!__is_allocator<_Compare>::value, void>,
2147 class = _EnableIf<__is_allocator<_Allocator>::value, void>>
Louis Dionned23a5f22019-06-20 19:32:00 +00002148multimap(initializer_list<pair<_Key, _Tp>>, _Compare = _Compare(), _Allocator = _Allocator())
2149 -> multimap<remove_const_t<_Key>, _Tp, _Compare, _Allocator>;
2150
2151template<class _InputIterator, class _Allocator,
Louis Dionne6c7da9a2019-07-19 17:13:39 +00002152 class = _EnableIf<__is_allocator<_Allocator>::value, void>>
Louis Dionned23a5f22019-06-20 19:32:00 +00002153multimap(_InputIterator, _InputIterator, _Allocator)
2154 -> multimap<__iter_key_type<_InputIterator>, __iter_mapped_type<_InputIterator>,
2155 less<__iter_key_type<_InputIterator>>, _Allocator>;
2156
2157template<class _Key, class _Tp, class _Allocator,
Louis Dionne6c7da9a2019-07-19 17:13:39 +00002158 class = _EnableIf<__is_allocator<_Allocator>::value, void>>
Louis Dionned23a5f22019-06-20 19:32:00 +00002159multimap(initializer_list<pair<_Key, _Tp>>, _Allocator)
2160 -> multimap<remove_const_t<_Key>, _Tp, less<remove_const_t<_Key>>, _Allocator>;
2161#endif
2162
Eric Fiselierd06276b2016-03-31 02:15:15 +00002163#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00002164template <class _Key, class _Tp, class _Compare, class _Allocator>
2165multimap<_Key, _Tp, _Compare, _Allocator>::multimap(multimap&& __m, const allocator_type& __a)
Marshall Clow657cbc42016-08-17 05:58:40 +00002166 : __tree_(_VSTD::move(__m.__tree_), typename __base::allocator_type(__a))
Howard Hinnantc51e1022010-05-11 19:42:16 +00002167{
2168 if (__a != __m.get_allocator())
2169 {
2170 const_iterator __e = cend();
2171 while (!__m.empty())
2172 __tree_.__insert_multi(__e.__i_,
Erik Pilkingtond3fe2992018-06-04 20:38:23 +00002173 _VSTD::move(__m.__tree_.remove(__m.begin().__i_)->__value_.__move()));
Howard Hinnantc51e1022010-05-11 19:42:16 +00002174 }
2175}
Eric Fiselierd06276b2016-03-31 02:15:15 +00002176#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00002177
2178template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00002179inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002180bool
2181operator==(const multimap<_Key, _Tp, _Compare, _Allocator>& __x,
2182 const multimap<_Key, _Tp, _Compare, _Allocator>& __y)
2183{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00002184 return __x.size() == __y.size() && _VSTD::equal(__x.begin(), __x.end(), __y.begin());
Howard Hinnantc51e1022010-05-11 19:42:16 +00002185}
2186
2187template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00002188inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002189bool
2190operator< (const multimap<_Key, _Tp, _Compare, _Allocator>& __x,
2191 const multimap<_Key, _Tp, _Compare, _Allocator>& __y)
2192{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00002193 return _VSTD::lexicographical_compare(__x.begin(), __x.end(), __y.begin(), __y.end());
Howard Hinnantc51e1022010-05-11 19:42:16 +00002194}
2195
2196template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00002197inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002198bool
2199operator!=(const multimap<_Key, _Tp, _Compare, _Allocator>& __x,
2200 const multimap<_Key, _Tp, _Compare, _Allocator>& __y)
2201{
2202 return !(__x == __y);
2203}
2204
2205template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00002206inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002207bool
2208operator> (const multimap<_Key, _Tp, _Compare, _Allocator>& __x,
2209 const multimap<_Key, _Tp, _Compare, _Allocator>& __y)
2210{
2211 return __y < __x;
2212}
2213
2214template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00002215inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002216bool
2217operator>=(const multimap<_Key, _Tp, _Compare, _Allocator>& __x,
2218 const multimap<_Key, _Tp, _Compare, _Allocator>& __y)
2219{
2220 return !(__x < __y);
2221}
2222
2223template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00002224inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002225bool
2226operator<=(const multimap<_Key, _Tp, _Compare, _Allocator>& __x,
2227 const multimap<_Key, _Tp, _Compare, _Allocator>& __y)
2228{
2229 return !(__y < __x);
2230}
2231
2232template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00002233inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002234void
2235swap(multimap<_Key, _Tp, _Compare, _Allocator>& __x,
2236 multimap<_Key, _Tp, _Compare, _Allocator>& __y)
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00002237 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
Howard Hinnantc51e1022010-05-11 19:42:16 +00002238{
2239 __x.swap(__y);
2240}
2241
Marshall Clow29b53f22018-12-14 18:49:35 +00002242#if _LIBCPP_STD_VER > 17
Marek Kurdeja98b1412020-05-02 13:58:03 +02002243template <class _Key, class _Tp, class _Compare, class _Allocator,
2244 class _Predicate>
Marshall Clow29b53f22018-12-14 18:49:35 +00002245inline _LIBCPP_INLINE_VISIBILITY
Marek Kurdeja98b1412020-05-02 13:58:03 +02002246 typename multimap<_Key, _Tp, _Compare, _Allocator>::size_type
2247 erase_if(multimap<_Key, _Tp, _Compare, _Allocator>& __c,
2248 _Predicate __pred) {
2249 return __libcpp_erase_if_container(__c, __pred);
2250}
Marshall Clow29b53f22018-12-14 18:49:35 +00002251#endif
2252
Howard Hinnantc51e1022010-05-11 19:42:16 +00002253_LIBCPP_END_NAMESPACE_STD
2254
2255#endif // _LIBCPP_MAP