blob: b6f89bf5ee54dda6192ffb96d7d90cb4e535e6a3 [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>
257 void erase_if(map<Key, T, Compare, Allocator>& c, Predicate pred); // C++20
258
259
Howard Hinnantc51e1022010-05-11 19:42:16 +0000260template <class Key, class T, class Compare = less<Key>,
261 class Allocator = allocator<pair<const Key, T>>>
262class multimap
263{
264public:
265 // types:
266 typedef Key key_type;
267 typedef T mapped_type;
268 typedef pair<const key_type,mapped_type> value_type;
269 typedef Compare key_compare;
270 typedef Allocator allocator_type;
271 typedef typename allocator_type::reference reference;
272 typedef typename allocator_type::const_reference const_reference;
273 typedef typename allocator_type::size_type size_type;
274 typedef typename allocator_type::difference_type difference_type;
275 typedef typename allocator_type::pointer pointer;
276 typedef typename allocator_type::const_pointer const_pointer;
277
278 typedef implementation-defined iterator;
279 typedef implementation-defined const_iterator;
280 typedef std::reverse_iterator<iterator> reverse_iterator;
281 typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
Erik Pilkingtonc37a3d82018-08-01 01:33:38 +0000282 typedef unspecified node_type; // C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000283
284 class value_compare
285 : public binary_function<value_type,value_type,bool>
286 {
287 friend class multimap;
288 protected:
289 key_compare comp;
290 value_compare(key_compare c);
291 public:
292 bool operator()(const value_type& x, const value_type& y) const;
293 };
294
295 // construct/copy/destroy:
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000296 multimap()
297 noexcept(
298 is_nothrow_default_constructible<allocator_type>::value &&
299 is_nothrow_default_constructible<key_compare>::value &&
300 is_nothrow_copy_constructible<key_compare>::value);
301 explicit multimap(const key_compare& comp);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000302 multimap(const key_compare& comp, const allocator_type& a);
303 template <class InputIterator>
304 multimap(InputIterator first, InputIterator last, const key_compare& comp);
305 template <class InputIterator>
306 multimap(InputIterator first, InputIterator last, const key_compare& comp,
307 const allocator_type& a);
308 multimap(const multimap& m);
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000309 multimap(multimap&& m)
310 noexcept(
311 is_nothrow_move_constructible<allocator_type>::value &&
312 is_nothrow_move_constructible<key_compare>::value);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000313 explicit multimap(const allocator_type& a);
314 multimap(const multimap& m, const allocator_type& a);
315 multimap(multimap&& m, const allocator_type& a);
316 multimap(initializer_list<value_type> il, const key_compare& comp = key_compare());
317 multimap(initializer_list<value_type> il, const key_compare& comp,
318 const allocator_type& a);
Marshall Clow300abfb2013-09-11 01:15:47 +0000319 template <class InputIterator>
320 multimap(InputIterator first, InputIterator last, const allocator_type& a)
321 : multimap(first, last, Compare(), a) {} // C++14
322 multimap(initializer_list<value_type> il, const allocator_type& a)
323 : multimap(il, Compare(), a) {} // C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000324 ~multimap();
325
326 multimap& operator=(const multimap& m);
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000327 multimap& operator=(multimap&& m)
328 noexcept(
329 allocator_type::propagate_on_container_move_assignment::value &&
330 is_nothrow_move_assignable<allocator_type>::value &&
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000331 is_nothrow_move_assignable<key_compare>::value);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000332 multimap& operator=(initializer_list<value_type> il);
333
334 // iterators:
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000335 iterator begin() noexcept;
336 const_iterator begin() const noexcept;
337 iterator end() noexcept;
338 const_iterator end() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000339
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000340 reverse_iterator rbegin() noexcept;
341 const_reverse_iterator rbegin() const noexcept;
342 reverse_iterator rend() noexcept;
343 const_reverse_iterator rend() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000344
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000345 const_iterator cbegin() const noexcept;
346 const_iterator cend() const noexcept;
347 const_reverse_iterator crbegin() const noexcept;
348 const_reverse_iterator crend() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000349
350 // capacity:
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000351 bool empty() const noexcept;
352 size_type size() const noexcept;
353 size_type max_size() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000354
355 // modifiers:
356 template <class... Args>
357 iterator emplace(Args&&... args);
358 template <class... Args>
359 iterator emplace_hint(const_iterator position, Args&&... args);
360 iterator insert(const value_type& v);
Marshall Clowd430d022016-01-05 19:32:41 +0000361 iterator insert( value_type&& v); // C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000362 template <class P>
363 iterator insert(P&& p);
364 iterator insert(const_iterator position, const value_type& v);
Marshall Clowd430d022016-01-05 19:32:41 +0000365 iterator insert(const_iterator position, value_type&& v); // C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000366 template <class P>
367 iterator insert(const_iterator position, P&& p);
368 template <class InputIterator>
369 void insert(InputIterator first, InputIterator last);
370 void insert(initializer_list<value_type> il);
371
Erik Pilkingtonc37a3d82018-08-01 01:33:38 +0000372 node_type extract(const_iterator position); // C++17
373 node_type extract(const key_type& x); // C++17
374 iterator insert(node_type&& nh); // C++17
375 iterator insert(const_iterator hint, node_type&& nh); // C++17
376
Howard Hinnantc51e1022010-05-11 19:42:16 +0000377 iterator erase(const_iterator position);
Marshall Clow22ea5b82015-05-10 13:35:00 +0000378 iterator erase(iterator position); // C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000379 size_type erase(const key_type& k);
380 iterator erase(const_iterator first, const_iterator last);
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000381 void clear() noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000382
Erik Pilkington82a65ad2018-10-31 17:31:35 +0000383 template<class C2>
384 void merge(multimap<Key, T, C2, Allocator>& source); // C++17
385 template<class C2>
386 void merge(multimap<Key, T, C2, Allocator>&& source); // C++17
387 template<class C2>
388 void merge(map<Key, T, C2, Allocator>& source); // C++17
389 template<class C2>
390 void merge(map<Key, T, C2, Allocator>&& source); // C++17
391
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000392 void swap(multimap& m)
Marshall Clow8982dcd2015-07-13 20:04:56 +0000393 noexcept(allocator_traits<allocator_type>::is_always_equal::value &&
Eric Fiselier6bfed252016-04-21 23:38:59 +0000394 is_nothrow_swappable<key_compare>::value); // C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000395
396 // observers:
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000397 allocator_type get_allocator() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000398 key_compare key_comp() const;
399 value_compare value_comp() const;
400
401 // map operations:
402 iterator find(const key_type& k);
403 const_iterator find(const key_type& k) const;
Marshall Clowebb57322013-08-13 22:18:47 +0000404 template<typename K>
405 iterator find(const K& x); // C++14
406 template<typename K>
407 const_iterator find(const K& x) const; // C++14
408 template<typename K>
Marshall Clowe6a5f522014-08-24 23:54:16 +0000409 size_type count(const K& x) const; // C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000410 size_type count(const key_type& k) const;
Zoe Carver3ffbab12019-07-16 03:21:01 +0000411 bool contains(const key_type& x) const; // C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000412 iterator lower_bound(const key_type& k);
413 const_iterator lower_bound(const key_type& k) const;
Marshall Clowebb57322013-08-13 22:18:47 +0000414 template<typename K>
415 iterator lower_bound(const K& x); // C++14
416 template<typename K>
417 const_iterator lower_bound(const K& x) const; // C++14
418
Howard Hinnantc51e1022010-05-11 19:42:16 +0000419 iterator upper_bound(const key_type& k);
420 const_iterator upper_bound(const key_type& k) const;
Marshall Clowebb57322013-08-13 22:18:47 +0000421 template<typename K>
422 iterator upper_bound(const K& x); // C++14
423 template<typename K>
424 const_iterator upper_bound(const K& x) const; // C++14
425
Howard Hinnantc51e1022010-05-11 19:42:16 +0000426 pair<iterator,iterator> equal_range(const key_type& k);
427 pair<const_iterator,const_iterator> equal_range(const key_type& k) const;
Marshall Clowebb57322013-08-13 22:18:47 +0000428 template<typename K>
429 pair<iterator,iterator> equal_range(const K& x); // C++14
430 template<typename K>
431 pair<const_iterator,const_iterator> equal_range(const K& x) const; // C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000432};
433
434template <class Key, class T, class Compare, class Allocator>
435bool
436operator==(const multimap<Key, T, Compare, Allocator>& x,
437 const multimap<Key, T, Compare, Allocator>& y);
438
439template <class Key, class T, class Compare, class Allocator>
440bool
441operator< (const multimap<Key, T, Compare, Allocator>& x,
442 const multimap<Key, T, Compare, Allocator>& y);
443
444template <class Key, class T, class Compare, class Allocator>
445bool
446operator!=(const multimap<Key, T, Compare, Allocator>& x,
447 const multimap<Key, T, Compare, Allocator>& y);
448
449template <class Key, class T, class Compare, class Allocator>
450bool
451operator> (const multimap<Key, T, Compare, Allocator>& x,
452 const multimap<Key, T, Compare, Allocator>& y);
453
454template <class Key, class T, class Compare, class Allocator>
455bool
456operator>=(const multimap<Key, T, Compare, Allocator>& x,
457 const multimap<Key, T, Compare, Allocator>& y);
458
459template <class Key, class T, class Compare, class Allocator>
460bool
461operator<=(const multimap<Key, T, Compare, Allocator>& x,
462 const multimap<Key, T, Compare, Allocator>& y);
463
464// specialized algorithms:
465template <class Key, class T, class Compare, class Allocator>
466void
467swap(multimap<Key, T, Compare, Allocator>& x,
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000468 multimap<Key, T, Compare, Allocator>& y)
469 noexcept(noexcept(x.swap(y)));
Howard Hinnantc51e1022010-05-11 19:42:16 +0000470
Marshall Clow29b53f22018-12-14 18:49:35 +0000471template <class Key, class T, class Compare, class Allocator, class Predicate>
472 void erase_if(multimap<Key, T, Compare, Allocator>& c, Predicate pred); // C++20
473
Howard Hinnantc51e1022010-05-11 19:42:16 +0000474} // std
475
476*/
477
478#include <__config>
479#include <__tree>
Erik Pilkingtonc37a3d82018-08-01 01:33:38 +0000480#include <__node_handle>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000481#include <iterator>
482#include <memory>
483#include <utility>
484#include <functional>
485#include <initializer_list>
Eric Fiselierf7394302015-06-13 07:08:02 +0000486#include <type_traits>
Marshall Clow0a1e7502018-09-12 19:41:40 +0000487#include <version>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000488
Howard Hinnantaaaa52b2011-10-17 20:05:10 +0000489#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000490#pragma GCC system_header
Howard Hinnantaaaa52b2011-10-17 20:05:10 +0000491#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000492
493_LIBCPP_BEGIN_NAMESPACE_STD
494
Louis Dionne878a3a82018-12-06 21:46:17 +0000495template <class _Key, class _CP, class _Compare,
496 bool = is_empty<_Compare>::value && !__libcpp_is_final<_Compare>::value>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000497class __map_value_compare
498 : private _Compare
499{
Howard Hinnantc51e1022010-05-11 19:42:16 +0000500public:
Howard Hinnant756c69b2010-09-22 16:48:34 +0000501 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000502 __map_value_compare()
503 _NOEXCEPT_(is_nothrow_default_constructible<_Compare>::value)
504 : _Compare() {}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000505 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000506 __map_value_compare(_Compare c)
507 _NOEXCEPT_(is_nothrow_copy_constructible<_Compare>::value)
508 : _Compare(c) {}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000509 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000510 const _Compare& key_comp() const _NOEXCEPT {return *this;}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000511 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000512 bool operator()(const _CP& __x, const _CP& __y) const
Erik Pilkingtond3fe2992018-06-04 20:38:23 +0000513 {return static_cast<const _Compare&>(*this)(__x.__get_value().first, __y.__get_value().first);}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000514 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000515 bool operator()(const _CP& __x, const _Key& __y) const
Erik Pilkingtond3fe2992018-06-04 20:38:23 +0000516 {return static_cast<const _Compare&>(*this)(__x.__get_value().first, __y);}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000517 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000518 bool operator()(const _Key& __x, const _CP& __y) const
Erik Pilkingtond3fe2992018-06-04 20:38:23 +0000519 {return static_cast<const _Compare&>(*this)(__x, __y.__get_value().first);}
Marshall Clow8982dcd2015-07-13 20:04:56 +0000520 void swap(__map_value_compare&__y)
521 _NOEXCEPT_(__is_nothrow_swappable<_Compare>::value)
522 {
Eric Fiselier68b5f0b2017-04-13 00:34:24 +0000523 using _VSTD::swap;
524 swap(static_cast<_Compare&>(*this), static_cast<_Compare&>(__y));
Marshall Clow8982dcd2015-07-13 20:04:56 +0000525 }
Marshall Clowebb57322013-08-13 22:18:47 +0000526
527#if _LIBCPP_STD_VER > 11
528 template <typename _K2>
529 _LIBCPP_INLINE_VISIBILITY
530 typename enable_if<__is_transparent<_Compare, _K2>::value, bool>::type
531 operator () ( const _K2& __x, const _CP& __y ) const
Erik Pilkingtond3fe2992018-06-04 20:38:23 +0000532 {return static_cast<const _Compare&>(*this) (__x, __y.__get_value().first);}
Marshall Clowebb57322013-08-13 22:18:47 +0000533
534 template <typename _K2>
535 _LIBCPP_INLINE_VISIBILITY
536 typename enable_if<__is_transparent<_Compare, _K2>::value, bool>::type
537 operator () (const _CP& __x, const _K2& __y) const
Erik Pilkingtond3fe2992018-06-04 20:38:23 +0000538 {return static_cast<const _Compare&>(*this) (__x.__get_value().first, __y);}
Marshall Clowebb57322013-08-13 22:18:47 +0000539#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000540};
541
Howard Hinnant90b91592013-07-05 18:06:00 +0000542template <class _Key, class _CP, class _Compare>
543class __map_value_compare<_Key, _CP, _Compare, false>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000544{
545 _Compare comp;
546
Howard Hinnantc51e1022010-05-11 19:42:16 +0000547public:
Howard Hinnant756c69b2010-09-22 16:48:34 +0000548 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000549 __map_value_compare()
550 _NOEXCEPT_(is_nothrow_default_constructible<_Compare>::value)
551 : comp() {}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000552 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000553 __map_value_compare(_Compare c)
554 _NOEXCEPT_(is_nothrow_copy_constructible<_Compare>::value)
555 : comp(c) {}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000556 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000557 const _Compare& key_comp() const _NOEXCEPT {return comp;}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000558
Howard Hinnant756c69b2010-09-22 16:48:34 +0000559 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000560 bool operator()(const _CP& __x, const _CP& __y) const
Erik Pilkingtond3fe2992018-06-04 20:38:23 +0000561 {return comp(__x.__get_value().first, __y.__get_value().first);}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000562 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000563 bool operator()(const _CP& __x, const _Key& __y) const
Erik Pilkingtond3fe2992018-06-04 20:38:23 +0000564 {return comp(__x.__get_value().first, __y);}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000565 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000566 bool operator()(const _Key& __x, const _CP& __y) const
Erik Pilkingtond3fe2992018-06-04 20:38:23 +0000567 {return comp(__x, __y.__get_value().first);}
Marshall Clow8982dcd2015-07-13 20:04:56 +0000568 void swap(__map_value_compare&__y)
569 _NOEXCEPT_(__is_nothrow_swappable<_Compare>::value)
570 {
571 using _VSTD::swap;
572 swap(comp, __y.comp);
573 }
Eric Fiseliercf8c0212017-01-05 06:06:18 +0000574
Marshall Clowebb57322013-08-13 22:18:47 +0000575#if _LIBCPP_STD_VER > 11
576 template <typename _K2>
577 _LIBCPP_INLINE_VISIBILITY
578 typename enable_if<__is_transparent<_Compare, _K2>::value, bool>::type
579 operator () ( const _K2& __x, const _CP& __y ) const
Erik Pilkingtond3fe2992018-06-04 20:38:23 +0000580 {return comp (__x, __y.__get_value().first);}
Marshall Clowebb57322013-08-13 22:18:47 +0000581
582 template <typename _K2>
583 _LIBCPP_INLINE_VISIBILITY
584 typename enable_if<__is_transparent<_Compare, _K2>::value, bool>::type
585 operator () (const _CP& __x, const _K2& __y) const
Erik Pilkingtond3fe2992018-06-04 20:38:23 +0000586 {return comp (__x.__get_value().first, __y);}
Marshall Clowebb57322013-08-13 22:18:47 +0000587#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000588};
589
Marshall Clow8982dcd2015-07-13 20:04:56 +0000590template <class _Key, class _CP, class _Compare, bool __b>
591inline _LIBCPP_INLINE_VISIBILITY
592void
593swap(__map_value_compare<_Key, _CP, _Compare, __b>& __x,
594 __map_value_compare<_Key, _CP, _Compare, __b>& __y)
595 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
596{
597 __x.swap(__y);
598}
599
Howard Hinnantc51e1022010-05-11 19:42:16 +0000600template <class _Allocator>
601class __map_node_destructor
602{
603 typedef _Allocator allocator_type;
604 typedef allocator_traits<allocator_type> __alloc_traits;
Eric Fiseliera00b4842016-02-20 05:28:30 +0000605
Howard Hinnantc51e1022010-05-11 19:42:16 +0000606public:
607 typedef typename __alloc_traits::pointer pointer;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000608
Eric Fiseliera00b4842016-02-20 05:28:30 +0000609private:
Howard Hinnantc51e1022010-05-11 19:42:16 +0000610 allocator_type& __na_;
611
612 __map_node_destructor& operator=(const __map_node_destructor&);
613
614public:
615 bool __first_constructed;
616 bool __second_constructed;
617
Howard Hinnant756c69b2010-09-22 16:48:34 +0000618 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000619 explicit __map_node_destructor(allocator_type& __na) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +0000620 : __na_(__na),
621 __first_constructed(false),
622 __second_constructed(false)
623 {}
624
Eric Fiseliera85b1282017-04-18 21:08:06 +0000625#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant756c69b2010-09-22 16:48:34 +0000626 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000627 __map_node_destructor(__tree_node_destructor<allocator_type>&& __x) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +0000628 : __na_(__x.__na_),
629 __first_constructed(__x.__value_constructed),
630 __second_constructed(__x.__value_constructed)
631 {
632 __x.__value_constructed = false;
633 }
Eric Fiseliera85b1282017-04-18 21:08:06 +0000634#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000635
Howard Hinnant756c69b2010-09-22 16:48:34 +0000636 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000637 void operator()(pointer __p) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +0000638 {
639 if (__second_constructed)
Erik Pilkingtond3fe2992018-06-04 20:38:23 +0000640 __alloc_traits::destroy(__na_, _VSTD::addressof(__p->__value_.__get_value().second));
Howard Hinnantc51e1022010-05-11 19:42:16 +0000641 if (__first_constructed)
Erik Pilkingtond3fe2992018-06-04 20:38:23 +0000642 __alloc_traits::destroy(__na_, _VSTD::addressof(__p->__value_.__get_value().first));
Howard Hinnantc51e1022010-05-11 19:42:16 +0000643 if (__p)
644 __alloc_traits::deallocate(__na_, __p, 1);
645 }
646};
647
Howard Hinnant944510a2011-06-14 19:58:17 +0000648template <class _Key, class _Tp, class _Compare, class _Allocator>
649 class map;
650template <class _Key, class _Tp, class _Compare, class _Allocator>
651 class multimap;
652template <class _TreeIterator> class __map_const_iterator;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000653
Eric Fiseliera00b4842016-02-20 05:28:30 +0000654#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant89f8b792013-09-30 19:08:22 +0000655
656template <class _Key, class _Tp>
Erik Pilkingtond3fe2992018-06-04 20:38:23 +0000657struct __value_type
Howard Hinnant89f8b792013-09-30 19:08:22 +0000658{
659 typedef _Key key_type;
660 typedef _Tp mapped_type;
661 typedef pair<const key_type, mapped_type> value_type;
Erik Pilkingtond3fe2992018-06-04 20:38:23 +0000662 typedef pair<key_type&, mapped_type&> __nc_ref_pair_type;
663 typedef pair<key_type&&, mapped_type&&> __nc_rref_pair_type;
Howard Hinnant89f8b792013-09-30 19:08:22 +0000664
Erik Pilkingtond3fe2992018-06-04 20:38:23 +0000665private:
Howard Hinnant89f8b792013-09-30 19:08:22 +0000666 value_type __cc;
Erik Pilkingtond3fe2992018-06-04 20:38:23 +0000667
668public:
669 _LIBCPP_INLINE_VISIBILITY
670 value_type& __get_value()
671 {
672#if _LIBCPP_STD_VER > 14
673 return *_VSTD::launder(_VSTD::addressof(__cc));
674#else
675 return __cc;
676#endif
677 }
678
679 _LIBCPP_INLINE_VISIBILITY
680 const value_type& __get_value() const
681 {
682#if _LIBCPP_STD_VER > 14
683 return *_VSTD::launder(_VSTD::addressof(__cc));
684#else
685 return __cc;
686#endif
687 }
688
689 _LIBCPP_INLINE_VISIBILITY
690 __nc_ref_pair_type __ref()
691 {
692 value_type& __v = __get_value();
693 return __nc_ref_pair_type(const_cast<key_type&>(__v.first), __v.second);
694 }
695
696 _LIBCPP_INLINE_VISIBILITY
697 __nc_rref_pair_type __move()
698 {
699 value_type& __v = __get_value();
700 return __nc_rref_pair_type(
701 _VSTD::move(const_cast<key_type&>(__v.first)),
702 _VSTD::move(__v.second));
703 }
Howard Hinnant89f8b792013-09-30 19:08:22 +0000704
Howard Hinnant89f8b792013-09-30 19:08:22 +0000705 _LIBCPP_INLINE_VISIBILITY
706 __value_type& operator=(const __value_type& __v)
Erik Pilkingtond3fe2992018-06-04 20:38:23 +0000707 {
708 __ref() = __v.__get_value();
709 return *this;
710 }
Howard Hinnant89f8b792013-09-30 19:08:22 +0000711
712 _LIBCPP_INLINE_VISIBILITY
713 __value_type& operator=(__value_type&& __v)
Erik Pilkingtond3fe2992018-06-04 20:38:23 +0000714 {
715 __ref() = __v.__move();
716 return *this;
717 }
Howard Hinnant89f8b792013-09-30 19:08:22 +0000718
Eric Fiselierd06276b2016-03-31 02:15:15 +0000719 template <class _ValueTp,
720 class = typename enable_if<
721 __is_same_uncvref<_ValueTp, value_type>::value
722 >::type
723 >
Howard Hinnant89f8b792013-09-30 19:08:22 +0000724 _LIBCPP_INLINE_VISIBILITY
Erik Pilkingtond3fe2992018-06-04 20:38:23 +0000725 __value_type& operator=(_ValueTp&& __v)
726 {
727 __ref() = _VSTD::forward<_ValueTp>(__v);
728 return *this;
Eric Fiselierd06276b2016-03-31 02:15:15 +0000729 }
730
731private:
732 __value_type() _LIBCPP_EQUAL_DELETE;
733 ~__value_type() _LIBCPP_EQUAL_DELETE;
734 __value_type(const __value_type& __v) _LIBCPP_EQUAL_DELETE;
735 __value_type(__value_type&& __v) _LIBCPP_EQUAL_DELETE;
Howard Hinnant89f8b792013-09-30 19:08:22 +0000736};
737
738#else
739
740template <class _Key, class _Tp>
741struct __value_type
742{
743 typedef _Key key_type;
744 typedef _Tp mapped_type;
745 typedef pair<const key_type, mapped_type> value_type;
746
Erik Pilkingtond3fe2992018-06-04 20:38:23 +0000747private:
Howard Hinnant89f8b792013-09-30 19:08:22 +0000748 value_type __cc;
749
Erik Pilkingtond3fe2992018-06-04 20:38:23 +0000750public:
751 _LIBCPP_INLINE_VISIBILITY
752 value_type& __get_value() { return __cc; }
753 _LIBCPP_INLINE_VISIBILITY
754 const value_type& __get_value() const { return __cc; }
755
Eric Fiselierd06276b2016-03-31 02:15:15 +0000756private:
757 __value_type();
758 __value_type(__value_type const&);
759 __value_type& operator=(__value_type const&);
760 ~__value_type();
Howard Hinnant89f8b792013-09-30 19:08:22 +0000761};
762
Eric Fiseliera85b1282017-04-18 21:08:06 +0000763#endif // _LIBCPP_CXX03_LANG
Howard Hinnant89f8b792013-09-30 19:08:22 +0000764
Eric Fiselier44f9fd02015-03-03 20:10:01 +0000765template <class _Tp>
766struct __extract_key_value_types;
767
768template <class _Key, class _Tp>
769struct __extract_key_value_types<__value_type<_Key, _Tp> >
770{
771 typedef _Key const __key_type;
772 typedef _Tp __mapped_type;
773};
774
Howard Hinnantc51e1022010-05-11 19:42:16 +0000775template <class _TreeIterator>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000776class _LIBCPP_TEMPLATE_VIS __map_iterator
Howard Hinnantc51e1022010-05-11 19:42:16 +0000777{
Eric Fiseliera00b4842016-02-20 05:28:30 +0000778 typedef typename _TreeIterator::_NodeTypes _NodeTypes;
779 typedef typename _TreeIterator::__pointer_traits __pointer_traits;
780
Howard Hinnantc51e1022010-05-11 19:42:16 +0000781 _TreeIterator __i_;
782
Howard Hinnantc51e1022010-05-11 19:42:16 +0000783public:
784 typedef bidirectional_iterator_tag iterator_category;
Eric Fiseliera00b4842016-02-20 05:28:30 +0000785 typedef typename _NodeTypes::__map_value_type value_type;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000786 typedef typename _TreeIterator::difference_type difference_type;
787 typedef value_type& reference;
Eric Fiseliera00b4842016-02-20 05:28:30 +0000788 typedef typename _NodeTypes::__map_value_type_pointer pointer;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000789
Howard Hinnant756c69b2010-09-22 16:48:34 +0000790 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000791 __map_iterator() _NOEXCEPT {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000792
Howard Hinnant756c69b2010-09-22 16:48:34 +0000793 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000794 __map_iterator(_TreeIterator __i) _NOEXCEPT : __i_(__i) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000795
Howard Hinnant756c69b2010-09-22 16:48:34 +0000796 _LIBCPP_INLINE_VISIBILITY
Erik Pilkingtond3fe2992018-06-04 20:38:23 +0000797 reference operator*() const {return __i_->__get_value();}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000798 _LIBCPP_INLINE_VISIBILITY
Erik Pilkingtond3fe2992018-06-04 20:38:23 +0000799 pointer operator->() const {return pointer_traits<pointer>::pointer_to(__i_->__get_value());}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000800
Howard Hinnant756c69b2010-09-22 16:48:34 +0000801 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000802 __map_iterator& operator++() {++__i_; return *this;}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000803 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000804 __map_iterator operator++(int)
805 {
806 __map_iterator __t(*this);
807 ++(*this);
808 return __t;
809 }
810
Howard Hinnant756c69b2010-09-22 16:48:34 +0000811 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000812 __map_iterator& operator--() {--__i_; return *this;}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000813 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000814 __map_iterator operator--(int)
815 {
816 __map_iterator __t(*this);
817 --(*this);
818 return __t;
819 }
820
Howard Hinnant756c69b2010-09-22 16:48:34 +0000821 friend _LIBCPP_INLINE_VISIBILITY
822 bool operator==(const __map_iterator& __x, const __map_iterator& __y)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000823 {return __x.__i_ == __y.__i_;}
Eric Fiseliercf8c0212017-01-05 06:06:18 +0000824 friend
Howard Hinnant756c69b2010-09-22 16:48:34 +0000825 _LIBCPP_INLINE_VISIBILITY
826 bool operator!=(const __map_iterator& __x, const __map_iterator& __y)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000827 {return __x.__i_ != __y.__i_;}
828
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000829 template <class, class, class, class> friend class _LIBCPP_TEMPLATE_VIS map;
830 template <class, class, class, class> friend class _LIBCPP_TEMPLATE_VIS multimap;
831 template <class> friend class _LIBCPP_TEMPLATE_VIS __map_const_iterator;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000832};
833
834template <class _TreeIterator>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000835class _LIBCPP_TEMPLATE_VIS __map_const_iterator
Howard Hinnantc51e1022010-05-11 19:42:16 +0000836{
Eric Fiseliera00b4842016-02-20 05:28:30 +0000837 typedef typename _TreeIterator::_NodeTypes _NodeTypes;
838 typedef typename _TreeIterator::__pointer_traits __pointer_traits;
839
Howard Hinnantc51e1022010-05-11 19:42:16 +0000840 _TreeIterator __i_;
841
Howard Hinnantc51e1022010-05-11 19:42:16 +0000842public:
843 typedef bidirectional_iterator_tag iterator_category;
Eric Fiseliera00b4842016-02-20 05:28:30 +0000844 typedef typename _NodeTypes::__map_value_type value_type;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000845 typedef typename _TreeIterator::difference_type difference_type;
846 typedef const value_type& reference;
Eric Fiseliera00b4842016-02-20 05:28:30 +0000847 typedef typename _NodeTypes::__const_map_value_type_pointer pointer;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000848
Howard Hinnant756c69b2010-09-22 16:48:34 +0000849 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000850 __map_const_iterator() _NOEXCEPT {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000851
Howard Hinnant756c69b2010-09-22 16:48:34 +0000852 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000853 __map_const_iterator(_TreeIterator __i) _NOEXCEPT : __i_(__i) {}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000854 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier44f9fd02015-03-03 20:10:01 +0000855 __map_const_iterator(__map_iterator<
856 typename _TreeIterator::__non_const_iterator> __i) _NOEXCEPT
857 : __i_(__i.__i_) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000858
Howard Hinnant756c69b2010-09-22 16:48:34 +0000859 _LIBCPP_INLINE_VISIBILITY
Erik Pilkingtond3fe2992018-06-04 20:38:23 +0000860 reference operator*() const {return __i_->__get_value();}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000861 _LIBCPP_INLINE_VISIBILITY
Erik Pilkingtond3fe2992018-06-04 20:38:23 +0000862 pointer operator->() const {return pointer_traits<pointer>::pointer_to(__i_->__get_value());}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000863
Howard Hinnant756c69b2010-09-22 16:48:34 +0000864 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000865 __map_const_iterator& operator++() {++__i_; return *this;}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000866 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000867 __map_const_iterator operator++(int)
868 {
869 __map_const_iterator __t(*this);
870 ++(*this);
871 return __t;
872 }
873
Howard Hinnant756c69b2010-09-22 16:48:34 +0000874 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000875 __map_const_iterator& operator--() {--__i_; return *this;}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000876 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000877 __map_const_iterator operator--(int)
878 {
879 __map_const_iterator __t(*this);
880 --(*this);
881 return __t;
882 }
883
Howard Hinnant756c69b2010-09-22 16:48:34 +0000884 friend _LIBCPP_INLINE_VISIBILITY
885 bool operator==(const __map_const_iterator& __x, const __map_const_iterator& __y)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000886 {return __x.__i_ == __y.__i_;}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000887 friend _LIBCPP_INLINE_VISIBILITY
888 bool operator!=(const __map_const_iterator& __x, const __map_const_iterator& __y)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000889 {return __x.__i_ != __y.__i_;}
890
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000891 template <class, class, class, class> friend class _LIBCPP_TEMPLATE_VIS map;
892 template <class, class, class, class> friend class _LIBCPP_TEMPLATE_VIS multimap;
893 template <class, class, class> friend class _LIBCPP_TEMPLATE_VIS __tree_const_iterator;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000894};
895
896template <class _Key, class _Tp, class _Compare = less<_Key>,
897 class _Allocator = allocator<pair<const _Key, _Tp> > >
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000898class _LIBCPP_TEMPLATE_VIS map
Howard Hinnantc51e1022010-05-11 19:42:16 +0000899{
900public:
901 // types:
902 typedef _Key key_type;
903 typedef _Tp mapped_type;
904 typedef pair<const key_type, mapped_type> value_type;
Louis Dionned23a5f22019-06-20 19:32:00 +0000905 typedef typename __identity<_Compare>::type key_compare;
906 typedef typename __identity<_Allocator>::type allocator_type;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000907 typedef value_type& reference;
908 typedef const value_type& const_reference;
909
Marshall Clow5128cf32015-11-26 01:24:04 +0000910 static_assert((is_same<typename allocator_type::value_type, value_type>::value),
911 "Allocator::value_type must be same type as value_type");
912
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000913 class _LIBCPP_TEMPLATE_VIS value_compare
Howard Hinnantc51e1022010-05-11 19:42:16 +0000914 : public binary_function<value_type, value_type, bool>
915 {
916 friend class map;
917 protected:
918 key_compare comp;
919
Howard Hinnant756c69b2010-09-22 16:48:34 +0000920 _LIBCPP_INLINE_VISIBILITY value_compare(key_compare c) : comp(c) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000921 public:
Howard Hinnant756c69b2010-09-22 16:48:34 +0000922 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000923 bool operator()(const value_type& __x, const value_type& __y) const
924 {return comp(__x.first, __y.first);}
925 };
926
927private:
Howard Hinnant2d0046b2013-06-19 21:29:40 +0000928
Howard Hinnant89f8b792013-09-30 19:08:22 +0000929 typedef _VSTD::__value_type<key_type, mapped_type> __value_type;
Howard Hinnant90b91592013-07-05 18:06:00 +0000930 typedef __map_value_compare<key_type, __value_type, key_compare> __vc;
Marshall Clow940e01c2015-04-07 05:21:38 +0000931 typedef typename __rebind_alloc_helper<allocator_traits<allocator_type>,
932 __value_type>::type __allocator_type;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000933 typedef __tree<__value_type, __vc, __allocator_type> __base;
934 typedef typename __base::__node_traits __node_traits;
935 typedef allocator_traits<allocator_type> __alloc_traits;
936
937 __base __tree_;
938
939public:
940 typedef typename __alloc_traits::pointer pointer;
941 typedef typename __alloc_traits::const_pointer const_pointer;
942 typedef typename __alloc_traits::size_type size_type;
943 typedef typename __alloc_traits::difference_type difference_type;
Eric Fiselier44f9fd02015-03-03 20:10:01 +0000944 typedef __map_iterator<typename __base::iterator> iterator;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000945 typedef __map_const_iterator<typename __base::const_iterator> const_iterator;
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000946 typedef _VSTD::reverse_iterator<iterator> reverse_iterator;
947 typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000948
Erik Pilkingtonc37a3d82018-08-01 01:33:38 +0000949#if _LIBCPP_STD_VER > 14
950 typedef __map_node_handle<typename __base::__node, allocator_type> node_type;
951 typedef __insert_return_type<iterator, node_type> insert_return_type;
952#endif
953
Erik Pilkington82a65ad2018-10-31 17:31:35 +0000954 template <class _Key2, class _Value2, class _Comp2, class _Alloc2>
955 friend class _LIBCPP_TEMPLATE_VIS map;
956 template <class _Key2, class _Value2, class _Comp2, class _Alloc2>
957 friend class _LIBCPP_TEMPLATE_VIS multimap;
958
Howard Hinnant756c69b2010-09-22 16:48:34 +0000959 _LIBCPP_INLINE_VISIBILITY
Marshall Clow7086a5a2014-03-10 04:50:10 +0000960 map()
961 _NOEXCEPT_(
962 is_nothrow_default_constructible<allocator_type>::value &&
963 is_nothrow_default_constructible<key_compare>::value &&
964 is_nothrow_copy_constructible<key_compare>::value)
965 : __tree_(__vc(key_compare())) {}
966
967 _LIBCPP_INLINE_VISIBILITY
968 explicit map(const key_compare& __comp)
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000969 _NOEXCEPT_(
970 is_nothrow_default_constructible<allocator_type>::value &&
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000971 is_nothrow_copy_constructible<key_compare>::value)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000972 : __tree_(__vc(__comp)) {}
973
Howard Hinnant756c69b2010-09-22 16:48:34 +0000974 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000975 explicit map(const key_compare& __comp, const allocator_type& __a)
Marshall Clow657cbc42016-08-17 05:58:40 +0000976 : __tree_(__vc(__comp), typename __base::allocator_type(__a)) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000977
978 template <class _InputIterator>
Howard Hinnant756c69b2010-09-22 16:48:34 +0000979 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000980 map(_InputIterator __f, _InputIterator __l,
981 const key_compare& __comp = key_compare())
982 : __tree_(__vc(__comp))
983 {
984 insert(__f, __l);
985 }
986
987 template <class _InputIterator>
Howard Hinnant756c69b2010-09-22 16:48:34 +0000988 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000989 map(_InputIterator __f, _InputIterator __l,
990 const key_compare& __comp, const allocator_type& __a)
Marshall Clow657cbc42016-08-17 05:58:40 +0000991 : __tree_(__vc(__comp), typename __base::allocator_type(__a))
Howard Hinnantc51e1022010-05-11 19:42:16 +0000992 {
993 insert(__f, __l);
994 }
995
Marshall Clow300abfb2013-09-11 01:15:47 +0000996#if _LIBCPP_STD_VER > 11
997 template <class _InputIterator>
Eric Fiseliercf8c0212017-01-05 06:06:18 +0000998 _LIBCPP_INLINE_VISIBILITY
Marshall Clow300abfb2013-09-11 01:15:47 +0000999 map(_InputIterator __f, _InputIterator __l, const allocator_type& __a)
1000 : map(__f, __l, key_compare(), __a) {}
1001#endif
1002
Howard Hinnant756c69b2010-09-22 16:48:34 +00001003 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001004 map(const map& __m)
1005 : __tree_(__m.__tree_)
1006 {
1007 insert(__m.begin(), __m.end());
1008 }
1009
Howard Hinnantd3a657f2011-07-01 19:24:36 +00001010 _LIBCPP_INLINE_VISIBILITY
1011 map& operator=(const map& __m)
1012 {
Marshall Clow476d3f42016-07-18 13:19:00 +00001013#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantd3a657f2011-07-01 19:24:36 +00001014 __tree_ = __m.__tree_;
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001015#else
Marshall Clowdb3cfcb2014-02-08 04:03:14 +00001016 if (this != &__m) {
1017 __tree_.clear();
1018 __tree_.value_comp() = __m.__tree_.value_comp();
1019 __tree_.__copy_assign_alloc(__m.__tree_);
1020 insert(__m.begin(), __m.end());
1021 }
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001022#endif
Howard Hinnantd3a657f2011-07-01 19:24:36 +00001023 return *this;
1024 }
1025
Eric Fiseliera85b1282017-04-18 21:08:06 +00001026#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001027
Howard Hinnant756c69b2010-09-22 16:48:34 +00001028 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001029 map(map&& __m)
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001030 _NOEXCEPT_(is_nothrow_move_constructible<__base>::value)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001031 : __tree_(_VSTD::move(__m.__tree_))
Howard Hinnantc51e1022010-05-11 19:42:16 +00001032 {
1033 }
1034
1035 map(map&& __m, const allocator_type& __a);
1036
Howard Hinnant756c69b2010-09-22 16:48:34 +00001037 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant33711792011-08-12 21:56:02 +00001038 map& operator=(map&& __m)
1039 _NOEXCEPT_(is_nothrow_move_assignable<__base>::value)
1040 {
1041 __tree_ = _VSTD::move(__m.__tree_);
1042 return *this;
1043 }
1044
Howard Hinnant33711792011-08-12 21:56:02 +00001045 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001046 map(initializer_list<value_type> __il, const key_compare& __comp = key_compare())
1047 : __tree_(__vc(__comp))
1048 {
1049 insert(__il.begin(), __il.end());
1050 }
1051
Howard Hinnant756c69b2010-09-22 16:48:34 +00001052 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001053 map(initializer_list<value_type> __il, const key_compare& __comp, const allocator_type& __a)
Marshall Clow657cbc42016-08-17 05:58:40 +00001054 : __tree_(__vc(__comp), typename __base::allocator_type(__a))
Howard Hinnantc51e1022010-05-11 19:42:16 +00001055 {
1056 insert(__il.begin(), __il.end());
1057 }
1058
Marshall Clow300abfb2013-09-11 01:15:47 +00001059#if _LIBCPP_STD_VER > 11
Eric Fiseliercf8c0212017-01-05 06:06:18 +00001060 _LIBCPP_INLINE_VISIBILITY
Marshall Clow300abfb2013-09-11 01:15:47 +00001061 map(initializer_list<value_type> __il, const allocator_type& __a)
1062 : map(__il, key_compare(), __a) {}
1063#endif
1064
Howard Hinnant756c69b2010-09-22 16:48:34 +00001065 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001066 map& operator=(initializer_list<value_type> __il)
1067 {
1068 __tree_.__assign_unique(__il.begin(), __il.end());
1069 return *this;
1070 }
1071
Eric Fiseliera85b1282017-04-18 21:08:06 +00001072#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001073
Howard Hinnant756c69b2010-09-22 16:48:34 +00001074 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001075 explicit map(const allocator_type& __a)
Marshall Clow657cbc42016-08-17 05:58:40 +00001076 : __tree_(typename __base::allocator_type(__a))
Howard Hinnantc51e1022010-05-11 19:42:16 +00001077 {
1078 }
1079
Howard Hinnant756c69b2010-09-22 16:48:34 +00001080 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001081 map(const map& __m, const allocator_type& __a)
Marshall Clow657cbc42016-08-17 05:58:40 +00001082 : __tree_(__m.__tree_.value_comp(), typename __base::allocator_type(__a))
Howard Hinnantc51e1022010-05-11 19:42:16 +00001083 {
1084 insert(__m.begin(), __m.end());
1085 }
1086
Howard Hinnant756c69b2010-09-22 16:48:34 +00001087 _LIBCPP_INLINE_VISIBILITY
Louis Dionne69c42c02019-04-11 16:14:56 +00001088 ~map() {
1089 static_assert(sizeof(__diagnose_non_const_comparator<_Key, _Compare>()), "");
1090 }
1091
1092 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001093 iterator begin() _NOEXCEPT {return __tree_.begin();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001094 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001095 const_iterator begin() const _NOEXCEPT {return __tree_.begin();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001096 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001097 iterator end() _NOEXCEPT {return __tree_.end();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001098 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001099 const_iterator end() const _NOEXCEPT {return __tree_.end();}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001100
Howard Hinnant756c69b2010-09-22 16:48:34 +00001101 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001102 reverse_iterator rbegin() _NOEXCEPT {return reverse_iterator(end());}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001103 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001104 const_reverse_iterator rbegin() const _NOEXCEPT
1105 {return const_reverse_iterator(end());}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001106 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001107 reverse_iterator rend() _NOEXCEPT
1108 {return reverse_iterator(begin());}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001109 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001110 const_reverse_iterator rend() const _NOEXCEPT
1111 {return const_reverse_iterator(begin());}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001112
Howard Hinnant756c69b2010-09-22 16:48:34 +00001113 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001114 const_iterator cbegin() const _NOEXCEPT {return begin();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001115 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001116 const_iterator cend() const _NOEXCEPT {return end();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001117 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001118 const_reverse_iterator crbegin() const _NOEXCEPT {return rbegin();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001119 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001120 const_reverse_iterator crend() const _NOEXCEPT {return rend();}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001121
Marshall Clow425f5752017-11-15 05:51:26 +00001122 _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001123 bool empty() const _NOEXCEPT {return __tree_.size() == 0;}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001124 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001125 size_type size() const _NOEXCEPT {return __tree_.size();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001126 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001127 size_type max_size() const _NOEXCEPT {return __tree_.max_size();}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001128
1129 mapped_type& operator[](const key_type& __k);
Eric Fiselierd63f38e2016-03-31 03:13:37 +00001130#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001131 mapped_type& operator[](key_type&& __k);
1132#endif
1133
1134 mapped_type& at(const key_type& __k);
1135 const mapped_type& at(const key_type& __k) const;
1136
Howard Hinnant756c69b2010-09-22 16:48:34 +00001137 _LIBCPP_INLINE_VISIBILITY
Marshall Clow657cbc42016-08-17 05:58:40 +00001138 allocator_type get_allocator() const _NOEXCEPT {return allocator_type(__tree_.__alloc());}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001139 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001140 key_compare key_comp() const {return __tree_.value_comp().key_comp();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001141 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001142 value_compare value_comp() const {return value_compare(__tree_.value_comp().key_comp());}
1143
Eric Fiselierd06276b2016-03-31 02:15:15 +00001144#ifndef _LIBCPP_CXX03_LANG
1145 template <class ..._Args>
1146 _LIBCPP_INLINE_VISIBILITY
1147 pair<iterator, bool> emplace(_Args&& ...__args) {
1148 return __tree_.__emplace_unique(_VSTD::forward<_Args>(__args)...);
1149 }
Howard Hinnant74279a52010-09-04 23:28:19 +00001150
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001151 template <class ..._Args>
Eric Fiselierd06276b2016-03-31 02:15:15 +00001152 _LIBCPP_INLINE_VISIBILITY
1153 iterator emplace_hint(const_iterator __p, _Args&& ...__args) {
1154 return __tree_.__emplace_hint_unique(__p.__i_, _VSTD::forward<_Args>(__args)...);
1155 }
Howard Hinnant74279a52010-09-04 23:28:19 +00001156
Howard Hinnantc834c512011-11-29 18:15:50 +00001157 template <class _Pp,
1158 class = typename enable_if<is_constructible<value_type, _Pp>::value>::type>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001159 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc834c512011-11-29 18:15:50 +00001160 pair<iterator, bool> insert(_Pp&& __p)
1161 {return __tree_.__insert_unique(_VSTD::forward<_Pp>(__p));}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001162
Howard Hinnantc834c512011-11-29 18:15:50 +00001163 template <class _Pp,
1164 class = typename enable_if<is_constructible<value_type, _Pp>::value>::type>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001165 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc834c512011-11-29 18:15:50 +00001166 iterator insert(const_iterator __pos, _Pp&& __p)
1167 {return __tree_.__insert_unique(__pos.__i_, _VSTD::forward<_Pp>(__p));}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001168
Eric Fiselierd06276b2016-03-31 02:15:15 +00001169#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001170
Howard Hinnant756c69b2010-09-22 16:48:34 +00001171 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001172 pair<iterator, bool>
1173 insert(const value_type& __v) {return __tree_.__insert_unique(__v);}
1174
Howard Hinnant756c69b2010-09-22 16:48:34 +00001175 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001176 iterator
1177 insert(const_iterator __p, const value_type& __v)
1178 {return __tree_.__insert_unique(__p.__i_, __v);}
1179
Eric Fiselierd6143132016-04-18 01:40:45 +00001180#ifndef _LIBCPP_CXX03_LANG
Marshall Clowd430d022016-01-05 19:32:41 +00001181 _LIBCPP_INLINE_VISIBILITY
1182 pair<iterator, bool>
Eric Fiselierd06276b2016-03-31 02:15:15 +00001183 insert(value_type&& __v) {return __tree_.__insert_unique(_VSTD::move(__v));}
Marshall Clowd430d022016-01-05 19:32:41 +00001184
1185 _LIBCPP_INLINE_VISIBILITY
Eric Fiselierd06276b2016-03-31 02:15:15 +00001186 iterator insert(const_iterator __p, value_type&& __v)
1187 {return __tree_.__insert_unique(__p.__i_, _VSTD::move(__v));}
Eric Fiseliera85b1282017-04-18 21:08:06 +00001188
1189 _LIBCPP_INLINE_VISIBILITY
1190 void insert(initializer_list<value_type> __il)
1191 {insert(__il.begin(), __il.end());}
Marshall Clowd430d022016-01-05 19:32:41 +00001192#endif
1193
Howard Hinnantc51e1022010-05-11 19:42:16 +00001194 template <class _InputIterator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001195 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001196 void insert(_InputIterator __f, _InputIterator __l)
1197 {
1198 for (const_iterator __e = cend(); __f != __l; ++__f)
1199 insert(__e.__i_, *__f);
1200 }
1201
Marshall Clow3223db82015-07-07 03:37:33 +00001202#if _LIBCPP_STD_VER > 14
Eric Fiselierd63f38e2016-03-31 03:13:37 +00001203
Marshall Clow3223db82015-07-07 03:37:33 +00001204 template <class... _Args>
1205 _LIBCPP_INLINE_VISIBILITY
1206 pair<iterator, bool> try_emplace(const key_type& __k, _Args&&... __args)
1207 {
Eric Fiselierd63f38e2016-03-31 03:13:37 +00001208 return __tree_.__emplace_unique_key_args(__k,
1209 _VSTD::piecewise_construct,
1210 _VSTD::forward_as_tuple(__k),
1211 _VSTD::forward_as_tuple(_VSTD::forward<_Args>(__args)...));
Marshall Clow3223db82015-07-07 03:37:33 +00001212 }
1213
1214 template <class... _Args>
1215 _LIBCPP_INLINE_VISIBILITY
1216 pair<iterator, bool> try_emplace(key_type&& __k, _Args&&... __args)
1217 {
Eric Fiselierd63f38e2016-03-31 03:13:37 +00001218 return __tree_.__emplace_unique_key_args(__k,
1219 _VSTD::piecewise_construct,
1220 _VSTD::forward_as_tuple(_VSTD::move(__k)),
1221 _VSTD::forward_as_tuple(_VSTD::forward<_Args>(__args)...));
Marshall Clow3223db82015-07-07 03:37:33 +00001222 }
1223
1224 template <class... _Args>
1225 _LIBCPP_INLINE_VISIBILITY
1226 iterator try_emplace(const_iterator __h, const key_type& __k, _Args&&... __args)
1227 {
Eric Fiselierd63f38e2016-03-31 03:13:37 +00001228 return __tree_.__emplace_hint_unique_key_args(__h.__i_, __k,
1229 _VSTD::piecewise_construct,
1230 _VSTD::forward_as_tuple(__k),
1231 _VSTD::forward_as_tuple(_VSTD::forward<_Args>(__args)...));
Marshall Clow3223db82015-07-07 03:37:33 +00001232 }
1233
1234 template <class... _Args>
1235 _LIBCPP_INLINE_VISIBILITY
1236 iterator try_emplace(const_iterator __h, key_type&& __k, _Args&&... __args)
1237 {
Eric Fiselierd63f38e2016-03-31 03:13:37 +00001238 return __tree_.__emplace_hint_unique_key_args(__h.__i_, __k,
1239 _VSTD::piecewise_construct,
1240 _VSTD::forward_as_tuple(_VSTD::move(__k)),
1241 _VSTD::forward_as_tuple(_VSTD::forward<_Args>(__args)...));
Marshall Clow3223db82015-07-07 03:37:33 +00001242 }
1243
1244 template <class _Vp>
1245 _LIBCPP_INLINE_VISIBILITY
1246 pair<iterator, bool> insert_or_assign(const key_type& __k, _Vp&& __v)
1247 {
1248 iterator __p = lower_bound(__k);
1249 if ( __p != end() && !key_comp()(__k, __p->first))
1250 {
1251 __p->second = _VSTD::forward<_Vp>(__v);
1252 return _VSTD::make_pair(__p, false);
1253 }
1254 return _VSTD::make_pair(emplace_hint(__p, __k, _VSTD::forward<_Vp>(__v)), true);
1255 }
Eric Fiselierd63f38e2016-03-31 03:13:37 +00001256
Marshall Clow3223db82015-07-07 03:37:33 +00001257 template <class _Vp>
1258 _LIBCPP_INLINE_VISIBILITY
1259 pair<iterator, bool> insert_or_assign(key_type&& __k, _Vp&& __v)
1260 {
1261 iterator __p = lower_bound(__k);
1262 if ( __p != end() && !key_comp()(__k, __p->first))
1263 {
1264 __p->second = _VSTD::forward<_Vp>(__v);
1265 return _VSTD::make_pair(__p, false);
1266 }
1267 return _VSTD::make_pair(emplace_hint(__p, _VSTD::move(__k), _VSTD::forward<_Vp>(__v)), true);
1268 }
1269
1270 template <class _Vp>
1271 _LIBCPP_INLINE_VISIBILITY
1272 iterator insert_or_assign(const_iterator __h, const key_type& __k, _Vp&& __v)
1273 {
1274 iterator __p = lower_bound(__k);
1275 if ( __p != end() && !key_comp()(__k, __p->first))
1276 {
1277 __p->second = _VSTD::forward<_Vp>(__v);
1278 return __p;
1279 }
1280 return emplace_hint(__h, __k, _VSTD::forward<_Vp>(__v));
1281 }
1282
1283 template <class _Vp>
1284 _LIBCPP_INLINE_VISIBILITY
1285 iterator insert_or_assign(const_iterator __h, key_type&& __k, _Vp&& __v)
1286 {
1287 iterator __p = lower_bound(__k);
1288 if ( __p != end() && !key_comp()(__k, __p->first))
1289 {
1290 __p->second = _VSTD::forward<_Vp>(__v);
1291 return __p;
1292 }
1293 return emplace_hint(__h, _VSTD::move(__k), _VSTD::forward<_Vp>(__v));
1294 }
Eric Fiselierd63f38e2016-03-31 03:13:37 +00001295
Eric Fiseliera85b1282017-04-18 21:08:06 +00001296#endif // _LIBCPP_STD_VER > 14
Marshall Clow3223db82015-07-07 03:37:33 +00001297
Howard Hinnant756c69b2010-09-22 16:48:34 +00001298 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001299 iterator erase(const_iterator __p) {return __tree_.erase(__p.__i_);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001300 _LIBCPP_INLINE_VISIBILITY
Marshall Clow22ea5b82015-05-10 13:35:00 +00001301 iterator erase(iterator __p) {return __tree_.erase(__p.__i_);}
1302 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001303 size_type erase(const key_type& __k)
1304 {return __tree_.__erase_unique(__k);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001305 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001306 iterator erase(const_iterator __f, const_iterator __l)
1307 {return __tree_.erase(__f.__i_, __l.__i_);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001308 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001309 void clear() _NOEXCEPT {__tree_.clear();}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001310
Erik Pilkingtonc37a3d82018-08-01 01:33:38 +00001311#if _LIBCPP_STD_VER > 14
1312 _LIBCPP_INLINE_VISIBILITY
1313 insert_return_type insert(node_type&& __nh)
1314 {
1315 _LIBCPP_ASSERT(__nh.empty() || __nh.get_allocator() == get_allocator(),
1316 "node_type with incompatible allocator passed to map::insert()");
1317 return __tree_.template __node_handle_insert_unique<
1318 node_type, insert_return_type>(_VSTD::move(__nh));
1319 }
1320 _LIBCPP_INLINE_VISIBILITY
1321 iterator insert(const_iterator __hint, node_type&& __nh)
1322 {
1323 _LIBCPP_ASSERT(__nh.empty() || __nh.get_allocator() == get_allocator(),
1324 "node_type with incompatible allocator passed to map::insert()");
1325 return __tree_.template __node_handle_insert_unique<node_type>(
1326 __hint.__i_, _VSTD::move(__nh));
1327 }
1328 _LIBCPP_INLINE_VISIBILITY
1329 node_type extract(key_type const& __key)
1330 {
1331 return __tree_.template __node_handle_extract<node_type>(__key);
1332 }
1333 _LIBCPP_INLINE_VISIBILITY
1334 node_type extract(const_iterator __it)
1335 {
1336 return __tree_.template __node_handle_extract<node_type>(__it.__i_);
1337 }
Louis Dionned2322c82018-11-01 14:41:37 +00001338 template <class _Compare2>
Erik Pilkington82a65ad2018-10-31 17:31:35 +00001339 _LIBCPP_INLINE_VISIBILITY
Louis Dionned2322c82018-11-01 14:41:37 +00001340 void merge(map<key_type, mapped_type, _Compare2, allocator_type>& __source)
Erik Pilkington82a65ad2018-10-31 17:31:35 +00001341 {
1342 _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
1343 "merging container with incompatible allocator");
1344 __tree_.__node_handle_merge_unique(__source.__tree_);
1345 }
Louis Dionned2322c82018-11-01 14:41:37 +00001346 template <class _Compare2>
Erik Pilkington82a65ad2018-10-31 17:31:35 +00001347 _LIBCPP_INLINE_VISIBILITY
Louis Dionned2322c82018-11-01 14:41:37 +00001348 void merge(map<key_type, mapped_type, _Compare2, allocator_type>&& __source)
Erik Pilkington82a65ad2018-10-31 17:31:35 +00001349 {
1350 _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
1351 "merging container with incompatible allocator");
1352 __tree_.__node_handle_merge_unique(__source.__tree_);
1353 }
Louis Dionned2322c82018-11-01 14:41:37 +00001354 template <class _Compare2>
Erik Pilkington82a65ad2018-10-31 17:31:35 +00001355 _LIBCPP_INLINE_VISIBILITY
Louis Dionned2322c82018-11-01 14:41:37 +00001356 void merge(multimap<key_type, mapped_type, _Compare2, allocator_type>& __source)
Erik Pilkington82a65ad2018-10-31 17:31:35 +00001357 {
1358 _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
1359 "merging container with incompatible allocator");
1360 __tree_.__node_handle_merge_unique(__source.__tree_);
1361 }
Louis Dionned2322c82018-11-01 14:41:37 +00001362 template <class _Compare2>
Erik Pilkington82a65ad2018-10-31 17:31:35 +00001363 _LIBCPP_INLINE_VISIBILITY
Louis Dionned2322c82018-11-01 14:41:37 +00001364 void merge(multimap<key_type, mapped_type, _Compare2, allocator_type>&& __source)
Erik Pilkington82a65ad2018-10-31 17:31:35 +00001365 {
1366 _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
1367 "merging container with incompatible allocator");
1368 __tree_.__node_handle_merge_unique(__source.__tree_);
1369 }
Erik Pilkingtonc37a3d82018-08-01 01:33:38 +00001370#endif
1371
Howard Hinnant756c69b2010-09-22 16:48:34 +00001372 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001373 void swap(map& __m)
1374 _NOEXCEPT_(__is_nothrow_swappable<__base>::value)
1375 {__tree_.swap(__m.__tree_);}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001376
Howard Hinnant756c69b2010-09-22 16:48:34 +00001377 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001378 iterator find(const key_type& __k) {return __tree_.find(__k);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001379 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001380 const_iterator find(const key_type& __k) const {return __tree_.find(__k);}
Marshall Clowebb57322013-08-13 22:18:47 +00001381#if _LIBCPP_STD_VER > 11
1382 template <typename _K2>
1383 _LIBCPP_INLINE_VISIBILITY
1384 typename enable_if<__is_transparent<_Compare, _K2>::value,iterator>::type
1385 find(const _K2& __k) {return __tree_.find(__k);}
1386 template <typename _K2>
1387 _LIBCPP_INLINE_VISIBILITY
1388 typename enable_if<__is_transparent<_Compare, _K2>::value,const_iterator>::type
1389 find(const _K2& __k) const {return __tree_.find(__k);}
1390#endif
1391
Howard Hinnant756c69b2010-09-22 16:48:34 +00001392 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001393 size_type count(const key_type& __k) const
1394 {return __tree_.__count_unique(__k);}
Marshall Clowe6a5f522014-08-24 23:54:16 +00001395#if _LIBCPP_STD_VER > 11
1396 template <typename _K2>
1397 _LIBCPP_INLINE_VISIBILITY
1398 typename enable_if<__is_transparent<_Compare, _K2>::value,size_type>::type
Eric Fiseliera85c9e92018-02-10 02:53:47 +00001399 count(const _K2& __k) const {return __tree_.__count_multi(__k);}
Marshall Clowe6a5f522014-08-24 23:54:16 +00001400#endif
Zoe Carver3ffbab12019-07-16 03:21:01 +00001401
1402#if _LIBCPP_STD_VER > 17
1403 _LIBCPP_INLINE_VISIBILITY
1404 bool contains(const key_type& __k) const {return find(__k) != end();}
1405#endif // _LIBCPP_STD_VER > 17
1406
Howard Hinnant756c69b2010-09-22 16:48:34 +00001407 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001408 iterator lower_bound(const key_type& __k)
1409 {return __tree_.lower_bound(__k);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001410 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001411 const_iterator lower_bound(const key_type& __k) const
1412 {return __tree_.lower_bound(__k);}
Marshall Clowebb57322013-08-13 22:18:47 +00001413#if _LIBCPP_STD_VER > 11
1414 template <typename _K2>
1415 _LIBCPP_INLINE_VISIBILITY
1416 typename enable_if<__is_transparent<_Compare, _K2>::value,iterator>::type
1417 lower_bound(const _K2& __k) {return __tree_.lower_bound(__k);}
1418
1419 template <typename _K2>
1420 _LIBCPP_INLINE_VISIBILITY
1421 typename enable_if<__is_transparent<_Compare, _K2>::value,const_iterator>::type
1422 lower_bound(const _K2& __k) const {return __tree_.lower_bound(__k);}
1423#endif
1424
Howard Hinnant756c69b2010-09-22 16:48:34 +00001425 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001426 iterator upper_bound(const key_type& __k)
1427 {return __tree_.upper_bound(__k);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001428 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001429 const_iterator upper_bound(const key_type& __k) const
1430 {return __tree_.upper_bound(__k);}
Marshall Clowebb57322013-08-13 22:18:47 +00001431#if _LIBCPP_STD_VER > 11
1432 template <typename _K2>
1433 _LIBCPP_INLINE_VISIBILITY
1434 typename enable_if<__is_transparent<_Compare, _K2>::value,iterator>::type
1435 upper_bound(const _K2& __k) {return __tree_.upper_bound(__k);}
1436 template <typename _K2>
1437 _LIBCPP_INLINE_VISIBILITY
1438 typename enable_if<__is_transparent<_Compare, _K2>::value,const_iterator>::type
1439 upper_bound(const _K2& __k) const {return __tree_.upper_bound(__k);}
1440#endif
1441
Howard Hinnant756c69b2010-09-22 16:48:34 +00001442 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001443 pair<iterator,iterator> equal_range(const key_type& __k)
1444 {return __tree_.__equal_range_unique(__k);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001445 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001446 pair<const_iterator,const_iterator> equal_range(const key_type& __k) const
1447 {return __tree_.__equal_range_unique(__k);}
Marshall Clowebb57322013-08-13 22:18:47 +00001448#if _LIBCPP_STD_VER > 11
1449 template <typename _K2>
1450 _LIBCPP_INLINE_VISIBILITY
1451 typename enable_if<__is_transparent<_Compare, _K2>::value,pair<iterator,iterator>>::type
Eric Fiseliera85c9e92018-02-10 02:53:47 +00001452 equal_range(const _K2& __k) {return __tree_.__equal_range_multi(__k);}
Marshall Clowebb57322013-08-13 22:18:47 +00001453 template <typename _K2>
1454 _LIBCPP_INLINE_VISIBILITY
1455 typename enable_if<__is_transparent<_Compare, _K2>::value,pair<const_iterator,const_iterator>>::type
Eric Fiseliera85c9e92018-02-10 02:53:47 +00001456 equal_range(const _K2& __k) const {return __tree_.__equal_range_multi(__k);}
Marshall Clowebb57322013-08-13 22:18:47 +00001457#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001458
1459private:
1460 typedef typename __base::__node __node;
1461 typedef typename __base::__node_allocator __node_allocator;
1462 typedef typename __base::__node_pointer __node_pointer;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001463 typedef typename __base::__node_base_pointer __node_base_pointer;
Eric Fiseliercf8c0212017-01-05 06:06:18 +00001464 typedef typename __base::__parent_pointer __parent_pointer;
Eric Fiseliera92b0732016-02-20 07:12:17 +00001465
Howard Hinnantc834c512011-11-29 18:15:50 +00001466 typedef __map_node_destructor<__node_allocator> _Dp;
1467 typedef unique_ptr<__node, _Dp> __node_holder;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001468
Eric Fiselierd63f38e2016-03-31 03:13:37 +00001469#ifdef _LIBCPP_CXX03_LANG
Howard Hinnantac7e7482013-07-04 20:59:16 +00001470 __node_holder __construct_node_with_key(const key_type& __k);
Eric Fiselierd63f38e2016-03-31 03:13:37 +00001471#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001472};
1473
Louis Dionned23a5f22019-06-20 19:32:00 +00001474#ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES
1475template<class _InputIterator, class _Compare = less<__iter_key_type<_InputIterator>>,
1476 class _Allocator = allocator<__iter_to_alloc_type<_InputIterator>>,
Louis Dionne6c7da9a2019-07-19 17:13:39 +00001477 class = _EnableIf<!__is_allocator<_Compare>::value, void>,
1478 class = _EnableIf<__is_allocator<_Allocator>::value, void>>
Louis Dionned23a5f22019-06-20 19:32:00 +00001479map(_InputIterator, _InputIterator, _Compare = _Compare(), _Allocator = _Allocator())
1480 -> map<__iter_key_type<_InputIterator>, __iter_mapped_type<_InputIterator>, _Compare, _Allocator>;
1481
1482template<class _Key, class _Tp, class _Compare = less<remove_const_t<_Key>>,
1483 class _Allocator = allocator<pair<const _Key, _Tp>>,
Louis Dionne6c7da9a2019-07-19 17:13:39 +00001484 class = _EnableIf<!__is_allocator<_Compare>::value, void>,
1485 class = _EnableIf<__is_allocator<_Allocator>::value, void>>
Louis Dionned23a5f22019-06-20 19:32:00 +00001486map(initializer_list<pair<_Key, _Tp>>, _Compare = _Compare(), _Allocator = _Allocator())
1487 -> map<remove_const_t<_Key>, _Tp, _Compare, _Allocator>;
1488
1489template<class _InputIterator, class _Allocator,
Louis Dionne6c7da9a2019-07-19 17:13:39 +00001490 class = _EnableIf<__is_allocator<_Allocator>::value, void>>
Louis Dionned23a5f22019-06-20 19:32:00 +00001491map(_InputIterator, _InputIterator, _Allocator)
1492 -> map<__iter_key_type<_InputIterator>, __iter_mapped_type<_InputIterator>,
1493 less<__iter_key_type<_InputIterator>>, _Allocator>;
1494
1495template<class _Key, class _Tp, class _Allocator,
Louis Dionne6c7da9a2019-07-19 17:13:39 +00001496 class = _EnableIf<__is_allocator<_Allocator>::value, void>>
Louis Dionned23a5f22019-06-20 19:32:00 +00001497map(initializer_list<pair<_Key, _Tp>>, _Allocator)
1498 -> map<remove_const_t<_Key>, _Tp, less<remove_const_t<_Key>>, _Allocator>;
1499#endif
Eric Fiseliera92b0732016-02-20 07:12:17 +00001500
Eric Fiselierd06276b2016-03-31 02:15:15 +00001501#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001502template <class _Key, class _Tp, class _Compare, class _Allocator>
1503map<_Key, _Tp, _Compare, _Allocator>::map(map&& __m, const allocator_type& __a)
Marshall Clow657cbc42016-08-17 05:58:40 +00001504 : __tree_(_VSTD::move(__m.__tree_), typename __base::allocator_type(__a))
Howard Hinnantc51e1022010-05-11 19:42:16 +00001505{
1506 if (__a != __m.get_allocator())
1507 {
1508 const_iterator __e = cend();
1509 while (!__m.empty())
1510 __tree_.__insert_unique(__e.__i_,
Erik Pilkingtond3fe2992018-06-04 20:38:23 +00001511 __m.__tree_.remove(__m.begin().__i_)->__value_.__move());
Howard Hinnantc51e1022010-05-11 19:42:16 +00001512 }
1513}
1514
Eric Fiseliera85b1282017-04-18 21:08:06 +00001515template <class _Key, class _Tp, class _Compare, class _Allocator>
1516_Tp&
1517map<_Key, _Tp, _Compare, _Allocator>::operator[](const key_type& __k)
1518{
1519 return __tree_.__emplace_unique_key_args(__k,
1520 _VSTD::piecewise_construct,
1521 _VSTD::forward_as_tuple(__k),
Erik Pilkingtond3fe2992018-06-04 20:38:23 +00001522 _VSTD::forward_as_tuple()).first->__get_value().second;
Eric Fiseliera85b1282017-04-18 21:08:06 +00001523}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001524
Eric Fiseliera85b1282017-04-18 21:08:06 +00001525template <class _Key, class _Tp, class _Compare, class _Allocator>
1526_Tp&
1527map<_Key, _Tp, _Compare, _Allocator>::operator[](key_type&& __k)
1528{
1529 return __tree_.__emplace_unique_key_args(__k,
1530 _VSTD::piecewise_construct,
1531 _VSTD::forward_as_tuple(_VSTD::move(__k)),
Erik Pilkingtond3fe2992018-06-04 20:38:23 +00001532 _VSTD::forward_as_tuple()).first->__get_value().second;
Eric Fiseliera85b1282017-04-18 21:08:06 +00001533}
Eric Fiselierd63f38e2016-03-31 03:13:37 +00001534
Eric Fiseliera85b1282017-04-18 21:08:06 +00001535#else // _LIBCPP_CXX03_LANG
Eric Fiselierd63f38e2016-03-31 03:13:37 +00001536
Howard Hinnantc51e1022010-05-11 19:42:16 +00001537template <class _Key, class _Tp, class _Compare, class _Allocator>
1538typename map<_Key, _Tp, _Compare, _Allocator>::__node_holder
Howard Hinnantac7e7482013-07-04 20:59:16 +00001539map<_Key, _Tp, _Compare, _Allocator>::__construct_node_with_key(const key_type& __k)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001540{
1541 __node_allocator& __na = __tree_.__node_alloc();
Howard Hinnantc834c512011-11-29 18:15:50 +00001542 __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
Erik Pilkingtond3fe2992018-06-04 20:38:23 +00001543 __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__get_value().first), __k);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001544 __h.get_deleter().__first_constructed = true;
Erik Pilkingtond3fe2992018-06-04 20:38:23 +00001545 __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__get_value().second));
Howard Hinnantc51e1022010-05-11 19:42:16 +00001546 __h.get_deleter().__second_constructed = true;
Dimitry Andric830fb602015-08-19 06:43:33 +00001547 return _LIBCPP_EXPLICIT_MOVE(__h); // explicitly moved for C++03
Howard Hinnantc51e1022010-05-11 19:42:16 +00001548}
1549
Howard Hinnantc51e1022010-05-11 19:42:16 +00001550template <class _Key, class _Tp, class _Compare, class _Allocator>
1551_Tp&
1552map<_Key, _Tp, _Compare, _Allocator>::operator[](const key_type& __k)
1553{
Eric Fiseliercf8c0212017-01-05 06:06:18 +00001554 __parent_pointer __parent;
1555 __node_base_pointer& __child = __tree_.__find_equal(__parent, __k);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001556 __node_pointer __r = static_cast<__node_pointer>(__child);
1557 if (__child == nullptr)
1558 {
Howard Hinnantac7e7482013-07-04 20:59:16 +00001559 __node_holder __h = __construct_node_with_key(__k);
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001560 __tree_.__insert_node_at(__parent, __child, static_cast<__node_base_pointer>(__h.get()));
Howard Hinnantc51e1022010-05-11 19:42:16 +00001561 __r = __h.release();
1562 }
Erik Pilkingtond3fe2992018-06-04 20:38:23 +00001563 return __r->__value_.__get_value().second;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001564}
1565
Eric Fiseliera85b1282017-04-18 21:08:06 +00001566#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001567
1568template <class _Key, class _Tp, class _Compare, class _Allocator>
1569_Tp&
1570map<_Key, _Tp, _Compare, _Allocator>::at(const key_type& __k)
1571{
Eric Fiseliercf8c0212017-01-05 06:06:18 +00001572 __parent_pointer __parent;
1573 __node_base_pointer& __child = __tree_.__find_equal(__parent, __k);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001574 if (__child == nullptr)
Louis Dionne2b239162019-02-12 16:06:02 +00001575 __throw_out_of_range("map::at: key not found");
Erik Pilkingtond3fe2992018-06-04 20:38:23 +00001576 return static_cast<__node_pointer>(__child)->__value_.__get_value().second;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001577}
1578
1579template <class _Key, class _Tp, class _Compare, class _Allocator>
1580const _Tp&
1581map<_Key, _Tp, _Compare, _Allocator>::at(const key_type& __k) const
1582{
Eric Fiseliercf8c0212017-01-05 06:06:18 +00001583 __parent_pointer __parent;
1584 __node_base_pointer __child = __tree_.__find_equal(__parent, __k);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001585 if (__child == nullptr)
Louis Dionne2b239162019-02-12 16:06:02 +00001586 __throw_out_of_range("map::at: key not found");
Erik Pilkingtond3fe2992018-06-04 20:38:23 +00001587 return static_cast<__node_pointer>(__child)->__value_.__get_value().second;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001588}
1589
Howard Hinnantc51e1022010-05-11 19:42:16 +00001590
1591template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001592inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001593bool
1594operator==(const map<_Key, _Tp, _Compare, _Allocator>& __x,
1595 const map<_Key, _Tp, _Compare, _Allocator>& __y)
1596{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001597 return __x.size() == __y.size() && _VSTD::equal(__x.begin(), __x.end(), __y.begin());
Howard Hinnantc51e1022010-05-11 19:42:16 +00001598}
1599
1600template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001601inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001602bool
1603operator< (const map<_Key, _Tp, _Compare, _Allocator>& __x,
1604 const map<_Key, _Tp, _Compare, _Allocator>& __y)
1605{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001606 return _VSTD::lexicographical_compare(__x.begin(), __x.end(), __y.begin(), __y.end());
Howard Hinnantc51e1022010-05-11 19:42:16 +00001607}
1608
1609template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001610inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001611bool
1612operator!=(const map<_Key, _Tp, _Compare, _Allocator>& __x,
1613 const map<_Key, _Tp, _Compare, _Allocator>& __y)
1614{
1615 return !(__x == __y);
1616}
1617
1618template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001619inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001620bool
1621operator> (const map<_Key, _Tp, _Compare, _Allocator>& __x,
1622 const map<_Key, _Tp, _Compare, _Allocator>& __y)
1623{
1624 return __y < __x;
1625}
1626
1627template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001628inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001629bool
1630operator>=(const map<_Key, _Tp, _Compare, _Allocator>& __x,
1631 const map<_Key, _Tp, _Compare, _Allocator>& __y)
1632{
1633 return !(__x < __y);
1634}
1635
1636template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001637inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001638bool
1639operator<=(const map<_Key, _Tp, _Compare, _Allocator>& __x,
1640 const map<_Key, _Tp, _Compare, _Allocator>& __y)
1641{
1642 return !(__y < __x);
1643}
1644
1645template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001646inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001647void
1648swap(map<_Key, _Tp, _Compare, _Allocator>& __x,
1649 map<_Key, _Tp, _Compare, _Allocator>& __y)
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001650 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
Howard Hinnantc51e1022010-05-11 19:42:16 +00001651{
1652 __x.swap(__y);
1653}
1654
Marshall Clow29b53f22018-12-14 18:49:35 +00001655#if _LIBCPP_STD_VER > 17
1656template <class _Key, class _Tp, class _Compare, class _Allocator, class _Predicate>
1657inline _LIBCPP_INLINE_VISIBILITY
1658void erase_if(map<_Key, _Tp, _Compare, _Allocator>& __c, _Predicate __pred)
1659{ __libcpp_erase_if_container(__c, __pred); }
1660#endif
1661
1662
Howard Hinnantc51e1022010-05-11 19:42:16 +00001663template <class _Key, class _Tp, class _Compare = less<_Key>,
1664 class _Allocator = allocator<pair<const _Key, _Tp> > >
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00001665class _LIBCPP_TEMPLATE_VIS multimap
Howard Hinnantc51e1022010-05-11 19:42:16 +00001666{
1667public:
1668 // types:
1669 typedef _Key key_type;
1670 typedef _Tp mapped_type;
1671 typedef pair<const key_type, mapped_type> value_type;
Louis Dionned23a5f22019-06-20 19:32:00 +00001672 typedef typename __identity<_Compare>::type key_compare;
1673 typedef typename __identity<_Allocator>::type allocator_type;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001674 typedef value_type& reference;
1675 typedef const value_type& const_reference;
1676
Marshall Clow5128cf32015-11-26 01:24:04 +00001677 static_assert((is_same<typename allocator_type::value_type, value_type>::value),
1678 "Allocator::value_type must be same type as value_type");
1679
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00001680 class _LIBCPP_TEMPLATE_VIS value_compare
Howard Hinnantc51e1022010-05-11 19:42:16 +00001681 : public binary_function<value_type, value_type, bool>
1682 {
1683 friend class multimap;
1684 protected:
1685 key_compare comp;
1686
Howard Hinnant756c69b2010-09-22 16:48:34 +00001687 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001688 value_compare(key_compare c) : comp(c) {}
1689 public:
Howard Hinnant756c69b2010-09-22 16:48:34 +00001690 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001691 bool operator()(const value_type& __x, const value_type& __y) const
1692 {return comp(__x.first, __y.first);}
1693 };
1694
1695private:
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001696
Howard Hinnant89f8b792013-09-30 19:08:22 +00001697 typedef _VSTD::__value_type<key_type, mapped_type> __value_type;
Howard Hinnant90b91592013-07-05 18:06:00 +00001698 typedef __map_value_compare<key_type, __value_type, key_compare> __vc;
Marshall Clow940e01c2015-04-07 05:21:38 +00001699 typedef typename __rebind_alloc_helper<allocator_traits<allocator_type>,
1700 __value_type>::type __allocator_type;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001701 typedef __tree<__value_type, __vc, __allocator_type> __base;
1702 typedef typename __base::__node_traits __node_traits;
1703 typedef allocator_traits<allocator_type> __alloc_traits;
1704
1705 __base __tree_;
1706
1707public:
1708 typedef typename __alloc_traits::pointer pointer;
1709 typedef typename __alloc_traits::const_pointer const_pointer;
1710 typedef typename __alloc_traits::size_type size_type;
1711 typedef typename __alloc_traits::difference_type difference_type;
1712 typedef __map_iterator<typename __base::iterator> iterator;
1713 typedef __map_const_iterator<typename __base::const_iterator> const_iterator;
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001714 typedef _VSTD::reverse_iterator<iterator> reverse_iterator;
1715 typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001716
Erik Pilkingtonc37a3d82018-08-01 01:33:38 +00001717#if _LIBCPP_STD_VER > 14
1718 typedef __map_node_handle<typename __base::__node, allocator_type> node_type;
1719#endif
1720
Erik Pilkington82a65ad2018-10-31 17:31:35 +00001721 template <class _Key2, class _Value2, class _Comp2, class _Alloc2>
1722 friend class _LIBCPP_TEMPLATE_VIS map;
1723 template <class _Key2, class _Value2, class _Comp2, class _Alloc2>
1724 friend class _LIBCPP_TEMPLATE_VIS multimap;
1725
Howard Hinnant756c69b2010-09-22 16:48:34 +00001726 _LIBCPP_INLINE_VISIBILITY
Marshall Clow7086a5a2014-03-10 04:50:10 +00001727 multimap()
1728 _NOEXCEPT_(
1729 is_nothrow_default_constructible<allocator_type>::value &&
1730 is_nothrow_default_constructible<key_compare>::value &&
1731 is_nothrow_copy_constructible<key_compare>::value)
1732 : __tree_(__vc(key_compare())) {}
1733
1734 _LIBCPP_INLINE_VISIBILITY
1735 explicit multimap(const key_compare& __comp)
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001736 _NOEXCEPT_(
1737 is_nothrow_default_constructible<allocator_type>::value &&
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001738 is_nothrow_copy_constructible<key_compare>::value)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001739 : __tree_(__vc(__comp)) {}
1740
Howard Hinnant756c69b2010-09-22 16:48:34 +00001741 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001742 explicit multimap(const key_compare& __comp, const allocator_type& __a)
Marshall Clow657cbc42016-08-17 05:58:40 +00001743 : __tree_(__vc(__comp), typename __base::allocator_type(__a)) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001744
1745 template <class _InputIterator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001746 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001747 multimap(_InputIterator __f, _InputIterator __l,
1748 const key_compare& __comp = key_compare())
1749 : __tree_(__vc(__comp))
1750 {
1751 insert(__f, __l);
1752 }
1753
1754 template <class _InputIterator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001755 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001756 multimap(_InputIterator __f, _InputIterator __l,
1757 const key_compare& __comp, const allocator_type& __a)
Marshall Clow657cbc42016-08-17 05:58:40 +00001758 : __tree_(__vc(__comp), typename __base::allocator_type(__a))
Howard Hinnantc51e1022010-05-11 19:42:16 +00001759 {
1760 insert(__f, __l);
1761 }
1762
Marshall Clow300abfb2013-09-11 01:15:47 +00001763#if _LIBCPP_STD_VER > 11
1764 template <class _InputIterator>
Eric Fiseliercf8c0212017-01-05 06:06:18 +00001765 _LIBCPP_INLINE_VISIBILITY
Marshall Clow300abfb2013-09-11 01:15:47 +00001766 multimap(_InputIterator __f, _InputIterator __l, const allocator_type& __a)
1767 : multimap(__f, __l, key_compare(), __a) {}
1768#endif
1769
Howard Hinnant756c69b2010-09-22 16:48:34 +00001770 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001771 multimap(const multimap& __m)
1772 : __tree_(__m.__tree_.value_comp(),
1773 __alloc_traits::select_on_container_copy_construction(__m.__tree_.__alloc()))
1774 {
1775 insert(__m.begin(), __m.end());
1776 }
1777
Howard Hinnantd3a657f2011-07-01 19:24:36 +00001778 _LIBCPP_INLINE_VISIBILITY
1779 multimap& operator=(const multimap& __m)
1780 {
Marshall Clow476d3f42016-07-18 13:19:00 +00001781#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantd3a657f2011-07-01 19:24:36 +00001782 __tree_ = __m.__tree_;
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001783#else
Marshall Clowdb3cfcb2014-02-08 04:03:14 +00001784 if (this != &__m) {
1785 __tree_.clear();
1786 __tree_.value_comp() = __m.__tree_.value_comp();
1787 __tree_.__copy_assign_alloc(__m.__tree_);
1788 insert(__m.begin(), __m.end());
1789 }
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001790#endif
Howard Hinnantd3a657f2011-07-01 19:24:36 +00001791 return *this;
1792 }
1793
Eric Fiseliera85b1282017-04-18 21:08:06 +00001794#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001795
Howard Hinnant756c69b2010-09-22 16:48:34 +00001796 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001797 multimap(multimap&& __m)
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001798 _NOEXCEPT_(is_nothrow_move_constructible<__base>::value)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001799 : __tree_(_VSTD::move(__m.__tree_))
Howard Hinnantc51e1022010-05-11 19:42:16 +00001800 {
1801 }
1802
1803 multimap(multimap&& __m, const allocator_type& __a);
1804
Howard Hinnant756c69b2010-09-22 16:48:34 +00001805 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant33711792011-08-12 21:56:02 +00001806 multimap& operator=(multimap&& __m)
1807 _NOEXCEPT_(is_nothrow_move_assignable<__base>::value)
1808 {
1809 __tree_ = _VSTD::move(__m.__tree_);
1810 return *this;
1811 }
1812
Howard Hinnant33711792011-08-12 21:56:02 +00001813 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001814 multimap(initializer_list<value_type> __il, const key_compare& __comp = key_compare())
1815 : __tree_(__vc(__comp))
1816 {
1817 insert(__il.begin(), __il.end());
1818 }
1819
Howard Hinnant756c69b2010-09-22 16:48:34 +00001820 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001821 multimap(initializer_list<value_type> __il, const key_compare& __comp, const allocator_type& __a)
Marshall Clow657cbc42016-08-17 05:58:40 +00001822 : __tree_(__vc(__comp), typename __base::allocator_type(__a))
Howard Hinnantc51e1022010-05-11 19:42:16 +00001823 {
1824 insert(__il.begin(), __il.end());
1825 }
1826
Marshall Clow300abfb2013-09-11 01:15:47 +00001827#if _LIBCPP_STD_VER > 11
Eric Fiseliercf8c0212017-01-05 06:06:18 +00001828 _LIBCPP_INLINE_VISIBILITY
Marshall Clow300abfb2013-09-11 01:15:47 +00001829 multimap(initializer_list<value_type> __il, const allocator_type& __a)
1830 : multimap(__il, key_compare(), __a) {}
1831#endif
1832
Howard Hinnant756c69b2010-09-22 16:48:34 +00001833 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001834 multimap& operator=(initializer_list<value_type> __il)
1835 {
1836 __tree_.__assign_multi(__il.begin(), __il.end());
1837 return *this;
1838 }
Howard Hinnant33711792011-08-12 21:56:02 +00001839
Eric Fiseliera85b1282017-04-18 21:08:06 +00001840#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001841
Howard Hinnant756c69b2010-09-22 16:48:34 +00001842 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001843 explicit multimap(const allocator_type& __a)
Marshall Clow657cbc42016-08-17 05:58:40 +00001844 : __tree_(typename __base::allocator_type(__a))
Howard Hinnantc51e1022010-05-11 19:42:16 +00001845 {
1846 }
1847
Howard Hinnant756c69b2010-09-22 16:48:34 +00001848 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001849 multimap(const multimap& __m, const allocator_type& __a)
Marshall Clow657cbc42016-08-17 05:58:40 +00001850 : __tree_(__m.__tree_.value_comp(), typename __base::allocator_type(__a))
Howard Hinnantc51e1022010-05-11 19:42:16 +00001851 {
1852 insert(__m.begin(), __m.end());
1853 }
1854
Howard Hinnant756c69b2010-09-22 16:48:34 +00001855 _LIBCPP_INLINE_VISIBILITY
Louis Dionne69c42c02019-04-11 16:14:56 +00001856 ~multimap() {
1857 static_assert(sizeof(__diagnose_non_const_comparator<_Key, _Compare>()), "");
1858 }
1859
1860 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001861 iterator begin() _NOEXCEPT {return __tree_.begin();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001862 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001863 const_iterator begin() const _NOEXCEPT {return __tree_.begin();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001864 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001865 iterator end() _NOEXCEPT {return __tree_.end();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001866 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001867 const_iterator end() const _NOEXCEPT {return __tree_.end();}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001868
Howard Hinnant756c69b2010-09-22 16:48:34 +00001869 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001870 reverse_iterator rbegin() _NOEXCEPT {return reverse_iterator(end());}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001871 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001872 const_reverse_iterator rbegin() const _NOEXCEPT
1873 {return const_reverse_iterator(end());}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001874 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001875 reverse_iterator rend() _NOEXCEPT {return reverse_iterator(begin());}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001876 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001877 const_reverse_iterator rend() const _NOEXCEPT
1878 {return const_reverse_iterator(begin());}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001879
Howard Hinnant756c69b2010-09-22 16:48:34 +00001880 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001881 const_iterator cbegin() const _NOEXCEPT {return begin();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001882 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001883 const_iterator cend() const _NOEXCEPT {return end();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001884 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001885 const_reverse_iterator crbegin() const _NOEXCEPT {return rbegin();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001886 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001887 const_reverse_iterator crend() const _NOEXCEPT {return rend();}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001888
Marshall Clow425f5752017-11-15 05:51:26 +00001889 _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001890 bool empty() const _NOEXCEPT {return __tree_.size() == 0;}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001891 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001892 size_type size() const _NOEXCEPT {return __tree_.size();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001893 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001894 size_type max_size() const _NOEXCEPT {return __tree_.max_size();}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001895
Howard Hinnant756c69b2010-09-22 16:48:34 +00001896 _LIBCPP_INLINE_VISIBILITY
Marshall Clow657cbc42016-08-17 05:58:40 +00001897 allocator_type get_allocator() const _NOEXCEPT {return allocator_type(__tree_.__alloc());}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001898 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001899 key_compare key_comp() const {return __tree_.value_comp().key_comp();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001900 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001901 value_compare value_comp() const
1902 {return value_compare(__tree_.value_comp().key_comp());}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001903
Eric Fiselierd06276b2016-03-31 02:15:15 +00001904#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant74279a52010-09-04 23:28:19 +00001905
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001906 template <class ..._Args>
Eric Fiselierd06276b2016-03-31 02:15:15 +00001907 _LIBCPP_INLINE_VISIBILITY
1908 iterator emplace(_Args&& ...__args) {
1909 return __tree_.__emplace_multi(_VSTD::forward<_Args>(__args)...);
1910 }
Howard Hinnantc51e1022010-05-11 19:42:16 +00001911
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001912 template <class ..._Args>
Eric Fiselierd06276b2016-03-31 02:15:15 +00001913 _LIBCPP_INLINE_VISIBILITY
1914 iterator emplace_hint(const_iterator __p, _Args&& ...__args) {
1915 return __tree_.__emplace_hint_multi(__p.__i_, _VSTD::forward<_Args>(__args)...);
1916 }
Howard Hinnant74279a52010-09-04 23:28:19 +00001917
Howard Hinnantc834c512011-11-29 18:15:50 +00001918 template <class _Pp,
1919 class = typename enable_if<is_constructible<value_type, _Pp>::value>::type>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001920 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc834c512011-11-29 18:15:50 +00001921 iterator insert(_Pp&& __p)
1922 {return __tree_.__insert_multi(_VSTD::forward<_Pp>(__p));}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001923
Howard Hinnantc834c512011-11-29 18:15:50 +00001924 template <class _Pp,
1925 class = typename enable_if<is_constructible<value_type, _Pp>::value>::type>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001926 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc834c512011-11-29 18:15:50 +00001927 iterator insert(const_iterator __pos, _Pp&& __p)
1928 {return __tree_.__insert_multi(__pos.__i_, _VSTD::forward<_Pp>(__p));}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001929
Eric Fiselierd6143132016-04-18 01:40:45 +00001930 _LIBCPP_INLINE_VISIBILITY
1931 iterator insert(value_type&& __v)
1932 {return __tree_.__insert_multi(_VSTD::move(__v));}
1933
1934 _LIBCPP_INLINE_VISIBILITY
1935 iterator insert(const_iterator __p, value_type&& __v)
1936 {return __tree_.__insert_multi(__p.__i_, _VSTD::move(__v));}
1937
Eric Fiseliera85b1282017-04-18 21:08:06 +00001938
1939 _LIBCPP_INLINE_VISIBILITY
1940 void insert(initializer_list<value_type> __il)
1941 {insert(__il.begin(), __il.end());}
1942
Eric Fiselierd06276b2016-03-31 02:15:15 +00001943#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001944
Howard Hinnant756c69b2010-09-22 16:48:34 +00001945 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001946 iterator insert(const value_type& __v) {return __tree_.__insert_multi(__v);}
1947
Howard Hinnant756c69b2010-09-22 16:48:34 +00001948 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001949 iterator insert(const_iterator __p, const value_type& __v)
1950 {return __tree_.__insert_multi(__p.__i_, __v);}
1951
1952 template <class _InputIterator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001953 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001954 void insert(_InputIterator __f, _InputIterator __l)
1955 {
1956 for (const_iterator __e = cend(); __f != __l; ++__f)
1957 __tree_.__insert_multi(__e.__i_, *__f);
1958 }
1959
Howard Hinnant756c69b2010-09-22 16:48:34 +00001960 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001961 iterator erase(const_iterator __p) {return __tree_.erase(__p.__i_);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001962 _LIBCPP_INLINE_VISIBILITY
Marshall Clow22ea5b82015-05-10 13:35:00 +00001963 iterator erase(iterator __p) {return __tree_.erase(__p.__i_);}
1964 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001965 size_type erase(const key_type& __k) {return __tree_.__erase_multi(__k);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001966 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001967 iterator erase(const_iterator __f, const_iterator __l)
1968 {return __tree_.erase(__f.__i_, __l.__i_);}
Erik Pilkingtonc37a3d82018-08-01 01:33:38 +00001969
1970#if _LIBCPP_STD_VER > 14
1971 _LIBCPP_INLINE_VISIBILITY
1972 iterator insert(node_type&& __nh)
1973 {
1974 _LIBCPP_ASSERT(__nh.empty() || __nh.get_allocator() == get_allocator(),
1975 "node_type with incompatible allocator passed to multimap::insert()");
1976 return __tree_.template __node_handle_insert_multi<node_type>(
1977 _VSTD::move(__nh));
1978 }
1979 _LIBCPP_INLINE_VISIBILITY
1980 iterator insert(const_iterator __hint, node_type&& __nh)
1981 {
1982 _LIBCPP_ASSERT(__nh.empty() || __nh.get_allocator() == get_allocator(),
1983 "node_type with incompatible allocator passed to multimap::insert()");
1984 return __tree_.template __node_handle_insert_multi<node_type>(
1985 __hint.__i_, _VSTD::move(__nh));
1986 }
1987 _LIBCPP_INLINE_VISIBILITY
1988 node_type extract(key_type const& __key)
1989 {
1990 return __tree_.template __node_handle_extract<node_type>(__key);
1991 }
1992 _LIBCPP_INLINE_VISIBILITY
1993 node_type extract(const_iterator __it)
1994 {
1995 return __tree_.template __node_handle_extract<node_type>(
1996 __it.__i_);
1997 }
Louis Dionned2322c82018-11-01 14:41:37 +00001998 template <class _Compare2>
Erik Pilkington82a65ad2018-10-31 17:31:35 +00001999 _LIBCPP_INLINE_VISIBILITY
Louis Dionned2322c82018-11-01 14:41:37 +00002000 void merge(multimap<key_type, mapped_type, _Compare2, allocator_type>& __source)
Erik Pilkington82a65ad2018-10-31 17:31:35 +00002001 {
2002 _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
2003 "merging container with incompatible allocator");
2004 return __tree_.__node_handle_merge_multi(__source.__tree_);
2005 }
Louis Dionned2322c82018-11-01 14:41:37 +00002006 template <class _Compare2>
Erik Pilkington82a65ad2018-10-31 17:31:35 +00002007 _LIBCPP_INLINE_VISIBILITY
Louis Dionned2322c82018-11-01 14:41:37 +00002008 void merge(multimap<key_type, mapped_type, _Compare2, allocator_type>&& __source)
Erik Pilkington82a65ad2018-10-31 17:31:35 +00002009 {
2010 _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
2011 "merging container with incompatible allocator");
2012 return __tree_.__node_handle_merge_multi(__source.__tree_);
2013 }
Louis Dionned2322c82018-11-01 14:41:37 +00002014 template <class _Compare2>
Erik Pilkington82a65ad2018-10-31 17:31:35 +00002015 _LIBCPP_INLINE_VISIBILITY
Louis Dionned2322c82018-11-01 14:41:37 +00002016 void merge(map<key_type, mapped_type, _Compare2, allocator_type>& __source)
Erik Pilkington82a65ad2018-10-31 17:31:35 +00002017 {
2018 _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
2019 "merging container with incompatible allocator");
2020 return __tree_.__node_handle_merge_multi(__source.__tree_);
2021 }
Louis Dionned2322c82018-11-01 14:41:37 +00002022 template <class _Compare2>
Erik Pilkington82a65ad2018-10-31 17:31:35 +00002023 _LIBCPP_INLINE_VISIBILITY
Louis Dionned2322c82018-11-01 14:41:37 +00002024 void merge(map<key_type, mapped_type, _Compare2, allocator_type>&& __source)
Erik Pilkington82a65ad2018-10-31 17:31:35 +00002025 {
2026 _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
2027 "merging container with incompatible allocator");
2028 return __tree_.__node_handle_merge_multi(__source.__tree_);
2029 }
Erik Pilkingtonc37a3d82018-08-01 01:33:38 +00002030#endif
2031
Howard Hinnant756c69b2010-09-22 16:48:34 +00002032 _LIBCPP_INLINE_VISIBILITY
Marshall Clowde1312a2018-08-22 04:28:43 +00002033 void clear() _NOEXCEPT {__tree_.clear();}
Howard Hinnantc51e1022010-05-11 19:42:16 +00002034
Howard Hinnant756c69b2010-09-22 16:48:34 +00002035 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00002036 void swap(multimap& __m)
2037 _NOEXCEPT_(__is_nothrow_swappable<__base>::value)
2038 {__tree_.swap(__m.__tree_);}
Howard Hinnantc51e1022010-05-11 19:42:16 +00002039
Howard Hinnant756c69b2010-09-22 16:48:34 +00002040 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002041 iterator find(const key_type& __k) {return __tree_.find(__k);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00002042 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002043 const_iterator find(const key_type& __k) const {return __tree_.find(__k);}
Marshall Clowebb57322013-08-13 22:18:47 +00002044#if _LIBCPP_STD_VER > 11
2045 template <typename _K2>
2046 _LIBCPP_INLINE_VISIBILITY
2047 typename enable_if<__is_transparent<_Compare, _K2>::value,iterator>::type
2048 find(const _K2& __k) {return __tree_.find(__k);}
2049 template <typename _K2>
2050 _LIBCPP_INLINE_VISIBILITY
2051 typename enable_if<__is_transparent<_Compare, _K2>::value,const_iterator>::type
2052 find(const _K2& __k) const {return __tree_.find(__k);}
2053#endif
2054
Howard Hinnant756c69b2010-09-22 16:48:34 +00002055 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002056 size_type count(const key_type& __k) const
2057 {return __tree_.__count_multi(__k);}
Marshall Clowe6a5f522014-08-24 23:54:16 +00002058#if _LIBCPP_STD_VER > 11
2059 template <typename _K2>
2060 _LIBCPP_INLINE_VISIBILITY
2061 typename enable_if<__is_transparent<_Compare, _K2>::value,size_type>::type
Marshall Clow141e47b2015-06-30 18:15:41 +00002062 count(const _K2& __k) const {return __tree_.__count_multi(__k);}
Marshall Clowe6a5f522014-08-24 23:54:16 +00002063#endif
Zoe Carver3ffbab12019-07-16 03:21:01 +00002064
2065#if _LIBCPP_STD_VER > 17
2066 _LIBCPP_INLINE_VISIBILITY
2067 bool contains(const key_type& __k) const {return find(__k) != end();}
2068#endif // _LIBCPP_STD_VER > 17
2069
Howard Hinnant756c69b2010-09-22 16:48:34 +00002070 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002071 iterator lower_bound(const key_type& __k)
2072 {return __tree_.lower_bound(__k);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00002073 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002074 const_iterator lower_bound(const key_type& __k) const
2075 {return __tree_.lower_bound(__k);}
Marshall Clowebb57322013-08-13 22:18:47 +00002076#if _LIBCPP_STD_VER > 11
2077 template <typename _K2>
2078 _LIBCPP_INLINE_VISIBILITY
2079 typename enable_if<__is_transparent<_Compare, _K2>::value,iterator>::type
2080 lower_bound(const _K2& __k) {return __tree_.lower_bound(__k);}
2081
2082 template <typename _K2>
2083 _LIBCPP_INLINE_VISIBILITY
2084 typename enable_if<__is_transparent<_Compare, _K2>::value,const_iterator>::type
2085 lower_bound(const _K2& __k) const {return __tree_.lower_bound(__k);}
2086#endif
2087
Howard Hinnant756c69b2010-09-22 16:48:34 +00002088 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002089 iterator upper_bound(const key_type& __k)
2090 {return __tree_.upper_bound(__k);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00002091 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002092 const_iterator upper_bound(const key_type& __k) const
2093 {return __tree_.upper_bound(__k);}
Marshall Clowebb57322013-08-13 22:18:47 +00002094#if _LIBCPP_STD_VER > 11
2095 template <typename _K2>
2096 _LIBCPP_INLINE_VISIBILITY
2097 typename enable_if<__is_transparent<_Compare, _K2>::value,iterator>::type
2098 upper_bound(const _K2& __k) {return __tree_.upper_bound(__k);}
2099 template <typename _K2>
2100 _LIBCPP_INLINE_VISIBILITY
2101 typename enable_if<__is_transparent<_Compare, _K2>::value,const_iterator>::type
2102 upper_bound(const _K2& __k) const {return __tree_.upper_bound(__k);}
2103#endif
2104
Howard Hinnant756c69b2010-09-22 16:48:34 +00002105 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002106 pair<iterator,iterator> equal_range(const key_type& __k)
2107 {return __tree_.__equal_range_multi(__k);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00002108 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002109 pair<const_iterator,const_iterator> equal_range(const key_type& __k) const
2110 {return __tree_.__equal_range_multi(__k);}
Marshall Clowebb57322013-08-13 22:18:47 +00002111#if _LIBCPP_STD_VER > 11
2112 template <typename _K2>
2113 _LIBCPP_INLINE_VISIBILITY
2114 typename enable_if<__is_transparent<_Compare, _K2>::value,pair<iterator,iterator>>::type
2115 equal_range(const _K2& __k) {return __tree_.__equal_range_multi(__k);}
2116 template <typename _K2>
2117 _LIBCPP_INLINE_VISIBILITY
2118 typename enable_if<__is_transparent<_Compare, _K2>::value,pair<const_iterator,const_iterator>>::type
2119 equal_range(const _K2& __k) const {return __tree_.__equal_range_multi(__k);}
2120#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00002121
2122private:
2123 typedef typename __base::__node __node;
2124 typedef typename __base::__node_allocator __node_allocator;
2125 typedef typename __base::__node_pointer __node_pointer;
Eric Fiseliera92b0732016-02-20 07:12:17 +00002126
Howard Hinnantc834c512011-11-29 18:15:50 +00002127 typedef __map_node_destructor<__node_allocator> _Dp;
2128 typedef unique_ptr<__node, _Dp> __node_holder;
Howard Hinnantc51e1022010-05-11 19:42:16 +00002129};
2130
Louis Dionned23a5f22019-06-20 19:32:00 +00002131#ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES
2132template<class _InputIterator, class _Compare = less<__iter_key_type<_InputIterator>>,
2133 class _Allocator = allocator<__iter_to_alloc_type<_InputIterator>>,
Louis Dionne6c7da9a2019-07-19 17:13:39 +00002134 class = _EnableIf<!__is_allocator<_Compare>::value, void>,
2135 class = _EnableIf<__is_allocator<_Allocator>::value, void>>
Louis Dionned23a5f22019-06-20 19:32:00 +00002136multimap(_InputIterator, _InputIterator, _Compare = _Compare(), _Allocator = _Allocator())
2137 -> multimap<__iter_key_type<_InputIterator>, __iter_mapped_type<_InputIterator>, _Compare, _Allocator>;
2138
2139template<class _Key, class _Tp, class _Compare = less<remove_const_t<_Key>>,
2140 class _Allocator = allocator<pair<const _Key, _Tp>>,
Louis Dionne6c7da9a2019-07-19 17:13:39 +00002141 class = _EnableIf<!__is_allocator<_Compare>::value, void>,
2142 class = _EnableIf<__is_allocator<_Allocator>::value, void>>
Louis Dionned23a5f22019-06-20 19:32:00 +00002143multimap(initializer_list<pair<_Key, _Tp>>, _Compare = _Compare(), _Allocator = _Allocator())
2144 -> multimap<remove_const_t<_Key>, _Tp, _Compare, _Allocator>;
2145
2146template<class _InputIterator, class _Allocator,
Louis Dionne6c7da9a2019-07-19 17:13:39 +00002147 class = _EnableIf<__is_allocator<_Allocator>::value, void>>
Louis Dionned23a5f22019-06-20 19:32:00 +00002148multimap(_InputIterator, _InputIterator, _Allocator)
2149 -> multimap<__iter_key_type<_InputIterator>, __iter_mapped_type<_InputIterator>,
2150 less<__iter_key_type<_InputIterator>>, _Allocator>;
2151
2152template<class _Key, class _Tp, class _Allocator,
Louis Dionne6c7da9a2019-07-19 17:13:39 +00002153 class = _EnableIf<__is_allocator<_Allocator>::value, void>>
Louis Dionned23a5f22019-06-20 19:32:00 +00002154multimap(initializer_list<pair<_Key, _Tp>>, _Allocator)
2155 -> multimap<remove_const_t<_Key>, _Tp, less<remove_const_t<_Key>>, _Allocator>;
2156#endif
2157
Eric Fiselierd06276b2016-03-31 02:15:15 +00002158#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00002159template <class _Key, class _Tp, class _Compare, class _Allocator>
2160multimap<_Key, _Tp, _Compare, _Allocator>::multimap(multimap&& __m, const allocator_type& __a)
Marshall Clow657cbc42016-08-17 05:58:40 +00002161 : __tree_(_VSTD::move(__m.__tree_), typename __base::allocator_type(__a))
Howard Hinnantc51e1022010-05-11 19:42:16 +00002162{
2163 if (__a != __m.get_allocator())
2164 {
2165 const_iterator __e = cend();
2166 while (!__m.empty())
2167 __tree_.__insert_multi(__e.__i_,
Erik Pilkingtond3fe2992018-06-04 20:38:23 +00002168 _VSTD::move(__m.__tree_.remove(__m.begin().__i_)->__value_.__move()));
Howard Hinnantc51e1022010-05-11 19:42:16 +00002169 }
2170}
Eric Fiselierd06276b2016-03-31 02:15:15 +00002171#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00002172
2173template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00002174inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002175bool
2176operator==(const multimap<_Key, _Tp, _Compare, _Allocator>& __x,
2177 const multimap<_Key, _Tp, _Compare, _Allocator>& __y)
2178{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00002179 return __x.size() == __y.size() && _VSTD::equal(__x.begin(), __x.end(), __y.begin());
Howard Hinnantc51e1022010-05-11 19:42:16 +00002180}
2181
2182template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00002183inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002184bool
2185operator< (const multimap<_Key, _Tp, _Compare, _Allocator>& __x,
2186 const multimap<_Key, _Tp, _Compare, _Allocator>& __y)
2187{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00002188 return _VSTD::lexicographical_compare(__x.begin(), __x.end(), __y.begin(), __y.end());
Howard Hinnantc51e1022010-05-11 19:42:16 +00002189}
2190
2191template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00002192inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002193bool
2194operator!=(const multimap<_Key, _Tp, _Compare, _Allocator>& __x,
2195 const multimap<_Key, _Tp, _Compare, _Allocator>& __y)
2196{
2197 return !(__x == __y);
2198}
2199
2200template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00002201inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002202bool
2203operator> (const multimap<_Key, _Tp, _Compare, _Allocator>& __x,
2204 const multimap<_Key, _Tp, _Compare, _Allocator>& __y)
2205{
2206 return __y < __x;
2207}
2208
2209template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00002210inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002211bool
2212operator>=(const multimap<_Key, _Tp, _Compare, _Allocator>& __x,
2213 const multimap<_Key, _Tp, _Compare, _Allocator>& __y)
2214{
2215 return !(__x < __y);
2216}
2217
2218template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00002219inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002220bool
2221operator<=(const multimap<_Key, _Tp, _Compare, _Allocator>& __x,
2222 const multimap<_Key, _Tp, _Compare, _Allocator>& __y)
2223{
2224 return !(__y < __x);
2225}
2226
2227template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00002228inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002229void
2230swap(multimap<_Key, _Tp, _Compare, _Allocator>& __x,
2231 multimap<_Key, _Tp, _Compare, _Allocator>& __y)
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00002232 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
Howard Hinnantc51e1022010-05-11 19:42:16 +00002233{
2234 __x.swap(__y);
2235}
2236
Marshall Clow29b53f22018-12-14 18:49:35 +00002237#if _LIBCPP_STD_VER > 17
2238template <class _Key, class _Tp, class _Compare, class _Allocator, class _Predicate>
2239inline _LIBCPP_INLINE_VISIBILITY
2240void erase_if(multimap<_Key, _Tp, _Compare, _Allocator>& __c, _Predicate __pred)
2241{ __libcpp_erase_if_container(__c, __pred); }
2242#endif
2243
Howard Hinnantc51e1022010-05-11 19:42:16 +00002244_LIBCPP_END_NAMESPACE_STD
2245
2246#endif // _LIBCPP_MAP