blob: 616bb46cfccd61e06afd0642f543ab87f3714b09 [file] [log] [blame]
Howard Hinnantc51e1022010-05-11 19:42:16 +00001// -*- C++ -*-
2//===----------------------------- map ------------------------------------===//
3//
Howard Hinnantc566dc32010-05-11 21:36:01 +00004// The LLVM Compiler Infrastructure
Howard Hinnantc51e1022010-05-11 19:42:16 +00005//
Howard Hinnantee11c312010-11-16 22:09:02 +00006// This file is dual licensed under the MIT and the University of Illinois Open
7// Source Licenses. See LICENSE.TXT for details.
Howard Hinnantc51e1022010-05-11 19:42:16 +00008//
9//===----------------------------------------------------------------------===//
10
11#ifndef _LIBCPP_MAP
12#define _LIBCPP_MAP
13
14/*
15
16 map synopsis
17
18namespace std
19{
20
21template <class Key, class T, class Compare = less<Key>,
22 class Allocator = allocator<pair<const Key, T>>>
23class map
24{
25public:
26 // types:
27 typedef Key key_type;
28 typedef T mapped_type;
29 typedef pair<const key_type, mapped_type> value_type;
30 typedef Compare key_compare;
31 typedef Allocator allocator_type;
32 typedef typename allocator_type::reference reference;
33 typedef typename allocator_type::const_reference const_reference;
34 typedef typename allocator_type::pointer pointer;
35 typedef typename allocator_type::const_pointer const_pointer;
36 typedef typename allocator_type::size_type size_type;
37 typedef typename allocator_type::difference_type difference_type;
38
39 typedef implementation-defined iterator;
40 typedef implementation-defined const_iterator;
41 typedef std::reverse_iterator<iterator> reverse_iterator;
42 typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
Erik Pilkingtonc37a3d82018-08-01 01:33:38 +000043 typedef unspecified node_type; // C++17
44 typedef INSERT_RETURN_TYPE<iterator, node_type> insert_return_type; // C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +000045
46 class value_compare
47 : public binary_function<value_type, value_type, bool>
48 {
49 friend class map;
50 protected:
51 key_compare comp;
52
53 value_compare(key_compare c);
54 public:
55 bool operator()(const value_type& x, const value_type& y) const;
56 };
57
58 // construct/copy/destroy:
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +000059 map()
60 noexcept(
61 is_nothrow_default_constructible<allocator_type>::value &&
62 is_nothrow_default_constructible<key_compare>::value &&
63 is_nothrow_copy_constructible<key_compare>::value);
Howard Hinnantc51e1022010-05-11 19:42:16 +000064 explicit map(const key_compare& comp);
65 map(const key_compare& comp, const allocator_type& a);
66 template <class InputIterator>
67 map(InputIterator first, InputIterator last,
68 const key_compare& comp = key_compare());
69 template <class InputIterator>
70 map(InputIterator first, InputIterator last,
71 const key_compare& comp, const allocator_type& a);
72 map(const map& m);
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +000073 map(map&& m)
74 noexcept(
75 is_nothrow_move_constructible<allocator_type>::value &&
76 is_nothrow_move_constructible<key_compare>::value);
Howard Hinnantc51e1022010-05-11 19:42:16 +000077 explicit map(const allocator_type& a);
78 map(const map& m, const allocator_type& a);
79 map(map&& m, const allocator_type& a);
80 map(initializer_list<value_type> il, const key_compare& comp = key_compare());
81 map(initializer_list<value_type> il, const key_compare& comp, const allocator_type& a);
Marshall Clow300abfb2013-09-11 01:15:47 +000082 template <class InputIterator>
83 map(InputIterator first, InputIterator last, const allocator_type& a)
84 : map(first, last, Compare(), a) {} // C++14
85 map(initializer_list<value_type> il, const allocator_type& a)
86 : map(il, Compare(), a) {} // C++14
87 ~map();
Howard Hinnantc51e1022010-05-11 19:42:16 +000088
89 map& operator=(const map& m);
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +000090 map& operator=(map&& m)
91 noexcept(
92 allocator_type::propagate_on_container_move_assignment::value &&
93 is_nothrow_move_assignable<allocator_type>::value &&
Howard Hinnantf95f4f52011-06-04 15:22:34 +000094 is_nothrow_move_assignable<key_compare>::value);
Howard Hinnantc51e1022010-05-11 19:42:16 +000095 map& operator=(initializer_list<value_type> il);
96
97 // iterators:
Howard Hinnantf95f4f52011-06-04 15:22:34 +000098 iterator begin() noexcept;
99 const_iterator begin() const noexcept;
100 iterator end() noexcept;
101 const_iterator end() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000102
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000103 reverse_iterator rbegin() noexcept;
104 const_reverse_iterator rbegin() const noexcept;
105 reverse_iterator rend() noexcept;
106 const_reverse_iterator rend() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000107
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000108 const_iterator cbegin() const noexcept;
109 const_iterator cend() const noexcept;
110 const_reverse_iterator crbegin() const noexcept;
111 const_reverse_iterator crend() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000112
113 // capacity:
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000114 bool empty() const noexcept;
115 size_type size() const noexcept;
116 size_type max_size() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000117
118 // element access:
119 mapped_type& operator[](const key_type& k);
120 mapped_type& operator[](key_type&& k);
121
122 mapped_type& at(const key_type& k);
123 const mapped_type& at(const key_type& k) const;
124
125 // modifiers:
126 template <class... Args>
127 pair<iterator, bool> emplace(Args&&... args);
128 template <class... Args>
129 iterator emplace_hint(const_iterator position, Args&&... args);
130 pair<iterator, bool> insert(const value_type& v);
Marshall Clowd430d022016-01-05 19:32:41 +0000131 pair<iterator, bool> insert( value_type&& v); // C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000132 template <class P>
133 pair<iterator, bool> insert(P&& p);
134 iterator insert(const_iterator position, const value_type& v);
Marshall Clowd430d022016-01-05 19:32:41 +0000135 iterator insert(const_iterator position, value_type&& v); // C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000136 template <class P>
137 iterator insert(const_iterator position, P&& p);
138 template <class InputIterator>
139 void insert(InputIterator first, InputIterator last);
140 void insert(initializer_list<value_type> il);
141
Erik Pilkingtonc37a3d82018-08-01 01:33:38 +0000142 node_type extract(const_iterator position); // C++17
143 node_type extract(const key_type& x); // C++17
144 insert_return_type insert(node_type&& nh); // C++17
145 iterator insert(const_iterator hint, node_type&& nh); // C++17
146
Marshall Clow3223db82015-07-07 03:37:33 +0000147 template <class... Args>
148 pair<iterator, bool> try_emplace(const key_type& k, Args&&... args); // C++17
149 template <class... Args>
150 pair<iterator, bool> try_emplace(key_type&& k, Args&&... args); // C++17
151 template <class... Args>
152 iterator try_emplace(const_iterator hint, const key_type& k, Args&&... args); // C++17
153 template <class... Args>
154 iterator try_emplace(const_iterator hint, key_type&& k, Args&&... args); // C++17
155 template <class M>
156 pair<iterator, bool> insert_or_assign(const key_type& k, M&& obj); // C++17
157 template <class M>
158 pair<iterator, bool> insert_or_assign(key_type&& k, M&& obj); // C++17
159 template <class M>
160 iterator insert_or_assign(const_iterator hint, const key_type& k, M&& obj); // C++17
161 template <class M>
162 iterator insert_or_assign(const_iterator hint, key_type&& k, M&& obj); // C++17
163
Howard Hinnantc51e1022010-05-11 19:42:16 +0000164 iterator erase(const_iterator position);
Marshall Clow22ea5b82015-05-10 13:35:00 +0000165 iterator erase(iterator position); // C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000166 size_type erase(const key_type& k);
167 iterator erase(const_iterator first, const_iterator last);
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000168 void clear() noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000169
Erik Pilkington82a65ad2018-10-31 17:31:35 +0000170 template<class C2>
171 void merge(map<Key, T, C2, Allocator>& source); // C++17
172 template<class C2>
173 void merge(map<Key, T, C2, Allocator>&& source); // C++17
174 template<class C2>
175 void merge(multimap<Key, T, C2, Allocator>& source); // C++17
176 template<class C2>
177 void merge(multimap<Key, T, C2, Allocator>&& source); // C++17
178
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000179 void swap(map& m)
Marshall Clow8982dcd2015-07-13 20:04:56 +0000180 noexcept(allocator_traits<allocator_type>::is_always_equal::value &&
Eric Fiselier6bfed252016-04-21 23:38:59 +0000181 is_nothrow_swappable<key_compare>::value); // C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000182
183 // observers:
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000184 allocator_type get_allocator() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000185 key_compare key_comp() const;
186 value_compare value_comp() const;
187
188 // map operations:
189 iterator find(const key_type& k);
190 const_iterator find(const key_type& k) const;
Marshall Clowebb57322013-08-13 22:18:47 +0000191 template<typename K>
192 iterator find(const K& x); // C++14
193 template<typename K>
194 const_iterator find(const K& x) const; // C++14
195 template<typename K>
Marshall Clowe6a5f522014-08-24 23:54:16 +0000196 size_type count(const K& x) const; // C++14
Marshall Clowebb57322013-08-13 22:18:47 +0000197
Howard Hinnantc51e1022010-05-11 19:42:16 +0000198 size_type count(const key_type& k) const;
199 iterator lower_bound(const key_type& k);
200 const_iterator lower_bound(const key_type& k) const;
Marshall Clowebb57322013-08-13 22:18:47 +0000201 template<typename K>
202 iterator lower_bound(const K& x); // C++14
203 template<typename K>
204 const_iterator lower_bound(const K& x) const; // C++14
205
Howard Hinnantc51e1022010-05-11 19:42:16 +0000206 iterator upper_bound(const key_type& k);
207 const_iterator upper_bound(const key_type& k) const;
Marshall Clowebb57322013-08-13 22:18:47 +0000208 template<typename K>
209 iterator upper_bound(const K& x); // C++14
210 template<typename K>
211 const_iterator upper_bound(const K& x) const; // C++14
212
Howard Hinnantc51e1022010-05-11 19:42:16 +0000213 pair<iterator,iterator> equal_range(const key_type& k);
214 pair<const_iterator,const_iterator> equal_range(const key_type& k) const;
Marshall Clowebb57322013-08-13 22:18:47 +0000215 template<typename K>
216 pair<iterator,iterator> equal_range(const K& x); // C++14
217 template<typename K>
218 pair<const_iterator,const_iterator> equal_range(const K& x) const; // C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000219};
220
221template <class Key, class T, class Compare, class Allocator>
222bool
223operator==(const map<Key, T, Compare, Allocator>& x,
224 const map<Key, T, Compare, Allocator>& y);
225
226template <class Key, class T, class Compare, class Allocator>
227bool
228operator< (const map<Key, T, Compare, Allocator>& x,
229 const map<Key, T, Compare, Allocator>& y);
230
231template <class Key, class T, class Compare, class Allocator>
232bool
233operator!=(const map<Key, T, Compare, Allocator>& x,
234 const map<Key, T, Compare, Allocator>& y);
235
236template <class Key, class T, class Compare, class Allocator>
237bool
238operator> (const map<Key, T, Compare, Allocator>& x,
239 const map<Key, T, Compare, Allocator>& y);
240
241template <class Key, class T, class Compare, class Allocator>
242bool
243operator>=(const map<Key, T, Compare, Allocator>& x,
244 const map<Key, T, Compare, Allocator>& y);
245
246template <class Key, class T, class Compare, class Allocator>
247bool
248operator<=(const map<Key, T, Compare, Allocator>& x,
249 const map<Key, T, Compare, Allocator>& y);
250
251// specialized algorithms:
252template <class Key, class T, class Compare, class Allocator>
253void
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000254swap(map<Key, T, Compare, Allocator>& x, map<Key, T, Compare, Allocator>& y)
255 noexcept(noexcept(x.swap(y)));
Howard Hinnantc51e1022010-05-11 19:42:16 +0000256
Marshall Clow29b53f22018-12-14 18:49:35 +0000257template <class Key, class T, class Compare, class Allocator, class Predicate>
258 void erase_if(map<Key, T, Compare, Allocator>& c, Predicate pred); // C++20
259
260
Howard Hinnantc51e1022010-05-11 19:42:16 +0000261template <class Key, class T, class Compare = less<Key>,
262 class Allocator = allocator<pair<const Key, T>>>
263class multimap
264{
265public:
266 // types:
267 typedef Key key_type;
268 typedef T mapped_type;
269 typedef pair<const key_type,mapped_type> value_type;
270 typedef Compare key_compare;
271 typedef Allocator allocator_type;
272 typedef typename allocator_type::reference reference;
273 typedef typename allocator_type::const_reference const_reference;
274 typedef typename allocator_type::size_type size_type;
275 typedef typename allocator_type::difference_type difference_type;
276 typedef typename allocator_type::pointer pointer;
277 typedef typename allocator_type::const_pointer const_pointer;
278
279 typedef implementation-defined iterator;
280 typedef implementation-defined const_iterator;
281 typedef std::reverse_iterator<iterator> reverse_iterator;
282 typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
Erik Pilkingtonc37a3d82018-08-01 01:33:38 +0000283 typedef unspecified node_type; // C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000284
285 class value_compare
286 : public binary_function<value_type,value_type,bool>
287 {
288 friend class multimap;
289 protected:
290 key_compare comp;
291 value_compare(key_compare c);
292 public:
293 bool operator()(const value_type& x, const value_type& y) const;
294 };
295
296 // construct/copy/destroy:
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000297 multimap()
298 noexcept(
299 is_nothrow_default_constructible<allocator_type>::value &&
300 is_nothrow_default_constructible<key_compare>::value &&
301 is_nothrow_copy_constructible<key_compare>::value);
302 explicit multimap(const key_compare& comp);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000303 multimap(const key_compare& comp, const allocator_type& a);
304 template <class InputIterator>
305 multimap(InputIterator first, InputIterator last, const key_compare& comp);
306 template <class InputIterator>
307 multimap(InputIterator first, InputIterator last, const key_compare& comp,
308 const allocator_type& a);
309 multimap(const multimap& m);
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000310 multimap(multimap&& m)
311 noexcept(
312 is_nothrow_move_constructible<allocator_type>::value &&
313 is_nothrow_move_constructible<key_compare>::value);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000314 explicit multimap(const allocator_type& a);
315 multimap(const multimap& m, const allocator_type& a);
316 multimap(multimap&& m, const allocator_type& a);
317 multimap(initializer_list<value_type> il, const key_compare& comp = key_compare());
318 multimap(initializer_list<value_type> il, const key_compare& comp,
319 const allocator_type& a);
Marshall Clow300abfb2013-09-11 01:15:47 +0000320 template <class InputIterator>
321 multimap(InputIterator first, InputIterator last, const allocator_type& a)
322 : multimap(first, last, Compare(), a) {} // C++14
323 multimap(initializer_list<value_type> il, const allocator_type& a)
324 : multimap(il, Compare(), a) {} // C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000325 ~multimap();
326
327 multimap& operator=(const multimap& m);
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000328 multimap& operator=(multimap&& m)
329 noexcept(
330 allocator_type::propagate_on_container_move_assignment::value &&
331 is_nothrow_move_assignable<allocator_type>::value &&
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000332 is_nothrow_move_assignable<key_compare>::value);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000333 multimap& operator=(initializer_list<value_type> il);
334
335 // iterators:
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000336 iterator begin() noexcept;
337 const_iterator begin() const noexcept;
338 iterator end() noexcept;
339 const_iterator end() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000340
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000341 reverse_iterator rbegin() noexcept;
342 const_reverse_iterator rbegin() const noexcept;
343 reverse_iterator rend() noexcept;
344 const_reverse_iterator rend() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000345
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000346 const_iterator cbegin() const noexcept;
347 const_iterator cend() const noexcept;
348 const_reverse_iterator crbegin() const noexcept;
349 const_reverse_iterator crend() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000350
351 // capacity:
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000352 bool empty() const noexcept;
353 size_type size() const noexcept;
354 size_type max_size() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000355
356 // modifiers:
357 template <class... Args>
358 iterator emplace(Args&&... args);
359 template <class... Args>
360 iterator emplace_hint(const_iterator position, Args&&... args);
361 iterator insert(const value_type& v);
Marshall Clowd430d022016-01-05 19:32:41 +0000362 iterator insert( value_type&& v); // C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000363 template <class P>
364 iterator insert(P&& p);
365 iterator insert(const_iterator position, const value_type& v);
Marshall Clowd430d022016-01-05 19:32:41 +0000366 iterator insert(const_iterator position, value_type&& v); // C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000367 template <class P>
368 iterator insert(const_iterator position, P&& p);
369 template <class InputIterator>
370 void insert(InputIterator first, InputIterator last);
371 void insert(initializer_list<value_type> il);
372
Erik Pilkingtonc37a3d82018-08-01 01:33:38 +0000373 node_type extract(const_iterator position); // C++17
374 node_type extract(const key_type& x); // C++17
375 iterator insert(node_type&& nh); // C++17
376 iterator insert(const_iterator hint, node_type&& nh); // C++17
377
Howard Hinnantc51e1022010-05-11 19:42:16 +0000378 iterator erase(const_iterator position);
Marshall Clow22ea5b82015-05-10 13:35:00 +0000379 iterator erase(iterator position); // C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000380 size_type erase(const key_type& k);
381 iterator erase(const_iterator first, const_iterator last);
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000382 void clear() noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000383
Erik Pilkington82a65ad2018-10-31 17:31:35 +0000384 template<class C2>
385 void merge(multimap<Key, T, C2, Allocator>& source); // C++17
386 template<class C2>
387 void merge(multimap<Key, T, C2, Allocator>&& source); // C++17
388 template<class C2>
389 void merge(map<Key, T, C2, Allocator>& source); // C++17
390 template<class C2>
391 void merge(map<Key, T, C2, Allocator>&& source); // C++17
392
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000393 void swap(multimap& m)
Marshall Clow8982dcd2015-07-13 20:04:56 +0000394 noexcept(allocator_traits<allocator_type>::is_always_equal::value &&
Eric Fiselier6bfed252016-04-21 23:38:59 +0000395 is_nothrow_swappable<key_compare>::value); // C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000396
397 // observers:
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000398 allocator_type get_allocator() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000399 key_compare key_comp() const;
400 value_compare value_comp() const;
401
402 // map operations:
403 iterator find(const key_type& k);
404 const_iterator find(const key_type& k) const;
Marshall Clowebb57322013-08-13 22:18:47 +0000405 template<typename K>
406 iterator find(const K& x); // C++14
407 template<typename K>
408 const_iterator find(const K& x) const; // C++14
409 template<typename K>
Marshall Clowe6a5f522014-08-24 23:54:16 +0000410 size_type count(const K& x) const; // C++14
Marshall Clowebb57322013-08-13 22:18:47 +0000411
Howard Hinnantc51e1022010-05-11 19:42:16 +0000412 size_type count(const key_type& k) const;
413 iterator lower_bound(const key_type& k);
414 const_iterator lower_bound(const key_type& k) const;
Marshall Clowebb57322013-08-13 22:18:47 +0000415 template<typename K>
416 iterator lower_bound(const K& x); // C++14
417 template<typename K>
418 const_iterator lower_bound(const K& x) const; // C++14
419
Howard Hinnantc51e1022010-05-11 19:42:16 +0000420 iterator upper_bound(const key_type& k);
421 const_iterator upper_bound(const key_type& k) const;
Marshall Clowebb57322013-08-13 22:18:47 +0000422 template<typename K>
423 iterator upper_bound(const K& x); // C++14
424 template<typename K>
425 const_iterator upper_bound(const K& x) const; // C++14
426
Howard Hinnantc51e1022010-05-11 19:42:16 +0000427 pair<iterator,iterator> equal_range(const key_type& k);
428 pair<const_iterator,const_iterator> equal_range(const key_type& k) const;
Marshall Clowebb57322013-08-13 22:18:47 +0000429 template<typename K>
430 pair<iterator,iterator> equal_range(const K& x); // C++14
431 template<typename K>
432 pair<const_iterator,const_iterator> equal_range(const K& x) const; // C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000433};
434
435template <class Key, class T, class Compare, class Allocator>
436bool
437operator==(const multimap<Key, T, Compare, Allocator>& x,
438 const multimap<Key, T, Compare, Allocator>& y);
439
440template <class Key, class T, class Compare, class Allocator>
441bool
442operator< (const multimap<Key, T, Compare, Allocator>& x,
443 const multimap<Key, T, Compare, Allocator>& y);
444
445template <class Key, class T, class Compare, class Allocator>
446bool
447operator!=(const multimap<Key, T, Compare, Allocator>& x,
448 const multimap<Key, T, Compare, Allocator>& y);
449
450template <class Key, class T, class Compare, class Allocator>
451bool
452operator> (const multimap<Key, T, Compare, Allocator>& x,
453 const multimap<Key, T, Compare, Allocator>& y);
454
455template <class Key, class T, class Compare, class Allocator>
456bool
457operator>=(const multimap<Key, T, Compare, Allocator>& x,
458 const multimap<Key, T, Compare, Allocator>& y);
459
460template <class Key, class T, class Compare, class Allocator>
461bool
462operator<=(const multimap<Key, T, Compare, Allocator>& x,
463 const multimap<Key, T, Compare, Allocator>& y);
464
465// specialized algorithms:
466template <class Key, class T, class Compare, class Allocator>
467void
468swap(multimap<Key, T, Compare, Allocator>& x,
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000469 multimap<Key, T, Compare, Allocator>& y)
470 noexcept(noexcept(x.swap(y)));
Howard Hinnantc51e1022010-05-11 19:42:16 +0000471
Marshall Clow29b53f22018-12-14 18:49:35 +0000472template <class Key, class T, class Compare, class Allocator, class Predicate>
473 void erase_if(multimap<Key, T, Compare, Allocator>& c, Predicate pred); // C++20
474
Howard Hinnantc51e1022010-05-11 19:42:16 +0000475} // std
476
477*/
478
479#include <__config>
480#include <__tree>
Erik Pilkingtonc37a3d82018-08-01 01:33:38 +0000481#include <__node_handle>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000482#include <iterator>
483#include <memory>
484#include <utility>
485#include <functional>
486#include <initializer_list>
Eric Fiselierf7394302015-06-13 07:08:02 +0000487#include <type_traits>
Marshall Clow0a1e7502018-09-12 19:41:40 +0000488#include <version>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000489
Howard Hinnantaaaa52b2011-10-17 20:05:10 +0000490#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000491#pragma GCC system_header
Howard Hinnantaaaa52b2011-10-17 20:05:10 +0000492#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000493
494_LIBCPP_BEGIN_NAMESPACE_STD
495
Louis Dionne878a3a82018-12-06 21:46:17 +0000496template <class _Key, class _CP, class _Compare,
497 bool = is_empty<_Compare>::value && !__libcpp_is_final<_Compare>::value>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000498class __map_value_compare
499 : private _Compare
500{
Howard Hinnantc51e1022010-05-11 19:42:16 +0000501public:
Howard Hinnant756c69b2010-09-22 16:48:34 +0000502 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000503 __map_value_compare()
504 _NOEXCEPT_(is_nothrow_default_constructible<_Compare>::value)
505 : _Compare() {}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000506 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000507 __map_value_compare(_Compare c)
508 _NOEXCEPT_(is_nothrow_copy_constructible<_Compare>::value)
509 : _Compare(c) {}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000510 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000511 const _Compare& key_comp() const _NOEXCEPT {return *this;}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000512 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000513 bool operator()(const _CP& __x, const _CP& __y) const
Erik Pilkingtond3fe2992018-06-04 20:38:23 +0000514 {return static_cast<const _Compare&>(*this)(__x.__get_value().first, __y.__get_value().first);}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000515 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000516 bool operator()(const _CP& __x, const _Key& __y) const
Erik Pilkingtond3fe2992018-06-04 20:38:23 +0000517 {return static_cast<const _Compare&>(*this)(__x.__get_value().first, __y);}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000518 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000519 bool operator()(const _Key& __x, const _CP& __y) const
Erik Pilkingtond3fe2992018-06-04 20:38:23 +0000520 {return static_cast<const _Compare&>(*this)(__x, __y.__get_value().first);}
Marshall Clow8982dcd2015-07-13 20:04:56 +0000521 void swap(__map_value_compare&__y)
522 _NOEXCEPT_(__is_nothrow_swappable<_Compare>::value)
523 {
Eric Fiselier68b5f0b2017-04-13 00:34:24 +0000524 using _VSTD::swap;
525 swap(static_cast<_Compare&>(*this), static_cast<_Compare&>(__y));
Marshall Clow8982dcd2015-07-13 20:04:56 +0000526 }
Marshall Clowebb57322013-08-13 22:18:47 +0000527
528#if _LIBCPP_STD_VER > 11
529 template <typename _K2>
530 _LIBCPP_INLINE_VISIBILITY
531 typename enable_if<__is_transparent<_Compare, _K2>::value, bool>::type
532 operator () ( const _K2& __x, const _CP& __y ) const
Erik Pilkingtond3fe2992018-06-04 20:38:23 +0000533 {return static_cast<const _Compare&>(*this) (__x, __y.__get_value().first);}
Marshall Clowebb57322013-08-13 22:18:47 +0000534
535 template <typename _K2>
536 _LIBCPP_INLINE_VISIBILITY
537 typename enable_if<__is_transparent<_Compare, _K2>::value, bool>::type
538 operator () (const _CP& __x, const _K2& __y) const
Erik Pilkingtond3fe2992018-06-04 20:38:23 +0000539 {return static_cast<const _Compare&>(*this) (__x.__get_value().first, __y);}
Marshall Clowebb57322013-08-13 22:18:47 +0000540#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000541};
542
Howard Hinnant90b91592013-07-05 18:06:00 +0000543template <class _Key, class _CP, class _Compare>
544class __map_value_compare<_Key, _CP, _Compare, false>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000545{
546 _Compare comp;
547
Howard Hinnantc51e1022010-05-11 19:42:16 +0000548public:
Howard Hinnant756c69b2010-09-22 16:48:34 +0000549 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000550 __map_value_compare()
551 _NOEXCEPT_(is_nothrow_default_constructible<_Compare>::value)
552 : comp() {}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000553 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000554 __map_value_compare(_Compare c)
555 _NOEXCEPT_(is_nothrow_copy_constructible<_Compare>::value)
556 : comp(c) {}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000557 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000558 const _Compare& key_comp() const _NOEXCEPT {return comp;}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000559
Howard Hinnant756c69b2010-09-22 16:48:34 +0000560 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000561 bool operator()(const _CP& __x, const _CP& __y) const
Erik Pilkingtond3fe2992018-06-04 20:38:23 +0000562 {return comp(__x.__get_value().first, __y.__get_value().first);}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000563 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000564 bool operator()(const _CP& __x, const _Key& __y) const
Erik Pilkingtond3fe2992018-06-04 20:38:23 +0000565 {return comp(__x.__get_value().first, __y);}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000566 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000567 bool operator()(const _Key& __x, const _CP& __y) const
Erik Pilkingtond3fe2992018-06-04 20:38:23 +0000568 {return comp(__x, __y.__get_value().first);}
Marshall Clow8982dcd2015-07-13 20:04:56 +0000569 void swap(__map_value_compare&__y)
570 _NOEXCEPT_(__is_nothrow_swappable<_Compare>::value)
571 {
572 using _VSTD::swap;
573 swap(comp, __y.comp);
574 }
Eric Fiseliercf8c0212017-01-05 06:06:18 +0000575
Marshall Clowebb57322013-08-13 22:18:47 +0000576#if _LIBCPP_STD_VER > 11
577 template <typename _K2>
578 _LIBCPP_INLINE_VISIBILITY
579 typename enable_if<__is_transparent<_Compare, _K2>::value, bool>::type
580 operator () ( const _K2& __x, const _CP& __y ) const
Erik Pilkingtond3fe2992018-06-04 20:38:23 +0000581 {return comp (__x, __y.__get_value().first);}
Marshall Clowebb57322013-08-13 22:18:47 +0000582
583 template <typename _K2>
584 _LIBCPP_INLINE_VISIBILITY
585 typename enable_if<__is_transparent<_Compare, _K2>::value, bool>::type
586 operator () (const _CP& __x, const _K2& __y) const
Erik Pilkingtond3fe2992018-06-04 20:38:23 +0000587 {return comp (__x.__get_value().first, __y);}
Marshall Clowebb57322013-08-13 22:18:47 +0000588#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000589};
590
Marshall Clow8982dcd2015-07-13 20:04:56 +0000591template <class _Key, class _CP, class _Compare, bool __b>
592inline _LIBCPP_INLINE_VISIBILITY
593void
594swap(__map_value_compare<_Key, _CP, _Compare, __b>& __x,
595 __map_value_compare<_Key, _CP, _Compare, __b>& __y)
596 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
597{
598 __x.swap(__y);
599}
600
Howard Hinnantc51e1022010-05-11 19:42:16 +0000601template <class _Allocator>
602class __map_node_destructor
603{
604 typedef _Allocator allocator_type;
605 typedef allocator_traits<allocator_type> __alloc_traits;
Eric Fiseliera00b4842016-02-20 05:28:30 +0000606
Howard Hinnantc51e1022010-05-11 19:42:16 +0000607public:
608 typedef typename __alloc_traits::pointer pointer;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000609
Eric Fiseliera00b4842016-02-20 05:28:30 +0000610private:
Howard Hinnantc51e1022010-05-11 19:42:16 +0000611 allocator_type& __na_;
612
613 __map_node_destructor& operator=(const __map_node_destructor&);
614
615public:
616 bool __first_constructed;
617 bool __second_constructed;
618
Howard Hinnant756c69b2010-09-22 16:48:34 +0000619 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000620 explicit __map_node_destructor(allocator_type& __na) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +0000621 : __na_(__na),
622 __first_constructed(false),
623 __second_constructed(false)
624 {}
625
Eric Fiseliera85b1282017-04-18 21:08:06 +0000626#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant756c69b2010-09-22 16:48:34 +0000627 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000628 __map_node_destructor(__tree_node_destructor<allocator_type>&& __x) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +0000629 : __na_(__x.__na_),
630 __first_constructed(__x.__value_constructed),
631 __second_constructed(__x.__value_constructed)
632 {
633 __x.__value_constructed = false;
634 }
Eric Fiseliera85b1282017-04-18 21:08:06 +0000635#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000636
Howard Hinnant756c69b2010-09-22 16:48:34 +0000637 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000638 void operator()(pointer __p) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +0000639 {
640 if (__second_constructed)
Erik Pilkingtond3fe2992018-06-04 20:38:23 +0000641 __alloc_traits::destroy(__na_, _VSTD::addressof(__p->__value_.__get_value().second));
Howard Hinnantc51e1022010-05-11 19:42:16 +0000642 if (__first_constructed)
Erik Pilkingtond3fe2992018-06-04 20:38:23 +0000643 __alloc_traits::destroy(__na_, _VSTD::addressof(__p->__value_.__get_value().first));
Howard Hinnantc51e1022010-05-11 19:42:16 +0000644 if (__p)
645 __alloc_traits::deallocate(__na_, __p, 1);
646 }
647};
648
Howard Hinnant944510a2011-06-14 19:58:17 +0000649template <class _Key, class _Tp, class _Compare, class _Allocator>
650 class map;
651template <class _Key, class _Tp, class _Compare, class _Allocator>
652 class multimap;
653template <class _TreeIterator> class __map_const_iterator;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000654
Eric Fiseliera00b4842016-02-20 05:28:30 +0000655#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant89f8b792013-09-30 19:08:22 +0000656
657template <class _Key, class _Tp>
Erik Pilkingtond3fe2992018-06-04 20:38:23 +0000658struct __value_type
Howard Hinnant89f8b792013-09-30 19:08:22 +0000659{
660 typedef _Key key_type;
661 typedef _Tp mapped_type;
662 typedef pair<const key_type, mapped_type> value_type;
Erik Pilkingtond3fe2992018-06-04 20:38:23 +0000663 typedef pair<key_type&, mapped_type&> __nc_ref_pair_type;
664 typedef pair<key_type&&, mapped_type&&> __nc_rref_pair_type;
Howard Hinnant89f8b792013-09-30 19:08:22 +0000665
Erik Pilkingtond3fe2992018-06-04 20:38:23 +0000666private:
Howard Hinnant89f8b792013-09-30 19:08:22 +0000667 value_type __cc;
Erik Pilkingtond3fe2992018-06-04 20:38:23 +0000668
669public:
670 _LIBCPP_INLINE_VISIBILITY
671 value_type& __get_value()
672 {
673#if _LIBCPP_STD_VER > 14
674 return *_VSTD::launder(_VSTD::addressof(__cc));
675#else
676 return __cc;
677#endif
678 }
679
680 _LIBCPP_INLINE_VISIBILITY
681 const value_type& __get_value() const
682 {
683#if _LIBCPP_STD_VER > 14
684 return *_VSTD::launder(_VSTD::addressof(__cc));
685#else
686 return __cc;
687#endif
688 }
689
690 _LIBCPP_INLINE_VISIBILITY
691 __nc_ref_pair_type __ref()
692 {
693 value_type& __v = __get_value();
694 return __nc_ref_pair_type(const_cast<key_type&>(__v.first), __v.second);
695 }
696
697 _LIBCPP_INLINE_VISIBILITY
698 __nc_rref_pair_type __move()
699 {
700 value_type& __v = __get_value();
701 return __nc_rref_pair_type(
702 _VSTD::move(const_cast<key_type&>(__v.first)),
703 _VSTD::move(__v.second));
704 }
Howard Hinnant89f8b792013-09-30 19:08:22 +0000705
Howard Hinnant89f8b792013-09-30 19:08:22 +0000706 _LIBCPP_INLINE_VISIBILITY
707 __value_type& operator=(const __value_type& __v)
Erik Pilkingtond3fe2992018-06-04 20:38:23 +0000708 {
709 __ref() = __v.__get_value();
710 return *this;
711 }
Howard Hinnant89f8b792013-09-30 19:08:22 +0000712
713 _LIBCPP_INLINE_VISIBILITY
714 __value_type& operator=(__value_type&& __v)
Erik Pilkingtond3fe2992018-06-04 20:38:23 +0000715 {
716 __ref() = __v.__move();
717 return *this;
718 }
Howard Hinnant89f8b792013-09-30 19:08:22 +0000719
Eric Fiselierd06276b2016-03-31 02:15:15 +0000720 template <class _ValueTp,
721 class = typename enable_if<
722 __is_same_uncvref<_ValueTp, value_type>::value
723 >::type
724 >
Howard Hinnant89f8b792013-09-30 19:08:22 +0000725 _LIBCPP_INLINE_VISIBILITY
Erik Pilkingtond3fe2992018-06-04 20:38:23 +0000726 __value_type& operator=(_ValueTp&& __v)
727 {
728 __ref() = _VSTD::forward<_ValueTp>(__v);
729 return *this;
Eric Fiselierd06276b2016-03-31 02:15:15 +0000730 }
731
732private:
733 __value_type() _LIBCPP_EQUAL_DELETE;
734 ~__value_type() _LIBCPP_EQUAL_DELETE;
735 __value_type(const __value_type& __v) _LIBCPP_EQUAL_DELETE;
736 __value_type(__value_type&& __v) _LIBCPP_EQUAL_DELETE;
Howard Hinnant89f8b792013-09-30 19:08:22 +0000737};
738
739#else
740
741template <class _Key, class _Tp>
742struct __value_type
743{
744 typedef _Key key_type;
745 typedef _Tp mapped_type;
746 typedef pair<const key_type, mapped_type> value_type;
747
Erik Pilkingtond3fe2992018-06-04 20:38:23 +0000748private:
Howard Hinnant89f8b792013-09-30 19:08:22 +0000749 value_type __cc;
750
Erik Pilkingtond3fe2992018-06-04 20:38:23 +0000751public:
752 _LIBCPP_INLINE_VISIBILITY
753 value_type& __get_value() { return __cc; }
754 _LIBCPP_INLINE_VISIBILITY
755 const value_type& __get_value() const { return __cc; }
756
Eric Fiselierd06276b2016-03-31 02:15:15 +0000757private:
758 __value_type();
759 __value_type(__value_type const&);
760 __value_type& operator=(__value_type const&);
761 ~__value_type();
Howard Hinnant89f8b792013-09-30 19:08:22 +0000762};
763
Eric Fiseliera85b1282017-04-18 21:08:06 +0000764#endif // _LIBCPP_CXX03_LANG
Howard Hinnant89f8b792013-09-30 19:08:22 +0000765
Eric Fiselier44f9fd02015-03-03 20:10:01 +0000766template <class _Tp>
767struct __extract_key_value_types;
768
769template <class _Key, class _Tp>
770struct __extract_key_value_types<__value_type<_Key, _Tp> >
771{
772 typedef _Key const __key_type;
773 typedef _Tp __mapped_type;
774};
775
Howard Hinnantc51e1022010-05-11 19:42:16 +0000776template <class _TreeIterator>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000777class _LIBCPP_TEMPLATE_VIS __map_iterator
Howard Hinnantc51e1022010-05-11 19:42:16 +0000778{
Eric Fiseliera00b4842016-02-20 05:28:30 +0000779 typedef typename _TreeIterator::_NodeTypes _NodeTypes;
780 typedef typename _TreeIterator::__pointer_traits __pointer_traits;
781
Howard Hinnantc51e1022010-05-11 19:42:16 +0000782 _TreeIterator __i_;
783
Howard Hinnantc51e1022010-05-11 19:42:16 +0000784public:
785 typedef bidirectional_iterator_tag iterator_category;
Eric Fiseliera00b4842016-02-20 05:28:30 +0000786 typedef typename _NodeTypes::__map_value_type value_type;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000787 typedef typename _TreeIterator::difference_type difference_type;
788 typedef value_type& reference;
Eric Fiseliera00b4842016-02-20 05:28:30 +0000789 typedef typename _NodeTypes::__map_value_type_pointer pointer;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000790
Howard Hinnant756c69b2010-09-22 16:48:34 +0000791 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000792 __map_iterator() _NOEXCEPT {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000793
Howard Hinnant756c69b2010-09-22 16:48:34 +0000794 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000795 __map_iterator(_TreeIterator __i) _NOEXCEPT : __i_(__i) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000796
Howard Hinnant756c69b2010-09-22 16:48:34 +0000797 _LIBCPP_INLINE_VISIBILITY
Erik Pilkingtond3fe2992018-06-04 20:38:23 +0000798 reference operator*() const {return __i_->__get_value();}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000799 _LIBCPP_INLINE_VISIBILITY
Erik Pilkingtond3fe2992018-06-04 20:38:23 +0000800 pointer operator->() const {return pointer_traits<pointer>::pointer_to(__i_->__get_value());}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000801
Howard Hinnant756c69b2010-09-22 16:48:34 +0000802 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000803 __map_iterator& operator++() {++__i_; return *this;}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000804 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000805 __map_iterator operator++(int)
806 {
807 __map_iterator __t(*this);
808 ++(*this);
809 return __t;
810 }
811
Howard Hinnant756c69b2010-09-22 16:48:34 +0000812 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000813 __map_iterator& operator--() {--__i_; return *this;}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000814 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000815 __map_iterator operator--(int)
816 {
817 __map_iterator __t(*this);
818 --(*this);
819 return __t;
820 }
821
Howard Hinnant756c69b2010-09-22 16:48:34 +0000822 friend _LIBCPP_INLINE_VISIBILITY
823 bool operator==(const __map_iterator& __x, const __map_iterator& __y)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000824 {return __x.__i_ == __y.__i_;}
Eric Fiseliercf8c0212017-01-05 06:06:18 +0000825 friend
Howard Hinnant756c69b2010-09-22 16:48:34 +0000826 _LIBCPP_INLINE_VISIBILITY
827 bool operator!=(const __map_iterator& __x, const __map_iterator& __y)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000828 {return __x.__i_ != __y.__i_;}
829
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000830 template <class, class, class, class> friend class _LIBCPP_TEMPLATE_VIS map;
831 template <class, class, class, class> friend class _LIBCPP_TEMPLATE_VIS multimap;
832 template <class> friend class _LIBCPP_TEMPLATE_VIS __map_const_iterator;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000833};
834
835template <class _TreeIterator>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000836class _LIBCPP_TEMPLATE_VIS __map_const_iterator
Howard Hinnantc51e1022010-05-11 19:42:16 +0000837{
Eric Fiseliera00b4842016-02-20 05:28:30 +0000838 typedef typename _TreeIterator::_NodeTypes _NodeTypes;
839 typedef typename _TreeIterator::__pointer_traits __pointer_traits;
840
Howard Hinnantc51e1022010-05-11 19:42:16 +0000841 _TreeIterator __i_;
842
Howard Hinnantc51e1022010-05-11 19:42:16 +0000843public:
844 typedef bidirectional_iterator_tag iterator_category;
Eric Fiseliera00b4842016-02-20 05:28:30 +0000845 typedef typename _NodeTypes::__map_value_type value_type;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000846 typedef typename _TreeIterator::difference_type difference_type;
847 typedef const value_type& reference;
Eric Fiseliera00b4842016-02-20 05:28:30 +0000848 typedef typename _NodeTypes::__const_map_value_type_pointer pointer;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000849
Howard Hinnant756c69b2010-09-22 16:48:34 +0000850 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000851 __map_const_iterator() _NOEXCEPT {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000852
Howard Hinnant756c69b2010-09-22 16:48:34 +0000853 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000854 __map_const_iterator(_TreeIterator __i) _NOEXCEPT : __i_(__i) {}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000855 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier44f9fd02015-03-03 20:10:01 +0000856 __map_const_iterator(__map_iterator<
857 typename _TreeIterator::__non_const_iterator> __i) _NOEXCEPT
858 : __i_(__i.__i_) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000859
Howard Hinnant756c69b2010-09-22 16:48:34 +0000860 _LIBCPP_INLINE_VISIBILITY
Erik Pilkingtond3fe2992018-06-04 20:38:23 +0000861 reference operator*() const {return __i_->__get_value();}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000862 _LIBCPP_INLINE_VISIBILITY
Erik Pilkingtond3fe2992018-06-04 20:38:23 +0000863 pointer operator->() const {return pointer_traits<pointer>::pointer_to(__i_->__get_value());}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000864
Howard Hinnant756c69b2010-09-22 16:48:34 +0000865 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000866 __map_const_iterator& operator++() {++__i_; return *this;}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000867 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000868 __map_const_iterator operator++(int)
869 {
870 __map_const_iterator __t(*this);
871 ++(*this);
872 return __t;
873 }
874
Howard Hinnant756c69b2010-09-22 16:48:34 +0000875 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000876 __map_const_iterator& operator--() {--__i_; return *this;}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000877 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000878 __map_const_iterator operator--(int)
879 {
880 __map_const_iterator __t(*this);
881 --(*this);
882 return __t;
883 }
884
Howard Hinnant756c69b2010-09-22 16:48:34 +0000885 friend _LIBCPP_INLINE_VISIBILITY
886 bool operator==(const __map_const_iterator& __x, const __map_const_iterator& __y)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000887 {return __x.__i_ == __y.__i_;}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000888 friend _LIBCPP_INLINE_VISIBILITY
889 bool operator!=(const __map_const_iterator& __x, const __map_const_iterator& __y)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000890 {return __x.__i_ != __y.__i_;}
891
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000892 template <class, class, class, class> friend class _LIBCPP_TEMPLATE_VIS map;
893 template <class, class, class, class> friend class _LIBCPP_TEMPLATE_VIS multimap;
894 template <class, class, class> friend class _LIBCPP_TEMPLATE_VIS __tree_const_iterator;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000895};
896
897template <class _Key, class _Tp, class _Compare = less<_Key>,
898 class _Allocator = allocator<pair<const _Key, _Tp> > >
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000899class _LIBCPP_TEMPLATE_VIS map
Howard Hinnantc51e1022010-05-11 19:42:16 +0000900{
901public:
902 // types:
903 typedef _Key key_type;
904 typedef _Tp mapped_type;
905 typedef pair<const key_type, mapped_type> value_type;
906 typedef _Compare key_compare;
907 typedef _Allocator allocator_type;
908 typedef value_type& reference;
909 typedef const value_type& const_reference;
910
Louis Dionne878a3a82018-12-06 21:46:17 +0000911 static_assert(sizeof(__diagnose_non_const_comparator<_Key, _Compare>()), "");
Marshall Clow5128cf32015-11-26 01:24:04 +0000912 static_assert((is_same<typename allocator_type::value_type, value_type>::value),
913 "Allocator::value_type must be same type as value_type");
914
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000915 class _LIBCPP_TEMPLATE_VIS value_compare
Howard Hinnantc51e1022010-05-11 19:42:16 +0000916 : public binary_function<value_type, value_type, bool>
917 {
918 friend class map;
919 protected:
920 key_compare comp;
921
Howard Hinnant756c69b2010-09-22 16:48:34 +0000922 _LIBCPP_INLINE_VISIBILITY value_compare(key_compare c) : comp(c) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000923 public:
Howard Hinnant756c69b2010-09-22 16:48:34 +0000924 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000925 bool operator()(const value_type& __x, const value_type& __y) const
926 {return comp(__x.first, __y.first);}
927 };
928
929private:
Howard Hinnant2d0046b2013-06-19 21:29:40 +0000930
Howard Hinnant89f8b792013-09-30 19:08:22 +0000931 typedef _VSTD::__value_type<key_type, mapped_type> __value_type;
Howard Hinnant90b91592013-07-05 18:06:00 +0000932 typedef __map_value_compare<key_type, __value_type, key_compare> __vc;
Marshall Clow940e01c2015-04-07 05:21:38 +0000933 typedef typename __rebind_alloc_helper<allocator_traits<allocator_type>,
934 __value_type>::type __allocator_type;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000935 typedef __tree<__value_type, __vc, __allocator_type> __base;
936 typedef typename __base::__node_traits __node_traits;
937 typedef allocator_traits<allocator_type> __alloc_traits;
938
939 __base __tree_;
940
941public:
942 typedef typename __alloc_traits::pointer pointer;
943 typedef typename __alloc_traits::const_pointer const_pointer;
944 typedef typename __alloc_traits::size_type size_type;
945 typedef typename __alloc_traits::difference_type difference_type;
Eric Fiselier44f9fd02015-03-03 20:10:01 +0000946 typedef __map_iterator<typename __base::iterator> iterator;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000947 typedef __map_const_iterator<typename __base::const_iterator> const_iterator;
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000948 typedef _VSTD::reverse_iterator<iterator> reverse_iterator;
949 typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000950
Erik Pilkingtonc37a3d82018-08-01 01:33:38 +0000951#if _LIBCPP_STD_VER > 14
952 typedef __map_node_handle<typename __base::__node, allocator_type> node_type;
953 typedef __insert_return_type<iterator, node_type> insert_return_type;
954#endif
955
Erik Pilkington82a65ad2018-10-31 17:31:35 +0000956 template <class _Key2, class _Value2, class _Comp2, class _Alloc2>
957 friend class _LIBCPP_TEMPLATE_VIS map;
958 template <class _Key2, class _Value2, class _Comp2, class _Alloc2>
959 friend class _LIBCPP_TEMPLATE_VIS multimap;
960
Howard Hinnant756c69b2010-09-22 16:48:34 +0000961 _LIBCPP_INLINE_VISIBILITY
Marshall Clow7086a5a2014-03-10 04:50:10 +0000962 map()
963 _NOEXCEPT_(
964 is_nothrow_default_constructible<allocator_type>::value &&
965 is_nothrow_default_constructible<key_compare>::value &&
966 is_nothrow_copy_constructible<key_compare>::value)
967 : __tree_(__vc(key_compare())) {}
968
969 _LIBCPP_INLINE_VISIBILITY
970 explicit map(const key_compare& __comp)
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000971 _NOEXCEPT_(
972 is_nothrow_default_constructible<allocator_type>::value &&
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000973 is_nothrow_copy_constructible<key_compare>::value)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000974 : __tree_(__vc(__comp)) {}
975
Howard Hinnant756c69b2010-09-22 16:48:34 +0000976 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000977 explicit map(const key_compare& __comp, const allocator_type& __a)
Marshall Clow657cbc42016-08-17 05:58:40 +0000978 : __tree_(__vc(__comp), typename __base::allocator_type(__a)) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000979
980 template <class _InputIterator>
Howard Hinnant756c69b2010-09-22 16:48:34 +0000981 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000982 map(_InputIterator __f, _InputIterator __l,
983 const key_compare& __comp = key_compare())
984 : __tree_(__vc(__comp))
985 {
986 insert(__f, __l);
987 }
988
989 template <class _InputIterator>
Howard Hinnant756c69b2010-09-22 16:48:34 +0000990 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000991 map(_InputIterator __f, _InputIterator __l,
992 const key_compare& __comp, const allocator_type& __a)
Marshall Clow657cbc42016-08-17 05:58:40 +0000993 : __tree_(__vc(__comp), typename __base::allocator_type(__a))
Howard Hinnantc51e1022010-05-11 19:42:16 +0000994 {
995 insert(__f, __l);
996 }
997
Marshall Clow300abfb2013-09-11 01:15:47 +0000998#if _LIBCPP_STD_VER > 11
999 template <class _InputIterator>
Eric Fiseliercf8c0212017-01-05 06:06:18 +00001000 _LIBCPP_INLINE_VISIBILITY
Marshall Clow300abfb2013-09-11 01:15:47 +00001001 map(_InputIterator __f, _InputIterator __l, const allocator_type& __a)
1002 : map(__f, __l, key_compare(), __a) {}
1003#endif
1004
Howard Hinnant756c69b2010-09-22 16:48:34 +00001005 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001006 map(const map& __m)
1007 : __tree_(__m.__tree_)
1008 {
1009 insert(__m.begin(), __m.end());
1010 }
1011
Howard Hinnantd3a657f2011-07-01 19:24:36 +00001012 _LIBCPP_INLINE_VISIBILITY
1013 map& operator=(const map& __m)
1014 {
Marshall Clow476d3f42016-07-18 13:19:00 +00001015#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantd3a657f2011-07-01 19:24:36 +00001016 __tree_ = __m.__tree_;
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001017#else
Marshall Clowdb3cfcb2014-02-08 04:03:14 +00001018 if (this != &__m) {
1019 __tree_.clear();
1020 __tree_.value_comp() = __m.__tree_.value_comp();
1021 __tree_.__copy_assign_alloc(__m.__tree_);
1022 insert(__m.begin(), __m.end());
1023 }
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001024#endif
Howard Hinnantd3a657f2011-07-01 19:24:36 +00001025 return *this;
1026 }
1027
Eric Fiseliera85b1282017-04-18 21:08:06 +00001028#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001029
Howard Hinnant756c69b2010-09-22 16:48:34 +00001030 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001031 map(map&& __m)
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001032 _NOEXCEPT_(is_nothrow_move_constructible<__base>::value)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001033 : __tree_(_VSTD::move(__m.__tree_))
Howard Hinnantc51e1022010-05-11 19:42:16 +00001034 {
1035 }
1036
1037 map(map&& __m, const allocator_type& __a);
1038
Howard Hinnant756c69b2010-09-22 16:48:34 +00001039 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant33711792011-08-12 21:56:02 +00001040 map& operator=(map&& __m)
1041 _NOEXCEPT_(is_nothrow_move_assignable<__base>::value)
1042 {
1043 __tree_ = _VSTD::move(__m.__tree_);
1044 return *this;
1045 }
1046
Howard Hinnant33711792011-08-12 21:56:02 +00001047 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001048 map(initializer_list<value_type> __il, const key_compare& __comp = key_compare())
1049 : __tree_(__vc(__comp))
1050 {
1051 insert(__il.begin(), __il.end());
1052 }
1053
Howard Hinnant756c69b2010-09-22 16:48:34 +00001054 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001055 map(initializer_list<value_type> __il, const key_compare& __comp, const allocator_type& __a)
Marshall Clow657cbc42016-08-17 05:58:40 +00001056 : __tree_(__vc(__comp), typename __base::allocator_type(__a))
Howard Hinnantc51e1022010-05-11 19:42:16 +00001057 {
1058 insert(__il.begin(), __il.end());
1059 }
1060
Marshall Clow300abfb2013-09-11 01:15:47 +00001061#if _LIBCPP_STD_VER > 11
Eric Fiseliercf8c0212017-01-05 06:06:18 +00001062 _LIBCPP_INLINE_VISIBILITY
Marshall Clow300abfb2013-09-11 01:15:47 +00001063 map(initializer_list<value_type> __il, const allocator_type& __a)
1064 : map(__il, key_compare(), __a) {}
1065#endif
1066
Howard Hinnant756c69b2010-09-22 16:48:34 +00001067 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001068 map& operator=(initializer_list<value_type> __il)
1069 {
1070 __tree_.__assign_unique(__il.begin(), __il.end());
1071 return *this;
1072 }
1073
Eric Fiseliera85b1282017-04-18 21:08:06 +00001074#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001075
Howard Hinnant756c69b2010-09-22 16:48:34 +00001076 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001077 explicit map(const allocator_type& __a)
Marshall Clow657cbc42016-08-17 05:58:40 +00001078 : __tree_(typename __base::allocator_type(__a))
Howard Hinnantc51e1022010-05-11 19:42:16 +00001079 {
1080 }
1081
Howard Hinnant756c69b2010-09-22 16:48:34 +00001082 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001083 map(const map& __m, const allocator_type& __a)
Marshall Clow657cbc42016-08-17 05:58:40 +00001084 : __tree_(__m.__tree_.value_comp(), typename __base::allocator_type(__a))
Howard Hinnantc51e1022010-05-11 19:42:16 +00001085 {
1086 insert(__m.begin(), __m.end());
1087 }
1088
Howard Hinnant756c69b2010-09-22 16:48:34 +00001089 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001090 iterator begin() _NOEXCEPT {return __tree_.begin();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001091 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001092 const_iterator begin() const _NOEXCEPT {return __tree_.begin();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001093 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001094 iterator end() _NOEXCEPT {return __tree_.end();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001095 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001096 const_iterator end() const _NOEXCEPT {return __tree_.end();}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001097
Howard Hinnant756c69b2010-09-22 16:48:34 +00001098 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001099 reverse_iterator rbegin() _NOEXCEPT {return reverse_iterator(end());}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001100 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001101 const_reverse_iterator rbegin() const _NOEXCEPT
1102 {return const_reverse_iterator(end());}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001103 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001104 reverse_iterator rend() _NOEXCEPT
1105 {return reverse_iterator(begin());}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001106 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001107 const_reverse_iterator rend() const _NOEXCEPT
1108 {return const_reverse_iterator(begin());}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001109
Howard Hinnant756c69b2010-09-22 16:48:34 +00001110 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001111 const_iterator cbegin() const _NOEXCEPT {return begin();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001112 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001113 const_iterator cend() const _NOEXCEPT {return end();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001114 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001115 const_reverse_iterator crbegin() const _NOEXCEPT {return rbegin();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001116 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001117 const_reverse_iterator crend() const _NOEXCEPT {return rend();}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001118
Marshall Clow425f5752017-11-15 05:51:26 +00001119 _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001120 bool empty() const _NOEXCEPT {return __tree_.size() == 0;}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001121 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001122 size_type size() const _NOEXCEPT {return __tree_.size();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001123 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001124 size_type max_size() const _NOEXCEPT {return __tree_.max_size();}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001125
1126 mapped_type& operator[](const key_type& __k);
Eric Fiselierd63f38e2016-03-31 03:13:37 +00001127#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001128 mapped_type& operator[](key_type&& __k);
1129#endif
1130
1131 mapped_type& at(const key_type& __k);
1132 const mapped_type& at(const key_type& __k) const;
1133
Howard Hinnant756c69b2010-09-22 16:48:34 +00001134 _LIBCPP_INLINE_VISIBILITY
Marshall Clow657cbc42016-08-17 05:58:40 +00001135 allocator_type get_allocator() const _NOEXCEPT {return allocator_type(__tree_.__alloc());}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001136 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001137 key_compare key_comp() const {return __tree_.value_comp().key_comp();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001138 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001139 value_compare value_comp() const {return value_compare(__tree_.value_comp().key_comp());}
1140
Eric Fiselierd06276b2016-03-31 02:15:15 +00001141#ifndef _LIBCPP_CXX03_LANG
1142 template <class ..._Args>
1143 _LIBCPP_INLINE_VISIBILITY
1144 pair<iterator, bool> emplace(_Args&& ...__args) {
1145 return __tree_.__emplace_unique(_VSTD::forward<_Args>(__args)...);
1146 }
Howard Hinnant74279a52010-09-04 23:28:19 +00001147
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001148 template <class ..._Args>
Eric Fiselierd06276b2016-03-31 02:15:15 +00001149 _LIBCPP_INLINE_VISIBILITY
1150 iterator emplace_hint(const_iterator __p, _Args&& ...__args) {
1151 return __tree_.__emplace_hint_unique(__p.__i_, _VSTD::forward<_Args>(__args)...);
1152 }
Howard Hinnant74279a52010-09-04 23:28:19 +00001153
Howard Hinnantc834c512011-11-29 18:15:50 +00001154 template <class _Pp,
1155 class = typename enable_if<is_constructible<value_type, _Pp>::value>::type>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001156 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc834c512011-11-29 18:15:50 +00001157 pair<iterator, bool> insert(_Pp&& __p)
1158 {return __tree_.__insert_unique(_VSTD::forward<_Pp>(__p));}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001159
Howard Hinnantc834c512011-11-29 18:15:50 +00001160 template <class _Pp,
1161 class = typename enable_if<is_constructible<value_type, _Pp>::value>::type>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001162 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc834c512011-11-29 18:15:50 +00001163 iterator insert(const_iterator __pos, _Pp&& __p)
1164 {return __tree_.__insert_unique(__pos.__i_, _VSTD::forward<_Pp>(__p));}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001165
Eric Fiselierd06276b2016-03-31 02:15:15 +00001166#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001167
Howard Hinnant756c69b2010-09-22 16:48:34 +00001168 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001169 pair<iterator, bool>
1170 insert(const value_type& __v) {return __tree_.__insert_unique(__v);}
1171
Howard Hinnant756c69b2010-09-22 16:48:34 +00001172 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001173 iterator
1174 insert(const_iterator __p, const value_type& __v)
1175 {return __tree_.__insert_unique(__p.__i_, __v);}
1176
Eric Fiselierd6143132016-04-18 01:40:45 +00001177#ifndef _LIBCPP_CXX03_LANG
Marshall Clowd430d022016-01-05 19:32:41 +00001178 _LIBCPP_INLINE_VISIBILITY
1179 pair<iterator, bool>
Eric Fiselierd06276b2016-03-31 02:15:15 +00001180 insert(value_type&& __v) {return __tree_.__insert_unique(_VSTD::move(__v));}
Marshall Clowd430d022016-01-05 19:32:41 +00001181
1182 _LIBCPP_INLINE_VISIBILITY
Eric Fiselierd06276b2016-03-31 02:15:15 +00001183 iterator insert(const_iterator __p, value_type&& __v)
1184 {return __tree_.__insert_unique(__p.__i_, _VSTD::move(__v));}
Eric Fiseliera85b1282017-04-18 21:08:06 +00001185
1186 _LIBCPP_INLINE_VISIBILITY
1187 void insert(initializer_list<value_type> __il)
1188 {insert(__il.begin(), __il.end());}
Marshall Clowd430d022016-01-05 19:32:41 +00001189#endif
1190
Howard Hinnantc51e1022010-05-11 19:42:16 +00001191 template <class _InputIterator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001192 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001193 void insert(_InputIterator __f, _InputIterator __l)
1194 {
1195 for (const_iterator __e = cend(); __f != __l; ++__f)
1196 insert(__e.__i_, *__f);
1197 }
1198
Marshall Clow3223db82015-07-07 03:37:33 +00001199#if _LIBCPP_STD_VER > 14
Eric Fiselierd63f38e2016-03-31 03:13:37 +00001200
Marshall Clow3223db82015-07-07 03:37:33 +00001201 template <class... _Args>
1202 _LIBCPP_INLINE_VISIBILITY
1203 pair<iterator, bool> try_emplace(const key_type& __k, _Args&&... __args)
1204 {
Eric Fiselierd63f38e2016-03-31 03:13:37 +00001205 return __tree_.__emplace_unique_key_args(__k,
1206 _VSTD::piecewise_construct,
1207 _VSTD::forward_as_tuple(__k),
1208 _VSTD::forward_as_tuple(_VSTD::forward<_Args>(__args)...));
Marshall Clow3223db82015-07-07 03:37:33 +00001209 }
1210
1211 template <class... _Args>
1212 _LIBCPP_INLINE_VISIBILITY
1213 pair<iterator, bool> try_emplace(key_type&& __k, _Args&&... __args)
1214 {
Eric Fiselierd63f38e2016-03-31 03:13:37 +00001215 return __tree_.__emplace_unique_key_args(__k,
1216 _VSTD::piecewise_construct,
1217 _VSTD::forward_as_tuple(_VSTD::move(__k)),
1218 _VSTD::forward_as_tuple(_VSTD::forward<_Args>(__args)...));
Marshall Clow3223db82015-07-07 03:37:33 +00001219 }
1220
1221 template <class... _Args>
1222 _LIBCPP_INLINE_VISIBILITY
1223 iterator try_emplace(const_iterator __h, const key_type& __k, _Args&&... __args)
1224 {
Eric Fiselierd63f38e2016-03-31 03:13:37 +00001225 return __tree_.__emplace_hint_unique_key_args(__h.__i_, __k,
1226 _VSTD::piecewise_construct,
1227 _VSTD::forward_as_tuple(__k),
1228 _VSTD::forward_as_tuple(_VSTD::forward<_Args>(__args)...));
Marshall Clow3223db82015-07-07 03:37:33 +00001229 }
1230
1231 template <class... _Args>
1232 _LIBCPP_INLINE_VISIBILITY
1233 iterator try_emplace(const_iterator __h, key_type&& __k, _Args&&... __args)
1234 {
Eric Fiselierd63f38e2016-03-31 03:13:37 +00001235 return __tree_.__emplace_hint_unique_key_args(__h.__i_, __k,
1236 _VSTD::piecewise_construct,
1237 _VSTD::forward_as_tuple(_VSTD::move(__k)),
1238 _VSTD::forward_as_tuple(_VSTD::forward<_Args>(__args)...));
Marshall Clow3223db82015-07-07 03:37:33 +00001239 }
1240
1241 template <class _Vp>
1242 _LIBCPP_INLINE_VISIBILITY
1243 pair<iterator, bool> insert_or_assign(const key_type& __k, _Vp&& __v)
1244 {
1245 iterator __p = lower_bound(__k);
1246 if ( __p != end() && !key_comp()(__k, __p->first))
1247 {
1248 __p->second = _VSTD::forward<_Vp>(__v);
1249 return _VSTD::make_pair(__p, false);
1250 }
1251 return _VSTD::make_pair(emplace_hint(__p, __k, _VSTD::forward<_Vp>(__v)), true);
1252 }
Eric Fiselierd63f38e2016-03-31 03:13:37 +00001253
Marshall Clow3223db82015-07-07 03:37:33 +00001254 template <class _Vp>
1255 _LIBCPP_INLINE_VISIBILITY
1256 pair<iterator, bool> insert_or_assign(key_type&& __k, _Vp&& __v)
1257 {
1258 iterator __p = lower_bound(__k);
1259 if ( __p != end() && !key_comp()(__k, __p->first))
1260 {
1261 __p->second = _VSTD::forward<_Vp>(__v);
1262 return _VSTD::make_pair(__p, false);
1263 }
1264 return _VSTD::make_pair(emplace_hint(__p, _VSTD::move(__k), _VSTD::forward<_Vp>(__v)), true);
1265 }
1266
1267 template <class _Vp>
1268 _LIBCPP_INLINE_VISIBILITY
1269 iterator insert_or_assign(const_iterator __h, const key_type& __k, _Vp&& __v)
1270 {
1271 iterator __p = lower_bound(__k);
1272 if ( __p != end() && !key_comp()(__k, __p->first))
1273 {
1274 __p->second = _VSTD::forward<_Vp>(__v);
1275 return __p;
1276 }
1277 return emplace_hint(__h, __k, _VSTD::forward<_Vp>(__v));
1278 }
1279
1280 template <class _Vp>
1281 _LIBCPP_INLINE_VISIBILITY
1282 iterator insert_or_assign(const_iterator __h, key_type&& __k, _Vp&& __v)
1283 {
1284 iterator __p = lower_bound(__k);
1285 if ( __p != end() && !key_comp()(__k, __p->first))
1286 {
1287 __p->second = _VSTD::forward<_Vp>(__v);
1288 return __p;
1289 }
1290 return emplace_hint(__h, _VSTD::move(__k), _VSTD::forward<_Vp>(__v));
1291 }
Eric Fiselierd63f38e2016-03-31 03:13:37 +00001292
Eric Fiseliera85b1282017-04-18 21:08:06 +00001293#endif // _LIBCPP_STD_VER > 14
Marshall Clow3223db82015-07-07 03:37:33 +00001294
Howard Hinnant756c69b2010-09-22 16:48:34 +00001295 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001296 iterator erase(const_iterator __p) {return __tree_.erase(__p.__i_);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001297 _LIBCPP_INLINE_VISIBILITY
Marshall Clow22ea5b82015-05-10 13:35:00 +00001298 iterator erase(iterator __p) {return __tree_.erase(__p.__i_);}
1299 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001300 size_type erase(const key_type& __k)
1301 {return __tree_.__erase_unique(__k);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001302 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001303 iterator erase(const_iterator __f, const_iterator __l)
1304 {return __tree_.erase(__f.__i_, __l.__i_);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001305 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001306 void clear() _NOEXCEPT {__tree_.clear();}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001307
Erik Pilkingtonc37a3d82018-08-01 01:33:38 +00001308#if _LIBCPP_STD_VER > 14
1309 _LIBCPP_INLINE_VISIBILITY
1310 insert_return_type insert(node_type&& __nh)
1311 {
1312 _LIBCPP_ASSERT(__nh.empty() || __nh.get_allocator() == get_allocator(),
1313 "node_type with incompatible allocator passed to map::insert()");
1314 return __tree_.template __node_handle_insert_unique<
1315 node_type, insert_return_type>(_VSTD::move(__nh));
1316 }
1317 _LIBCPP_INLINE_VISIBILITY
1318 iterator insert(const_iterator __hint, node_type&& __nh)
1319 {
1320 _LIBCPP_ASSERT(__nh.empty() || __nh.get_allocator() == get_allocator(),
1321 "node_type with incompatible allocator passed to map::insert()");
1322 return __tree_.template __node_handle_insert_unique<node_type>(
1323 __hint.__i_, _VSTD::move(__nh));
1324 }
1325 _LIBCPP_INLINE_VISIBILITY
1326 node_type extract(key_type const& __key)
1327 {
1328 return __tree_.template __node_handle_extract<node_type>(__key);
1329 }
1330 _LIBCPP_INLINE_VISIBILITY
1331 node_type extract(const_iterator __it)
1332 {
1333 return __tree_.template __node_handle_extract<node_type>(__it.__i_);
1334 }
Louis Dionned2322c82018-11-01 14:41:37 +00001335 template <class _Compare2>
Erik Pilkington82a65ad2018-10-31 17:31:35 +00001336 _LIBCPP_INLINE_VISIBILITY
Louis Dionned2322c82018-11-01 14:41:37 +00001337 void merge(map<key_type, mapped_type, _Compare2, allocator_type>& __source)
Erik Pilkington82a65ad2018-10-31 17:31:35 +00001338 {
1339 _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
1340 "merging container with incompatible allocator");
1341 __tree_.__node_handle_merge_unique(__source.__tree_);
1342 }
Louis Dionned2322c82018-11-01 14:41:37 +00001343 template <class _Compare2>
Erik Pilkington82a65ad2018-10-31 17:31:35 +00001344 _LIBCPP_INLINE_VISIBILITY
Louis Dionned2322c82018-11-01 14:41:37 +00001345 void merge(map<key_type, mapped_type, _Compare2, allocator_type>&& __source)
Erik Pilkington82a65ad2018-10-31 17:31:35 +00001346 {
1347 _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
1348 "merging container with incompatible allocator");
1349 __tree_.__node_handle_merge_unique(__source.__tree_);
1350 }
Louis Dionned2322c82018-11-01 14:41:37 +00001351 template <class _Compare2>
Erik Pilkington82a65ad2018-10-31 17:31:35 +00001352 _LIBCPP_INLINE_VISIBILITY
Louis Dionned2322c82018-11-01 14:41:37 +00001353 void merge(multimap<key_type, mapped_type, _Compare2, allocator_type>& __source)
Erik Pilkington82a65ad2018-10-31 17:31:35 +00001354 {
1355 _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
1356 "merging container with incompatible allocator");
1357 __tree_.__node_handle_merge_unique(__source.__tree_);
1358 }
Louis Dionned2322c82018-11-01 14:41:37 +00001359 template <class _Compare2>
Erik Pilkington82a65ad2018-10-31 17:31:35 +00001360 _LIBCPP_INLINE_VISIBILITY
Louis Dionned2322c82018-11-01 14:41:37 +00001361 void merge(multimap<key_type, mapped_type, _Compare2, allocator_type>&& __source)
Erik Pilkington82a65ad2018-10-31 17:31:35 +00001362 {
1363 _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
1364 "merging container with incompatible allocator");
1365 __tree_.__node_handle_merge_unique(__source.__tree_);
1366 }
Erik Pilkingtonc37a3d82018-08-01 01:33:38 +00001367#endif
1368
Howard Hinnant756c69b2010-09-22 16:48:34 +00001369 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001370 void swap(map& __m)
1371 _NOEXCEPT_(__is_nothrow_swappable<__base>::value)
1372 {__tree_.swap(__m.__tree_);}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001373
Howard Hinnant756c69b2010-09-22 16:48:34 +00001374 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001375 iterator find(const key_type& __k) {return __tree_.find(__k);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001376 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001377 const_iterator find(const key_type& __k) const {return __tree_.find(__k);}
Marshall Clowebb57322013-08-13 22:18:47 +00001378#if _LIBCPP_STD_VER > 11
1379 template <typename _K2>
1380 _LIBCPP_INLINE_VISIBILITY
1381 typename enable_if<__is_transparent<_Compare, _K2>::value,iterator>::type
1382 find(const _K2& __k) {return __tree_.find(__k);}
1383 template <typename _K2>
1384 _LIBCPP_INLINE_VISIBILITY
1385 typename enable_if<__is_transparent<_Compare, _K2>::value,const_iterator>::type
1386 find(const _K2& __k) const {return __tree_.find(__k);}
1387#endif
1388
Howard Hinnant756c69b2010-09-22 16:48:34 +00001389 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001390 size_type count(const key_type& __k) const
1391 {return __tree_.__count_unique(__k);}
Marshall Clowe6a5f522014-08-24 23:54:16 +00001392#if _LIBCPP_STD_VER > 11
1393 template <typename _K2>
1394 _LIBCPP_INLINE_VISIBILITY
1395 typename enable_if<__is_transparent<_Compare, _K2>::value,size_type>::type
Eric Fiseliera85c9e92018-02-10 02:53:47 +00001396 count(const _K2& __k) const {return __tree_.__count_multi(__k);}
Marshall Clowe6a5f522014-08-24 23:54:16 +00001397#endif
Howard Hinnant756c69b2010-09-22 16:48:34 +00001398 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001399 iterator lower_bound(const key_type& __k)
1400 {return __tree_.lower_bound(__k);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001401 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001402 const_iterator lower_bound(const key_type& __k) const
1403 {return __tree_.lower_bound(__k);}
Marshall Clowebb57322013-08-13 22:18:47 +00001404#if _LIBCPP_STD_VER > 11
1405 template <typename _K2>
1406 _LIBCPP_INLINE_VISIBILITY
1407 typename enable_if<__is_transparent<_Compare, _K2>::value,iterator>::type
1408 lower_bound(const _K2& __k) {return __tree_.lower_bound(__k);}
1409
1410 template <typename _K2>
1411 _LIBCPP_INLINE_VISIBILITY
1412 typename enable_if<__is_transparent<_Compare, _K2>::value,const_iterator>::type
1413 lower_bound(const _K2& __k) const {return __tree_.lower_bound(__k);}
1414#endif
1415
Howard Hinnant756c69b2010-09-22 16:48:34 +00001416 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001417 iterator upper_bound(const key_type& __k)
1418 {return __tree_.upper_bound(__k);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001419 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001420 const_iterator upper_bound(const key_type& __k) const
1421 {return __tree_.upper_bound(__k);}
Marshall Clowebb57322013-08-13 22:18:47 +00001422#if _LIBCPP_STD_VER > 11
1423 template <typename _K2>
1424 _LIBCPP_INLINE_VISIBILITY
1425 typename enable_if<__is_transparent<_Compare, _K2>::value,iterator>::type
1426 upper_bound(const _K2& __k) {return __tree_.upper_bound(__k);}
1427 template <typename _K2>
1428 _LIBCPP_INLINE_VISIBILITY
1429 typename enable_if<__is_transparent<_Compare, _K2>::value,const_iterator>::type
1430 upper_bound(const _K2& __k) const {return __tree_.upper_bound(__k);}
1431#endif
1432
Howard Hinnant756c69b2010-09-22 16:48:34 +00001433 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001434 pair<iterator,iterator> equal_range(const key_type& __k)
1435 {return __tree_.__equal_range_unique(__k);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001436 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001437 pair<const_iterator,const_iterator> equal_range(const key_type& __k) const
1438 {return __tree_.__equal_range_unique(__k);}
Marshall Clowebb57322013-08-13 22:18:47 +00001439#if _LIBCPP_STD_VER > 11
1440 template <typename _K2>
1441 _LIBCPP_INLINE_VISIBILITY
1442 typename enable_if<__is_transparent<_Compare, _K2>::value,pair<iterator,iterator>>::type
Eric Fiseliera85c9e92018-02-10 02:53:47 +00001443 equal_range(const _K2& __k) {return __tree_.__equal_range_multi(__k);}
Marshall Clowebb57322013-08-13 22:18:47 +00001444 template <typename _K2>
1445 _LIBCPP_INLINE_VISIBILITY
1446 typename enable_if<__is_transparent<_Compare, _K2>::value,pair<const_iterator,const_iterator>>::type
Eric Fiseliera85c9e92018-02-10 02:53:47 +00001447 equal_range(const _K2& __k) const {return __tree_.__equal_range_multi(__k);}
Marshall Clowebb57322013-08-13 22:18:47 +00001448#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001449
1450private:
1451 typedef typename __base::__node __node;
1452 typedef typename __base::__node_allocator __node_allocator;
1453 typedef typename __base::__node_pointer __node_pointer;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001454 typedef typename __base::__node_base_pointer __node_base_pointer;
Eric Fiseliercf8c0212017-01-05 06:06:18 +00001455 typedef typename __base::__parent_pointer __parent_pointer;
Eric Fiseliera92b0732016-02-20 07:12:17 +00001456
Howard Hinnantc834c512011-11-29 18:15:50 +00001457 typedef __map_node_destructor<__node_allocator> _Dp;
1458 typedef unique_ptr<__node, _Dp> __node_holder;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001459
Eric Fiselierd63f38e2016-03-31 03:13:37 +00001460#ifdef _LIBCPP_CXX03_LANG
Howard Hinnantac7e7482013-07-04 20:59:16 +00001461 __node_holder __construct_node_with_key(const key_type& __k);
Eric Fiselierd63f38e2016-03-31 03:13:37 +00001462#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001463};
1464
Eric Fiseliera92b0732016-02-20 07:12:17 +00001465
Eric Fiselierd06276b2016-03-31 02:15:15 +00001466#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001467template <class _Key, class _Tp, class _Compare, class _Allocator>
1468map<_Key, _Tp, _Compare, _Allocator>::map(map&& __m, const allocator_type& __a)
Marshall Clow657cbc42016-08-17 05:58:40 +00001469 : __tree_(_VSTD::move(__m.__tree_), typename __base::allocator_type(__a))
Howard Hinnantc51e1022010-05-11 19:42:16 +00001470{
1471 if (__a != __m.get_allocator())
1472 {
1473 const_iterator __e = cend();
1474 while (!__m.empty())
1475 __tree_.__insert_unique(__e.__i_,
Erik Pilkingtond3fe2992018-06-04 20:38:23 +00001476 __m.__tree_.remove(__m.begin().__i_)->__value_.__move());
Howard Hinnantc51e1022010-05-11 19:42:16 +00001477 }
1478}
1479
Eric Fiseliera85b1282017-04-18 21:08:06 +00001480template <class _Key, class _Tp, class _Compare, class _Allocator>
1481_Tp&
1482map<_Key, _Tp, _Compare, _Allocator>::operator[](const key_type& __k)
1483{
1484 return __tree_.__emplace_unique_key_args(__k,
1485 _VSTD::piecewise_construct,
1486 _VSTD::forward_as_tuple(__k),
Erik Pilkingtond3fe2992018-06-04 20:38:23 +00001487 _VSTD::forward_as_tuple()).first->__get_value().second;
Eric Fiseliera85b1282017-04-18 21:08:06 +00001488}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001489
Eric Fiseliera85b1282017-04-18 21:08:06 +00001490template <class _Key, class _Tp, class _Compare, class _Allocator>
1491_Tp&
1492map<_Key, _Tp, _Compare, _Allocator>::operator[](key_type&& __k)
1493{
1494 return __tree_.__emplace_unique_key_args(__k,
1495 _VSTD::piecewise_construct,
1496 _VSTD::forward_as_tuple(_VSTD::move(__k)),
Erik Pilkingtond3fe2992018-06-04 20:38:23 +00001497 _VSTD::forward_as_tuple()).first->__get_value().second;
Eric Fiseliera85b1282017-04-18 21:08:06 +00001498}
Eric Fiselierd63f38e2016-03-31 03:13:37 +00001499
Eric Fiseliera85b1282017-04-18 21:08:06 +00001500#else // _LIBCPP_CXX03_LANG
Eric Fiselierd63f38e2016-03-31 03:13:37 +00001501
Howard Hinnantc51e1022010-05-11 19:42:16 +00001502template <class _Key, class _Tp, class _Compare, class _Allocator>
1503typename map<_Key, _Tp, _Compare, _Allocator>::__node_holder
Howard Hinnantac7e7482013-07-04 20:59:16 +00001504map<_Key, _Tp, _Compare, _Allocator>::__construct_node_with_key(const key_type& __k)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001505{
1506 __node_allocator& __na = __tree_.__node_alloc();
Howard Hinnantc834c512011-11-29 18:15:50 +00001507 __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
Erik Pilkingtond3fe2992018-06-04 20:38:23 +00001508 __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__get_value().first), __k);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001509 __h.get_deleter().__first_constructed = true;
Erik Pilkingtond3fe2992018-06-04 20:38:23 +00001510 __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__get_value().second));
Howard Hinnantc51e1022010-05-11 19:42:16 +00001511 __h.get_deleter().__second_constructed = true;
Dimitry Andric830fb602015-08-19 06:43:33 +00001512 return _LIBCPP_EXPLICIT_MOVE(__h); // explicitly moved for C++03
Howard Hinnantc51e1022010-05-11 19:42:16 +00001513}
1514
Howard Hinnantc51e1022010-05-11 19:42:16 +00001515template <class _Key, class _Tp, class _Compare, class _Allocator>
1516_Tp&
1517map<_Key, _Tp, _Compare, _Allocator>::operator[](const key_type& __k)
1518{
Eric Fiseliercf8c0212017-01-05 06:06:18 +00001519 __parent_pointer __parent;
1520 __node_base_pointer& __child = __tree_.__find_equal(__parent, __k);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001521 __node_pointer __r = static_cast<__node_pointer>(__child);
1522 if (__child == nullptr)
1523 {
Howard Hinnantac7e7482013-07-04 20:59:16 +00001524 __node_holder __h = __construct_node_with_key(__k);
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001525 __tree_.__insert_node_at(__parent, __child, static_cast<__node_base_pointer>(__h.get()));
Howard Hinnantc51e1022010-05-11 19:42:16 +00001526 __r = __h.release();
1527 }
Erik Pilkingtond3fe2992018-06-04 20:38:23 +00001528 return __r->__value_.__get_value().second;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001529}
1530
Eric Fiseliera85b1282017-04-18 21:08:06 +00001531#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001532
1533template <class _Key, class _Tp, class _Compare, class _Allocator>
1534_Tp&
1535map<_Key, _Tp, _Compare, _Allocator>::at(const key_type& __k)
1536{
Eric Fiseliercf8c0212017-01-05 06:06:18 +00001537 __parent_pointer __parent;
1538 __node_base_pointer& __child = __tree_.__find_equal(__parent, __k);
Howard Hinnant72f73582010-08-11 17:04:31 +00001539#ifndef _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +00001540 if (__child == nullptr)
1541 throw out_of_range("map::at: key not found");
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001542#endif // _LIBCPP_NO_EXCEPTIONS
Erik Pilkingtond3fe2992018-06-04 20:38:23 +00001543 return static_cast<__node_pointer>(__child)->__value_.__get_value().second;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001544}
1545
1546template <class _Key, class _Tp, class _Compare, class _Allocator>
1547const _Tp&
1548map<_Key, _Tp, _Compare, _Allocator>::at(const key_type& __k) const
1549{
Eric Fiseliercf8c0212017-01-05 06:06:18 +00001550 __parent_pointer __parent;
1551 __node_base_pointer __child = __tree_.__find_equal(__parent, __k);
Howard Hinnant72f73582010-08-11 17:04:31 +00001552#ifndef _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +00001553 if (__child == nullptr)
1554 throw out_of_range("map::at: key not found");
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001555#endif // _LIBCPP_NO_EXCEPTIONS
Erik Pilkingtond3fe2992018-06-04 20:38:23 +00001556 return static_cast<__node_pointer>(__child)->__value_.__get_value().second;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001557}
1558
Howard Hinnantc51e1022010-05-11 19:42:16 +00001559
1560template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001561inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001562bool
1563operator==(const map<_Key, _Tp, _Compare, _Allocator>& __x,
1564 const map<_Key, _Tp, _Compare, _Allocator>& __y)
1565{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001566 return __x.size() == __y.size() && _VSTD::equal(__x.begin(), __x.end(), __y.begin());
Howard Hinnantc51e1022010-05-11 19:42:16 +00001567}
1568
1569template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001570inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001571bool
1572operator< (const map<_Key, _Tp, _Compare, _Allocator>& __x,
1573 const map<_Key, _Tp, _Compare, _Allocator>& __y)
1574{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001575 return _VSTD::lexicographical_compare(__x.begin(), __x.end(), __y.begin(), __y.end());
Howard Hinnantc51e1022010-05-11 19:42:16 +00001576}
1577
1578template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001579inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001580bool
1581operator!=(const map<_Key, _Tp, _Compare, _Allocator>& __x,
1582 const map<_Key, _Tp, _Compare, _Allocator>& __y)
1583{
1584 return !(__x == __y);
1585}
1586
1587template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001588inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001589bool
1590operator> (const map<_Key, _Tp, _Compare, _Allocator>& __x,
1591 const map<_Key, _Tp, _Compare, _Allocator>& __y)
1592{
1593 return __y < __x;
1594}
1595
1596template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001597inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001598bool
1599operator>=(const map<_Key, _Tp, _Compare, _Allocator>& __x,
1600 const map<_Key, _Tp, _Compare, _Allocator>& __y)
1601{
1602 return !(__x < __y);
1603}
1604
1605template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001606inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001607bool
1608operator<=(const map<_Key, _Tp, _Compare, _Allocator>& __x,
1609 const map<_Key, _Tp, _Compare, _Allocator>& __y)
1610{
1611 return !(__y < __x);
1612}
1613
1614template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001615inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001616void
1617swap(map<_Key, _Tp, _Compare, _Allocator>& __x,
1618 map<_Key, _Tp, _Compare, _Allocator>& __y)
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001619 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
Howard Hinnantc51e1022010-05-11 19:42:16 +00001620{
1621 __x.swap(__y);
1622}
1623
Marshall Clow29b53f22018-12-14 18:49:35 +00001624#if _LIBCPP_STD_VER > 17
1625template <class _Key, class _Tp, class _Compare, class _Allocator, class _Predicate>
1626inline _LIBCPP_INLINE_VISIBILITY
1627void erase_if(map<_Key, _Tp, _Compare, _Allocator>& __c, _Predicate __pred)
1628{ __libcpp_erase_if_container(__c, __pred); }
1629#endif
1630
1631
Howard Hinnantc51e1022010-05-11 19:42:16 +00001632template <class _Key, class _Tp, class _Compare = less<_Key>,
1633 class _Allocator = allocator<pair<const _Key, _Tp> > >
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00001634class _LIBCPP_TEMPLATE_VIS multimap
Howard Hinnantc51e1022010-05-11 19:42:16 +00001635{
1636public:
1637 // types:
1638 typedef _Key key_type;
1639 typedef _Tp mapped_type;
1640 typedef pair<const key_type, mapped_type> value_type;
1641 typedef _Compare key_compare;
1642 typedef _Allocator allocator_type;
1643 typedef value_type& reference;
1644 typedef const value_type& const_reference;
1645
Louis Dionne878a3a82018-12-06 21:46:17 +00001646 static_assert(sizeof(__diagnose_non_const_comparator<_Key, _Compare>()), "");
Marshall Clow5128cf32015-11-26 01:24:04 +00001647 static_assert((is_same<typename allocator_type::value_type, value_type>::value),
1648 "Allocator::value_type must be same type as value_type");
1649
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00001650 class _LIBCPP_TEMPLATE_VIS value_compare
Howard Hinnantc51e1022010-05-11 19:42:16 +00001651 : public binary_function<value_type, value_type, bool>
1652 {
1653 friend class multimap;
1654 protected:
1655 key_compare comp;
1656
Howard Hinnant756c69b2010-09-22 16:48:34 +00001657 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001658 value_compare(key_compare c) : comp(c) {}
1659 public:
Howard Hinnant756c69b2010-09-22 16:48:34 +00001660 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001661 bool operator()(const value_type& __x, const value_type& __y) const
1662 {return comp(__x.first, __y.first);}
1663 };
1664
1665private:
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001666
Howard Hinnant89f8b792013-09-30 19:08:22 +00001667 typedef _VSTD::__value_type<key_type, mapped_type> __value_type;
Howard Hinnant90b91592013-07-05 18:06:00 +00001668 typedef __map_value_compare<key_type, __value_type, key_compare> __vc;
Marshall Clow940e01c2015-04-07 05:21:38 +00001669 typedef typename __rebind_alloc_helper<allocator_traits<allocator_type>,
1670 __value_type>::type __allocator_type;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001671 typedef __tree<__value_type, __vc, __allocator_type> __base;
1672 typedef typename __base::__node_traits __node_traits;
1673 typedef allocator_traits<allocator_type> __alloc_traits;
1674
1675 __base __tree_;
1676
1677public:
1678 typedef typename __alloc_traits::pointer pointer;
1679 typedef typename __alloc_traits::const_pointer const_pointer;
1680 typedef typename __alloc_traits::size_type size_type;
1681 typedef typename __alloc_traits::difference_type difference_type;
1682 typedef __map_iterator<typename __base::iterator> iterator;
1683 typedef __map_const_iterator<typename __base::const_iterator> const_iterator;
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001684 typedef _VSTD::reverse_iterator<iterator> reverse_iterator;
1685 typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001686
Erik Pilkingtonc37a3d82018-08-01 01:33:38 +00001687#if _LIBCPP_STD_VER > 14
1688 typedef __map_node_handle<typename __base::__node, allocator_type> node_type;
1689#endif
1690
Erik Pilkington82a65ad2018-10-31 17:31:35 +00001691 template <class _Key2, class _Value2, class _Comp2, class _Alloc2>
1692 friend class _LIBCPP_TEMPLATE_VIS map;
1693 template <class _Key2, class _Value2, class _Comp2, class _Alloc2>
1694 friend class _LIBCPP_TEMPLATE_VIS multimap;
1695
Howard Hinnant756c69b2010-09-22 16:48:34 +00001696 _LIBCPP_INLINE_VISIBILITY
Marshall Clow7086a5a2014-03-10 04:50:10 +00001697 multimap()
1698 _NOEXCEPT_(
1699 is_nothrow_default_constructible<allocator_type>::value &&
1700 is_nothrow_default_constructible<key_compare>::value &&
1701 is_nothrow_copy_constructible<key_compare>::value)
1702 : __tree_(__vc(key_compare())) {}
1703
1704 _LIBCPP_INLINE_VISIBILITY
1705 explicit multimap(const key_compare& __comp)
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001706 _NOEXCEPT_(
1707 is_nothrow_default_constructible<allocator_type>::value &&
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001708 is_nothrow_copy_constructible<key_compare>::value)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001709 : __tree_(__vc(__comp)) {}
1710
Howard Hinnant756c69b2010-09-22 16:48:34 +00001711 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001712 explicit multimap(const key_compare& __comp, const allocator_type& __a)
Marshall Clow657cbc42016-08-17 05:58:40 +00001713 : __tree_(__vc(__comp), typename __base::allocator_type(__a)) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001714
1715 template <class _InputIterator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001716 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001717 multimap(_InputIterator __f, _InputIterator __l,
1718 const key_compare& __comp = key_compare())
1719 : __tree_(__vc(__comp))
1720 {
1721 insert(__f, __l);
1722 }
1723
1724 template <class _InputIterator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001725 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001726 multimap(_InputIterator __f, _InputIterator __l,
1727 const key_compare& __comp, const allocator_type& __a)
Marshall Clow657cbc42016-08-17 05:58:40 +00001728 : __tree_(__vc(__comp), typename __base::allocator_type(__a))
Howard Hinnantc51e1022010-05-11 19:42:16 +00001729 {
1730 insert(__f, __l);
1731 }
1732
Marshall Clow300abfb2013-09-11 01:15:47 +00001733#if _LIBCPP_STD_VER > 11
1734 template <class _InputIterator>
Eric Fiseliercf8c0212017-01-05 06:06:18 +00001735 _LIBCPP_INLINE_VISIBILITY
Marshall Clow300abfb2013-09-11 01:15:47 +00001736 multimap(_InputIterator __f, _InputIterator __l, const allocator_type& __a)
1737 : multimap(__f, __l, key_compare(), __a) {}
1738#endif
1739
Howard Hinnant756c69b2010-09-22 16:48:34 +00001740 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001741 multimap(const multimap& __m)
1742 : __tree_(__m.__tree_.value_comp(),
1743 __alloc_traits::select_on_container_copy_construction(__m.__tree_.__alloc()))
1744 {
1745 insert(__m.begin(), __m.end());
1746 }
1747
Howard Hinnantd3a657f2011-07-01 19:24:36 +00001748 _LIBCPP_INLINE_VISIBILITY
1749 multimap& operator=(const multimap& __m)
1750 {
Marshall Clow476d3f42016-07-18 13:19:00 +00001751#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantd3a657f2011-07-01 19:24:36 +00001752 __tree_ = __m.__tree_;
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001753#else
Marshall Clowdb3cfcb2014-02-08 04:03:14 +00001754 if (this != &__m) {
1755 __tree_.clear();
1756 __tree_.value_comp() = __m.__tree_.value_comp();
1757 __tree_.__copy_assign_alloc(__m.__tree_);
1758 insert(__m.begin(), __m.end());
1759 }
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001760#endif
Howard Hinnantd3a657f2011-07-01 19:24:36 +00001761 return *this;
1762 }
1763
Eric Fiseliera85b1282017-04-18 21:08:06 +00001764#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001765
Howard Hinnant756c69b2010-09-22 16:48:34 +00001766 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001767 multimap(multimap&& __m)
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001768 _NOEXCEPT_(is_nothrow_move_constructible<__base>::value)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001769 : __tree_(_VSTD::move(__m.__tree_))
Howard Hinnantc51e1022010-05-11 19:42:16 +00001770 {
1771 }
1772
1773 multimap(multimap&& __m, const allocator_type& __a);
1774
Howard Hinnant756c69b2010-09-22 16:48:34 +00001775 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant33711792011-08-12 21:56:02 +00001776 multimap& operator=(multimap&& __m)
1777 _NOEXCEPT_(is_nothrow_move_assignable<__base>::value)
1778 {
1779 __tree_ = _VSTD::move(__m.__tree_);
1780 return *this;
1781 }
1782
Howard Hinnant33711792011-08-12 21:56:02 +00001783 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001784 multimap(initializer_list<value_type> __il, const key_compare& __comp = key_compare())
1785 : __tree_(__vc(__comp))
1786 {
1787 insert(__il.begin(), __il.end());
1788 }
1789
Howard Hinnant756c69b2010-09-22 16:48:34 +00001790 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001791 multimap(initializer_list<value_type> __il, const key_compare& __comp, const allocator_type& __a)
Marshall Clow657cbc42016-08-17 05:58:40 +00001792 : __tree_(__vc(__comp), typename __base::allocator_type(__a))
Howard Hinnantc51e1022010-05-11 19:42:16 +00001793 {
1794 insert(__il.begin(), __il.end());
1795 }
1796
Marshall Clow300abfb2013-09-11 01:15:47 +00001797#if _LIBCPP_STD_VER > 11
Eric Fiseliercf8c0212017-01-05 06:06:18 +00001798 _LIBCPP_INLINE_VISIBILITY
Marshall Clow300abfb2013-09-11 01:15:47 +00001799 multimap(initializer_list<value_type> __il, const allocator_type& __a)
1800 : multimap(__il, key_compare(), __a) {}
1801#endif
1802
Howard Hinnant756c69b2010-09-22 16:48:34 +00001803 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001804 multimap& operator=(initializer_list<value_type> __il)
1805 {
1806 __tree_.__assign_multi(__il.begin(), __il.end());
1807 return *this;
1808 }
Howard Hinnant33711792011-08-12 21:56:02 +00001809
Eric Fiseliera85b1282017-04-18 21:08:06 +00001810#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001811
Howard Hinnant756c69b2010-09-22 16:48:34 +00001812 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001813 explicit multimap(const allocator_type& __a)
Marshall Clow657cbc42016-08-17 05:58:40 +00001814 : __tree_(typename __base::allocator_type(__a))
Howard Hinnantc51e1022010-05-11 19:42:16 +00001815 {
1816 }
1817
Howard Hinnant756c69b2010-09-22 16:48:34 +00001818 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001819 multimap(const multimap& __m, const allocator_type& __a)
Marshall Clow657cbc42016-08-17 05:58:40 +00001820 : __tree_(__m.__tree_.value_comp(), typename __base::allocator_type(__a))
Howard Hinnantc51e1022010-05-11 19:42:16 +00001821 {
1822 insert(__m.begin(), __m.end());
1823 }
1824
Howard Hinnant756c69b2010-09-22 16:48:34 +00001825 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001826 iterator begin() _NOEXCEPT {return __tree_.begin();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001827 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001828 const_iterator begin() const _NOEXCEPT {return __tree_.begin();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001829 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001830 iterator end() _NOEXCEPT {return __tree_.end();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001831 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001832 const_iterator end() const _NOEXCEPT {return __tree_.end();}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001833
Howard Hinnant756c69b2010-09-22 16:48:34 +00001834 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001835 reverse_iterator rbegin() _NOEXCEPT {return reverse_iterator(end());}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001836 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001837 const_reverse_iterator rbegin() const _NOEXCEPT
1838 {return const_reverse_iterator(end());}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001839 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001840 reverse_iterator rend() _NOEXCEPT {return reverse_iterator(begin());}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001841 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001842 const_reverse_iterator rend() const _NOEXCEPT
1843 {return const_reverse_iterator(begin());}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001844
Howard Hinnant756c69b2010-09-22 16:48:34 +00001845 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001846 const_iterator cbegin() const _NOEXCEPT {return begin();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001847 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001848 const_iterator cend() const _NOEXCEPT {return end();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001849 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001850 const_reverse_iterator crbegin() const _NOEXCEPT {return rbegin();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001851 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001852 const_reverse_iterator crend() const _NOEXCEPT {return rend();}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001853
Marshall Clow425f5752017-11-15 05:51:26 +00001854 _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001855 bool empty() const _NOEXCEPT {return __tree_.size() == 0;}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001856 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001857 size_type size() const _NOEXCEPT {return __tree_.size();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001858 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001859 size_type max_size() const _NOEXCEPT {return __tree_.max_size();}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001860
Howard Hinnant756c69b2010-09-22 16:48:34 +00001861 _LIBCPP_INLINE_VISIBILITY
Marshall Clow657cbc42016-08-17 05:58:40 +00001862 allocator_type get_allocator() const _NOEXCEPT {return allocator_type(__tree_.__alloc());}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001863 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001864 key_compare key_comp() const {return __tree_.value_comp().key_comp();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001865 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001866 value_compare value_comp() const
1867 {return value_compare(__tree_.value_comp().key_comp());}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001868
Eric Fiselierd06276b2016-03-31 02:15:15 +00001869#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant74279a52010-09-04 23:28:19 +00001870
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001871 template <class ..._Args>
Eric Fiselierd06276b2016-03-31 02:15:15 +00001872 _LIBCPP_INLINE_VISIBILITY
1873 iterator emplace(_Args&& ...__args) {
1874 return __tree_.__emplace_multi(_VSTD::forward<_Args>(__args)...);
1875 }
Howard Hinnantc51e1022010-05-11 19:42:16 +00001876
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001877 template <class ..._Args>
Eric Fiselierd06276b2016-03-31 02:15:15 +00001878 _LIBCPP_INLINE_VISIBILITY
1879 iterator emplace_hint(const_iterator __p, _Args&& ...__args) {
1880 return __tree_.__emplace_hint_multi(__p.__i_, _VSTD::forward<_Args>(__args)...);
1881 }
Howard Hinnant74279a52010-09-04 23:28:19 +00001882
Howard Hinnantc834c512011-11-29 18:15:50 +00001883 template <class _Pp,
1884 class = typename enable_if<is_constructible<value_type, _Pp>::value>::type>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001885 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc834c512011-11-29 18:15:50 +00001886 iterator insert(_Pp&& __p)
1887 {return __tree_.__insert_multi(_VSTD::forward<_Pp>(__p));}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001888
Howard Hinnantc834c512011-11-29 18:15:50 +00001889 template <class _Pp,
1890 class = typename enable_if<is_constructible<value_type, _Pp>::value>::type>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001891 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc834c512011-11-29 18:15:50 +00001892 iterator insert(const_iterator __pos, _Pp&& __p)
1893 {return __tree_.__insert_multi(__pos.__i_, _VSTD::forward<_Pp>(__p));}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001894
Eric Fiselierd6143132016-04-18 01:40:45 +00001895 _LIBCPP_INLINE_VISIBILITY
1896 iterator insert(value_type&& __v)
1897 {return __tree_.__insert_multi(_VSTD::move(__v));}
1898
1899 _LIBCPP_INLINE_VISIBILITY
1900 iterator insert(const_iterator __p, value_type&& __v)
1901 {return __tree_.__insert_multi(__p.__i_, _VSTD::move(__v));}
1902
Eric Fiseliera85b1282017-04-18 21:08:06 +00001903
1904 _LIBCPP_INLINE_VISIBILITY
1905 void insert(initializer_list<value_type> __il)
1906 {insert(__il.begin(), __il.end());}
1907
Eric Fiselierd06276b2016-03-31 02:15:15 +00001908#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001909
Howard Hinnant756c69b2010-09-22 16:48:34 +00001910 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001911 iterator insert(const value_type& __v) {return __tree_.__insert_multi(__v);}
1912
Howard Hinnant756c69b2010-09-22 16:48:34 +00001913 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001914 iterator insert(const_iterator __p, const value_type& __v)
1915 {return __tree_.__insert_multi(__p.__i_, __v);}
1916
1917 template <class _InputIterator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001918 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001919 void insert(_InputIterator __f, _InputIterator __l)
1920 {
1921 for (const_iterator __e = cend(); __f != __l; ++__f)
1922 __tree_.__insert_multi(__e.__i_, *__f);
1923 }
1924
Howard Hinnant756c69b2010-09-22 16:48:34 +00001925 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001926 iterator erase(const_iterator __p) {return __tree_.erase(__p.__i_);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001927 _LIBCPP_INLINE_VISIBILITY
Marshall Clow22ea5b82015-05-10 13:35:00 +00001928 iterator erase(iterator __p) {return __tree_.erase(__p.__i_);}
1929 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001930 size_type erase(const key_type& __k) {return __tree_.__erase_multi(__k);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001931 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001932 iterator erase(const_iterator __f, const_iterator __l)
1933 {return __tree_.erase(__f.__i_, __l.__i_);}
Erik Pilkingtonc37a3d82018-08-01 01:33:38 +00001934
1935#if _LIBCPP_STD_VER > 14
1936 _LIBCPP_INLINE_VISIBILITY
1937 iterator insert(node_type&& __nh)
1938 {
1939 _LIBCPP_ASSERT(__nh.empty() || __nh.get_allocator() == get_allocator(),
1940 "node_type with incompatible allocator passed to multimap::insert()");
1941 return __tree_.template __node_handle_insert_multi<node_type>(
1942 _VSTD::move(__nh));
1943 }
1944 _LIBCPP_INLINE_VISIBILITY
1945 iterator insert(const_iterator __hint, node_type&& __nh)
1946 {
1947 _LIBCPP_ASSERT(__nh.empty() || __nh.get_allocator() == get_allocator(),
1948 "node_type with incompatible allocator passed to multimap::insert()");
1949 return __tree_.template __node_handle_insert_multi<node_type>(
1950 __hint.__i_, _VSTD::move(__nh));
1951 }
1952 _LIBCPP_INLINE_VISIBILITY
1953 node_type extract(key_type const& __key)
1954 {
1955 return __tree_.template __node_handle_extract<node_type>(__key);
1956 }
1957 _LIBCPP_INLINE_VISIBILITY
1958 node_type extract(const_iterator __it)
1959 {
1960 return __tree_.template __node_handle_extract<node_type>(
1961 __it.__i_);
1962 }
Louis Dionned2322c82018-11-01 14:41:37 +00001963 template <class _Compare2>
Erik Pilkington82a65ad2018-10-31 17:31:35 +00001964 _LIBCPP_INLINE_VISIBILITY
Louis Dionned2322c82018-11-01 14:41:37 +00001965 void merge(multimap<key_type, mapped_type, _Compare2, allocator_type>& __source)
Erik Pilkington82a65ad2018-10-31 17:31:35 +00001966 {
1967 _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
1968 "merging container with incompatible allocator");
1969 return __tree_.__node_handle_merge_multi(__source.__tree_);
1970 }
Louis Dionned2322c82018-11-01 14:41:37 +00001971 template <class _Compare2>
Erik Pilkington82a65ad2018-10-31 17:31:35 +00001972 _LIBCPP_INLINE_VISIBILITY
Louis Dionned2322c82018-11-01 14:41:37 +00001973 void merge(multimap<key_type, mapped_type, _Compare2, allocator_type>&& __source)
Erik Pilkington82a65ad2018-10-31 17:31:35 +00001974 {
1975 _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
1976 "merging container with incompatible allocator");
1977 return __tree_.__node_handle_merge_multi(__source.__tree_);
1978 }
Louis Dionned2322c82018-11-01 14:41:37 +00001979 template <class _Compare2>
Erik Pilkington82a65ad2018-10-31 17:31:35 +00001980 _LIBCPP_INLINE_VISIBILITY
Louis Dionned2322c82018-11-01 14:41:37 +00001981 void merge(map<key_type, mapped_type, _Compare2, allocator_type>& __source)
Erik Pilkington82a65ad2018-10-31 17:31:35 +00001982 {
1983 _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
1984 "merging container with incompatible allocator");
1985 return __tree_.__node_handle_merge_multi(__source.__tree_);
1986 }
Louis Dionned2322c82018-11-01 14:41:37 +00001987 template <class _Compare2>
Erik Pilkington82a65ad2018-10-31 17:31:35 +00001988 _LIBCPP_INLINE_VISIBILITY
Louis Dionned2322c82018-11-01 14:41:37 +00001989 void merge(map<key_type, mapped_type, _Compare2, allocator_type>&& __source)
Erik Pilkington82a65ad2018-10-31 17:31:35 +00001990 {
1991 _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
1992 "merging container with incompatible allocator");
1993 return __tree_.__node_handle_merge_multi(__source.__tree_);
1994 }
Erik Pilkingtonc37a3d82018-08-01 01:33:38 +00001995#endif
1996
Howard Hinnant756c69b2010-09-22 16:48:34 +00001997 _LIBCPP_INLINE_VISIBILITY
Marshall Clowde1312a2018-08-22 04:28:43 +00001998 void clear() _NOEXCEPT {__tree_.clear();}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001999
Howard Hinnant756c69b2010-09-22 16:48:34 +00002000 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00002001 void swap(multimap& __m)
2002 _NOEXCEPT_(__is_nothrow_swappable<__base>::value)
2003 {__tree_.swap(__m.__tree_);}
Howard Hinnantc51e1022010-05-11 19:42:16 +00002004
Howard Hinnant756c69b2010-09-22 16:48:34 +00002005 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002006 iterator find(const key_type& __k) {return __tree_.find(__k);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00002007 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002008 const_iterator find(const key_type& __k) const {return __tree_.find(__k);}
Marshall Clowebb57322013-08-13 22:18:47 +00002009#if _LIBCPP_STD_VER > 11
2010 template <typename _K2>
2011 _LIBCPP_INLINE_VISIBILITY
2012 typename enable_if<__is_transparent<_Compare, _K2>::value,iterator>::type
2013 find(const _K2& __k) {return __tree_.find(__k);}
2014 template <typename _K2>
2015 _LIBCPP_INLINE_VISIBILITY
2016 typename enable_if<__is_transparent<_Compare, _K2>::value,const_iterator>::type
2017 find(const _K2& __k) const {return __tree_.find(__k);}
2018#endif
2019
Howard Hinnant756c69b2010-09-22 16:48:34 +00002020 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002021 size_type count(const key_type& __k) const
2022 {return __tree_.__count_multi(__k);}
Marshall Clowe6a5f522014-08-24 23:54:16 +00002023#if _LIBCPP_STD_VER > 11
2024 template <typename _K2>
2025 _LIBCPP_INLINE_VISIBILITY
2026 typename enable_if<__is_transparent<_Compare, _K2>::value,size_type>::type
Marshall Clow141e47b2015-06-30 18:15:41 +00002027 count(const _K2& __k) const {return __tree_.__count_multi(__k);}
Marshall Clowe6a5f522014-08-24 23:54:16 +00002028#endif
Howard Hinnant756c69b2010-09-22 16:48:34 +00002029 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002030 iterator lower_bound(const key_type& __k)
2031 {return __tree_.lower_bound(__k);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00002032 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002033 const_iterator lower_bound(const key_type& __k) const
2034 {return __tree_.lower_bound(__k);}
Marshall Clowebb57322013-08-13 22:18:47 +00002035#if _LIBCPP_STD_VER > 11
2036 template <typename _K2>
2037 _LIBCPP_INLINE_VISIBILITY
2038 typename enable_if<__is_transparent<_Compare, _K2>::value,iterator>::type
2039 lower_bound(const _K2& __k) {return __tree_.lower_bound(__k);}
2040
2041 template <typename _K2>
2042 _LIBCPP_INLINE_VISIBILITY
2043 typename enable_if<__is_transparent<_Compare, _K2>::value,const_iterator>::type
2044 lower_bound(const _K2& __k) const {return __tree_.lower_bound(__k);}
2045#endif
2046
Howard Hinnant756c69b2010-09-22 16:48:34 +00002047 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002048 iterator upper_bound(const key_type& __k)
2049 {return __tree_.upper_bound(__k);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00002050 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002051 const_iterator upper_bound(const key_type& __k) const
2052 {return __tree_.upper_bound(__k);}
Marshall Clowebb57322013-08-13 22:18:47 +00002053#if _LIBCPP_STD_VER > 11
2054 template <typename _K2>
2055 _LIBCPP_INLINE_VISIBILITY
2056 typename enable_if<__is_transparent<_Compare, _K2>::value,iterator>::type
2057 upper_bound(const _K2& __k) {return __tree_.upper_bound(__k);}
2058 template <typename _K2>
2059 _LIBCPP_INLINE_VISIBILITY
2060 typename enable_if<__is_transparent<_Compare, _K2>::value,const_iterator>::type
2061 upper_bound(const _K2& __k) const {return __tree_.upper_bound(__k);}
2062#endif
2063
Howard Hinnant756c69b2010-09-22 16:48:34 +00002064 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002065 pair<iterator,iterator> equal_range(const key_type& __k)
2066 {return __tree_.__equal_range_multi(__k);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00002067 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002068 pair<const_iterator,const_iterator> equal_range(const key_type& __k) const
2069 {return __tree_.__equal_range_multi(__k);}
Marshall Clowebb57322013-08-13 22:18:47 +00002070#if _LIBCPP_STD_VER > 11
2071 template <typename _K2>
2072 _LIBCPP_INLINE_VISIBILITY
2073 typename enable_if<__is_transparent<_Compare, _K2>::value,pair<iterator,iterator>>::type
2074 equal_range(const _K2& __k) {return __tree_.__equal_range_multi(__k);}
2075 template <typename _K2>
2076 _LIBCPP_INLINE_VISIBILITY
2077 typename enable_if<__is_transparent<_Compare, _K2>::value,pair<const_iterator,const_iterator>>::type
2078 equal_range(const _K2& __k) const {return __tree_.__equal_range_multi(__k);}
2079#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00002080
2081private:
2082 typedef typename __base::__node __node;
2083 typedef typename __base::__node_allocator __node_allocator;
2084 typedef typename __base::__node_pointer __node_pointer;
Eric Fiseliera92b0732016-02-20 07:12:17 +00002085
Howard Hinnantc834c512011-11-29 18:15:50 +00002086 typedef __map_node_destructor<__node_allocator> _Dp;
2087 typedef unique_ptr<__node, _Dp> __node_holder;
Howard Hinnantc51e1022010-05-11 19:42:16 +00002088};
2089
Eric Fiselierd06276b2016-03-31 02:15:15 +00002090#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00002091template <class _Key, class _Tp, class _Compare, class _Allocator>
2092multimap<_Key, _Tp, _Compare, _Allocator>::multimap(multimap&& __m, const allocator_type& __a)
Marshall Clow657cbc42016-08-17 05:58:40 +00002093 : __tree_(_VSTD::move(__m.__tree_), typename __base::allocator_type(__a))
Howard Hinnantc51e1022010-05-11 19:42:16 +00002094{
2095 if (__a != __m.get_allocator())
2096 {
2097 const_iterator __e = cend();
2098 while (!__m.empty())
2099 __tree_.__insert_multi(__e.__i_,
Erik Pilkingtond3fe2992018-06-04 20:38:23 +00002100 _VSTD::move(__m.__tree_.remove(__m.begin().__i_)->__value_.__move()));
Howard Hinnantc51e1022010-05-11 19:42:16 +00002101 }
2102}
Eric Fiselierd06276b2016-03-31 02:15:15 +00002103#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00002104
2105template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00002106inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002107bool
2108operator==(const multimap<_Key, _Tp, _Compare, _Allocator>& __x,
2109 const multimap<_Key, _Tp, _Compare, _Allocator>& __y)
2110{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00002111 return __x.size() == __y.size() && _VSTD::equal(__x.begin(), __x.end(), __y.begin());
Howard Hinnantc51e1022010-05-11 19:42:16 +00002112}
2113
2114template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00002115inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002116bool
2117operator< (const multimap<_Key, _Tp, _Compare, _Allocator>& __x,
2118 const multimap<_Key, _Tp, _Compare, _Allocator>& __y)
2119{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00002120 return _VSTD::lexicographical_compare(__x.begin(), __x.end(), __y.begin(), __y.end());
Howard Hinnantc51e1022010-05-11 19:42:16 +00002121}
2122
2123template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00002124inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002125bool
2126operator!=(const multimap<_Key, _Tp, _Compare, _Allocator>& __x,
2127 const multimap<_Key, _Tp, _Compare, _Allocator>& __y)
2128{
2129 return !(__x == __y);
2130}
2131
2132template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00002133inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002134bool
2135operator> (const multimap<_Key, _Tp, _Compare, _Allocator>& __x,
2136 const multimap<_Key, _Tp, _Compare, _Allocator>& __y)
2137{
2138 return __y < __x;
2139}
2140
2141template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00002142inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002143bool
2144operator>=(const multimap<_Key, _Tp, _Compare, _Allocator>& __x,
2145 const multimap<_Key, _Tp, _Compare, _Allocator>& __y)
2146{
2147 return !(__x < __y);
2148}
2149
2150template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00002151inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002152bool
2153operator<=(const multimap<_Key, _Tp, _Compare, _Allocator>& __x,
2154 const multimap<_Key, _Tp, _Compare, _Allocator>& __y)
2155{
2156 return !(__y < __x);
2157}
2158
2159template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00002160inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002161void
2162swap(multimap<_Key, _Tp, _Compare, _Allocator>& __x,
2163 multimap<_Key, _Tp, _Compare, _Allocator>& __y)
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00002164 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
Howard Hinnantc51e1022010-05-11 19:42:16 +00002165{
2166 __x.swap(__y);
2167}
2168
Marshall Clow29b53f22018-12-14 18:49:35 +00002169#if _LIBCPP_STD_VER > 17
2170template <class _Key, class _Tp, class _Compare, class _Allocator, class _Predicate>
2171inline _LIBCPP_INLINE_VISIBILITY
2172void erase_if(multimap<_Key, _Tp, _Compare, _Allocator>& __c, _Predicate __pred)
2173{ __libcpp_erase_if_container(__c, __pred); }
2174#endif
2175
Howard Hinnantc51e1022010-05-11 19:42:16 +00002176_LIBCPP_END_NAMESPACE_STD
2177
2178#endif // _LIBCPP_MAP