blob: 97ce4d0b18c7cf2d71ad1037f9b949066c712af2 [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;
43
44 class value_compare
45 : public binary_function<value_type, value_type, bool>
46 {
47 friend class map;
48 protected:
49 key_compare comp;
50
51 value_compare(key_compare c);
52 public:
53 bool operator()(const value_type& x, const value_type& y) const;
54 };
55
56 // construct/copy/destroy:
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +000057 map()
58 noexcept(
59 is_nothrow_default_constructible<allocator_type>::value &&
60 is_nothrow_default_constructible<key_compare>::value &&
61 is_nothrow_copy_constructible<key_compare>::value);
Howard Hinnantc51e1022010-05-11 19:42:16 +000062 explicit map(const key_compare& comp);
63 map(const key_compare& comp, const allocator_type& a);
64 template <class InputIterator>
65 map(InputIterator first, InputIterator last,
66 const key_compare& comp = key_compare());
67 template <class InputIterator>
68 map(InputIterator first, InputIterator last,
69 const key_compare& comp, const allocator_type& a);
70 map(const map& m);
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +000071 map(map&& m)
72 noexcept(
73 is_nothrow_move_constructible<allocator_type>::value &&
74 is_nothrow_move_constructible<key_compare>::value);
Howard Hinnantc51e1022010-05-11 19:42:16 +000075 explicit map(const allocator_type& a);
76 map(const map& m, const allocator_type& a);
77 map(map&& m, const allocator_type& a);
78 map(initializer_list<value_type> il, const key_compare& comp = key_compare());
79 map(initializer_list<value_type> il, const key_compare& comp, const allocator_type& a);
Marshall Clow300abfb2013-09-11 01:15:47 +000080 template <class InputIterator>
81 map(InputIterator first, InputIterator last, const allocator_type& a)
82 : map(first, last, Compare(), a) {} // C++14
83 map(initializer_list<value_type> il, const allocator_type& a)
84 : map(il, Compare(), a) {} // C++14
85 ~map();
Howard Hinnantc51e1022010-05-11 19:42:16 +000086
87 map& operator=(const map& m);
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +000088 map& operator=(map&& m)
89 noexcept(
90 allocator_type::propagate_on_container_move_assignment::value &&
91 is_nothrow_move_assignable<allocator_type>::value &&
Howard Hinnantf95f4f52011-06-04 15:22:34 +000092 is_nothrow_move_assignable<key_compare>::value);
Howard Hinnantc51e1022010-05-11 19:42:16 +000093 map& operator=(initializer_list<value_type> il);
94
95 // iterators:
Howard Hinnantf95f4f52011-06-04 15:22:34 +000096 iterator begin() noexcept;
97 const_iterator begin() const noexcept;
98 iterator end() noexcept;
99 const_iterator end() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000100
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000101 reverse_iterator rbegin() noexcept;
102 const_reverse_iterator rbegin() const noexcept;
103 reverse_iterator rend() noexcept;
104 const_reverse_iterator rend() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000105
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000106 const_iterator cbegin() const noexcept;
107 const_iterator cend() const noexcept;
108 const_reverse_iterator crbegin() const noexcept;
109 const_reverse_iterator crend() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000110
111 // capacity:
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000112 bool empty() const noexcept;
113 size_type size() const noexcept;
114 size_type max_size() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000115
116 // element access:
117 mapped_type& operator[](const key_type& k);
118 mapped_type& operator[](key_type&& k);
119
120 mapped_type& at(const key_type& k);
121 const mapped_type& at(const key_type& k) const;
122
123 // modifiers:
124 template <class... Args>
125 pair<iterator, bool> emplace(Args&&... args);
126 template <class... Args>
127 iterator emplace_hint(const_iterator position, Args&&... args);
128 pair<iterator, bool> insert(const value_type& v);
Marshall Clowd430d022016-01-05 19:32:41 +0000129 pair<iterator, bool> insert( value_type&& v); // C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000130 template <class P>
131 pair<iterator, bool> insert(P&& p);
132 iterator insert(const_iterator position, const value_type& v);
Marshall Clowd430d022016-01-05 19:32:41 +0000133 iterator insert(const_iterator position, value_type&& v); // C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000134 template <class P>
135 iterator insert(const_iterator position, P&& p);
136 template <class InputIterator>
137 void insert(InputIterator first, InputIterator last);
138 void insert(initializer_list<value_type> il);
139
Marshall Clow3223db82015-07-07 03:37:33 +0000140 template <class... Args>
141 pair<iterator, bool> try_emplace(const key_type& k, Args&&... args); // C++17
142 template <class... Args>
143 pair<iterator, bool> try_emplace(key_type&& k, Args&&... args); // C++17
144 template <class... Args>
145 iterator try_emplace(const_iterator hint, const key_type& k, Args&&... args); // C++17
146 template <class... Args>
147 iterator try_emplace(const_iterator hint, key_type&& k, Args&&... args); // C++17
148 template <class M>
149 pair<iterator, bool> insert_or_assign(const key_type& k, M&& obj); // C++17
150 template <class M>
151 pair<iterator, bool> insert_or_assign(key_type&& k, M&& obj); // C++17
152 template <class M>
153 iterator insert_or_assign(const_iterator hint, const key_type& k, M&& obj); // C++17
154 template <class M>
155 iterator insert_or_assign(const_iterator hint, key_type&& k, M&& obj); // C++17
156
Howard Hinnantc51e1022010-05-11 19:42:16 +0000157 iterator erase(const_iterator position);
Marshall Clow22ea5b82015-05-10 13:35:00 +0000158 iterator erase(iterator position); // C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000159 size_type erase(const key_type& k);
160 iterator erase(const_iterator first, const_iterator last);
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000161 void clear() noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000162
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000163 void swap(map& m)
Marshall Clow8982dcd2015-07-13 20:04:56 +0000164 noexcept(allocator_traits<allocator_type>::is_always_equal::value &&
Eric Fiselier6bfed252016-04-21 23:38:59 +0000165 is_nothrow_swappable<key_compare>::value); // C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000166
167 // observers:
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000168 allocator_type get_allocator() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000169 key_compare key_comp() const;
170 value_compare value_comp() const;
171
172 // map operations:
173 iterator find(const key_type& k);
174 const_iterator find(const key_type& k) const;
Marshall Clowebb57322013-08-13 22:18:47 +0000175 template<typename K>
176 iterator find(const K& x); // C++14
177 template<typename K>
178 const_iterator find(const K& x) const; // C++14
179 template<typename K>
Marshall Clowe6a5f522014-08-24 23:54:16 +0000180 size_type count(const K& x) const; // C++14
Marshall Clowebb57322013-08-13 22:18:47 +0000181
Howard Hinnantc51e1022010-05-11 19:42:16 +0000182 size_type count(const key_type& k) const;
183 iterator lower_bound(const key_type& k);
184 const_iterator lower_bound(const key_type& k) const;
Marshall Clowebb57322013-08-13 22:18:47 +0000185 template<typename K>
186 iterator lower_bound(const K& x); // C++14
187 template<typename K>
188 const_iterator lower_bound(const K& x) const; // C++14
189
Howard Hinnantc51e1022010-05-11 19:42:16 +0000190 iterator upper_bound(const key_type& k);
191 const_iterator upper_bound(const key_type& k) const;
Marshall Clowebb57322013-08-13 22:18:47 +0000192 template<typename K>
193 iterator upper_bound(const K& x); // C++14
194 template<typename K>
195 const_iterator upper_bound(const K& x) const; // C++14
196
Howard Hinnantc51e1022010-05-11 19:42:16 +0000197 pair<iterator,iterator> equal_range(const key_type& k);
198 pair<const_iterator,const_iterator> equal_range(const key_type& k) const;
Marshall Clowebb57322013-08-13 22:18:47 +0000199 template<typename K>
200 pair<iterator,iterator> equal_range(const K& x); // C++14
201 template<typename K>
202 pair<const_iterator,const_iterator> equal_range(const K& x) const; // C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000203};
204
205template <class Key, class T, class Compare, class Allocator>
206bool
207operator==(const map<Key, T, Compare, Allocator>& x,
208 const map<Key, T, Compare, Allocator>& y);
209
210template <class Key, class T, class Compare, class Allocator>
211bool
212operator< (const map<Key, T, Compare, Allocator>& x,
213 const map<Key, T, Compare, Allocator>& y);
214
215template <class Key, class T, class Compare, class Allocator>
216bool
217operator!=(const map<Key, T, Compare, Allocator>& x,
218 const map<Key, T, Compare, Allocator>& y);
219
220template <class Key, class T, class Compare, class Allocator>
221bool
222operator> (const map<Key, T, Compare, Allocator>& x,
223 const map<Key, T, Compare, Allocator>& y);
224
225template <class Key, class T, class Compare, class Allocator>
226bool
227operator>=(const map<Key, T, Compare, Allocator>& x,
228 const map<Key, T, Compare, Allocator>& y);
229
230template <class Key, class T, class Compare, class Allocator>
231bool
232operator<=(const map<Key, T, Compare, Allocator>& x,
233 const map<Key, T, Compare, Allocator>& y);
234
235// specialized algorithms:
236template <class Key, class T, class Compare, class Allocator>
237void
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000238swap(map<Key, T, Compare, Allocator>& x, map<Key, T, Compare, Allocator>& y)
239 noexcept(noexcept(x.swap(y)));
Howard Hinnantc51e1022010-05-11 19:42:16 +0000240
241template <class Key, class T, class Compare = less<Key>,
242 class Allocator = allocator<pair<const Key, T>>>
243class multimap
244{
245public:
246 // types:
247 typedef Key key_type;
248 typedef T mapped_type;
249 typedef pair<const key_type,mapped_type> value_type;
250 typedef Compare key_compare;
251 typedef Allocator allocator_type;
252 typedef typename allocator_type::reference reference;
253 typedef typename allocator_type::const_reference const_reference;
254 typedef typename allocator_type::size_type size_type;
255 typedef typename allocator_type::difference_type difference_type;
256 typedef typename allocator_type::pointer pointer;
257 typedef typename allocator_type::const_pointer const_pointer;
258
259 typedef implementation-defined iterator;
260 typedef implementation-defined const_iterator;
261 typedef std::reverse_iterator<iterator> reverse_iterator;
262 typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
263
264 class value_compare
265 : public binary_function<value_type,value_type,bool>
266 {
267 friend class multimap;
268 protected:
269 key_compare comp;
270 value_compare(key_compare c);
271 public:
272 bool operator()(const value_type& x, const value_type& y) const;
273 };
274
275 // construct/copy/destroy:
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000276 multimap()
277 noexcept(
278 is_nothrow_default_constructible<allocator_type>::value &&
279 is_nothrow_default_constructible<key_compare>::value &&
280 is_nothrow_copy_constructible<key_compare>::value);
281 explicit multimap(const key_compare& comp);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000282 multimap(const key_compare& comp, const allocator_type& a);
283 template <class InputIterator>
284 multimap(InputIterator first, InputIterator last, const key_compare& comp);
285 template <class InputIterator>
286 multimap(InputIterator first, InputIterator last, const key_compare& comp,
287 const allocator_type& a);
288 multimap(const multimap& m);
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000289 multimap(multimap&& m)
290 noexcept(
291 is_nothrow_move_constructible<allocator_type>::value &&
292 is_nothrow_move_constructible<key_compare>::value);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000293 explicit multimap(const allocator_type& a);
294 multimap(const multimap& m, const allocator_type& a);
295 multimap(multimap&& m, const allocator_type& a);
296 multimap(initializer_list<value_type> il, const key_compare& comp = key_compare());
297 multimap(initializer_list<value_type> il, const key_compare& comp,
298 const allocator_type& a);
Marshall Clow300abfb2013-09-11 01:15:47 +0000299 template <class InputIterator>
300 multimap(InputIterator first, InputIterator last, const allocator_type& a)
301 : multimap(first, last, Compare(), a) {} // C++14
302 multimap(initializer_list<value_type> il, const allocator_type& a)
303 : multimap(il, Compare(), a) {} // C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000304 ~multimap();
305
306 multimap& operator=(const multimap& m);
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000307 multimap& operator=(multimap&& m)
308 noexcept(
309 allocator_type::propagate_on_container_move_assignment::value &&
310 is_nothrow_move_assignable<allocator_type>::value &&
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000311 is_nothrow_move_assignable<key_compare>::value);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000312 multimap& operator=(initializer_list<value_type> il);
313
314 // iterators:
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000315 iterator begin() noexcept;
316 const_iterator begin() const noexcept;
317 iterator end() noexcept;
318 const_iterator end() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000319
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000320 reverse_iterator rbegin() noexcept;
321 const_reverse_iterator rbegin() const noexcept;
322 reverse_iterator rend() noexcept;
323 const_reverse_iterator rend() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000324
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000325 const_iterator cbegin() const noexcept;
326 const_iterator cend() const noexcept;
327 const_reverse_iterator crbegin() const noexcept;
328 const_reverse_iterator crend() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000329
330 // capacity:
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000331 bool empty() const noexcept;
332 size_type size() const noexcept;
333 size_type max_size() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000334
335 // modifiers:
336 template <class... Args>
337 iterator emplace(Args&&... args);
338 template <class... Args>
339 iterator emplace_hint(const_iterator position, Args&&... args);
340 iterator insert(const value_type& v);
Marshall Clowd430d022016-01-05 19:32:41 +0000341 iterator insert( value_type&& v); // C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000342 template <class P>
343 iterator insert(P&& p);
344 iterator insert(const_iterator position, const value_type& v);
Marshall Clowd430d022016-01-05 19:32:41 +0000345 iterator insert(const_iterator position, value_type&& v); // C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000346 template <class P>
347 iterator insert(const_iterator position, P&& p);
348 template <class InputIterator>
349 void insert(InputIterator first, InputIterator last);
350 void insert(initializer_list<value_type> il);
351
352 iterator erase(const_iterator position);
Marshall Clow22ea5b82015-05-10 13:35:00 +0000353 iterator erase(iterator position); // C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000354 size_type erase(const key_type& k);
355 iterator erase(const_iterator first, const_iterator last);
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000356 void clear() noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000357
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000358 void swap(multimap& m)
Marshall Clow8982dcd2015-07-13 20:04:56 +0000359 noexcept(allocator_traits<allocator_type>::is_always_equal::value &&
Eric Fiselier6bfed252016-04-21 23:38:59 +0000360 is_nothrow_swappable<key_compare>::value); // C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000361
362 // observers:
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000363 allocator_type get_allocator() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000364 key_compare key_comp() const;
365 value_compare value_comp() const;
366
367 // map operations:
368 iterator find(const key_type& k);
369 const_iterator find(const key_type& k) const;
Marshall Clowebb57322013-08-13 22:18:47 +0000370 template<typename K>
371 iterator find(const K& x); // C++14
372 template<typename K>
373 const_iterator find(const K& x) const; // C++14
374 template<typename K>
Marshall Clowe6a5f522014-08-24 23:54:16 +0000375 size_type count(const K& x) const; // C++14
Marshall Clowebb57322013-08-13 22:18:47 +0000376
Howard Hinnantc51e1022010-05-11 19:42:16 +0000377 size_type count(const key_type& k) const;
378 iterator lower_bound(const key_type& k);
379 const_iterator lower_bound(const key_type& k) const;
Marshall Clowebb57322013-08-13 22:18:47 +0000380 template<typename K>
381 iterator lower_bound(const K& x); // C++14
382 template<typename K>
383 const_iterator lower_bound(const K& x) const; // C++14
384
Howard Hinnantc51e1022010-05-11 19:42:16 +0000385 iterator upper_bound(const key_type& k);
386 const_iterator upper_bound(const key_type& k) const;
Marshall Clowebb57322013-08-13 22:18:47 +0000387 template<typename K>
388 iterator upper_bound(const K& x); // C++14
389 template<typename K>
390 const_iterator upper_bound(const K& x) const; // C++14
391
Howard Hinnantc51e1022010-05-11 19:42:16 +0000392 pair<iterator,iterator> equal_range(const key_type& k);
393 pair<const_iterator,const_iterator> equal_range(const key_type& k) const;
Marshall Clowebb57322013-08-13 22:18:47 +0000394 template<typename K>
395 pair<iterator,iterator> equal_range(const K& x); // C++14
396 template<typename K>
397 pair<const_iterator,const_iterator> equal_range(const K& x) const; // C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000398};
399
400template <class Key, class T, class Compare, class Allocator>
401bool
402operator==(const multimap<Key, T, Compare, Allocator>& x,
403 const multimap<Key, T, Compare, Allocator>& y);
404
405template <class Key, class T, class Compare, class Allocator>
406bool
407operator< (const multimap<Key, T, Compare, Allocator>& x,
408 const multimap<Key, T, Compare, Allocator>& y);
409
410template <class Key, class T, class Compare, class Allocator>
411bool
412operator!=(const multimap<Key, T, Compare, Allocator>& x,
413 const multimap<Key, T, Compare, Allocator>& y);
414
415template <class Key, class T, class Compare, class Allocator>
416bool
417operator> (const multimap<Key, T, Compare, Allocator>& x,
418 const multimap<Key, T, Compare, Allocator>& y);
419
420template <class Key, class T, class Compare, class Allocator>
421bool
422operator>=(const multimap<Key, T, Compare, Allocator>& x,
423 const multimap<Key, T, Compare, Allocator>& y);
424
425template <class Key, class T, class Compare, class Allocator>
426bool
427operator<=(const multimap<Key, T, Compare, Allocator>& x,
428 const multimap<Key, T, Compare, Allocator>& y);
429
430// specialized algorithms:
431template <class Key, class T, class Compare, class Allocator>
432void
433swap(multimap<Key, T, Compare, Allocator>& x,
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000434 multimap<Key, T, Compare, Allocator>& y)
435 noexcept(noexcept(x.swap(y)));
Howard Hinnantc51e1022010-05-11 19:42:16 +0000436
437} // std
438
439*/
440
441#include <__config>
442#include <__tree>
443#include <iterator>
444#include <memory>
445#include <utility>
446#include <functional>
447#include <initializer_list>
Eric Fiselierf7394302015-06-13 07:08:02 +0000448#include <type_traits>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000449
Howard Hinnantaaaa52b2011-10-17 20:05:10 +0000450#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000451#pragma GCC system_header
Howard Hinnantaaaa52b2011-10-17 20:05:10 +0000452#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000453
454_LIBCPP_BEGIN_NAMESPACE_STD
455
Eric Fiseliera7a14ed2017-01-13 22:02:08 +0000456template <class _Key, class _CP, class _Compare, bool _IsSmall>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000457class __map_value_compare
458 : private _Compare
459{
Howard Hinnantc51e1022010-05-11 19:42:16 +0000460public:
Howard Hinnant756c69b2010-09-22 16:48:34 +0000461 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000462 __map_value_compare()
463 _NOEXCEPT_(is_nothrow_default_constructible<_Compare>::value)
464 : _Compare() {}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000465 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000466 __map_value_compare(_Compare c)
467 _NOEXCEPT_(is_nothrow_copy_constructible<_Compare>::value)
468 : _Compare(c) {}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000469 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000470 const _Compare& key_comp() const _NOEXCEPT {return *this;}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000471 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000472 bool operator()(const _CP& __x, const _CP& __y) const
Erik Pilkingtond3fe2992018-06-04 20:38:23 +0000473 {return static_cast<const _Compare&>(*this)(__x.__get_value().first, __y.__get_value().first);}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000474 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000475 bool operator()(const _CP& __x, const _Key& __y) const
Erik Pilkingtond3fe2992018-06-04 20:38:23 +0000476 {return static_cast<const _Compare&>(*this)(__x.__get_value().first, __y);}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000477 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000478 bool operator()(const _Key& __x, const _CP& __y) const
Erik Pilkingtond3fe2992018-06-04 20:38:23 +0000479 {return static_cast<const _Compare&>(*this)(__x, __y.__get_value().first);}
Marshall Clow8982dcd2015-07-13 20:04:56 +0000480 void swap(__map_value_compare&__y)
481 _NOEXCEPT_(__is_nothrow_swappable<_Compare>::value)
482 {
Eric Fiselier68b5f0b2017-04-13 00:34:24 +0000483 using _VSTD::swap;
484 swap(static_cast<_Compare&>(*this), static_cast<_Compare&>(__y));
Marshall Clow8982dcd2015-07-13 20:04:56 +0000485 }
Marshall Clowebb57322013-08-13 22:18:47 +0000486
487#if _LIBCPP_STD_VER > 11
488 template <typename _K2>
489 _LIBCPP_INLINE_VISIBILITY
490 typename enable_if<__is_transparent<_Compare, _K2>::value, bool>::type
491 operator () ( const _K2& __x, const _CP& __y ) const
Erik Pilkingtond3fe2992018-06-04 20:38:23 +0000492 {return static_cast<const _Compare&>(*this) (__x, __y.__get_value().first);}
Marshall Clowebb57322013-08-13 22:18:47 +0000493
494 template <typename _K2>
495 _LIBCPP_INLINE_VISIBILITY
496 typename enable_if<__is_transparent<_Compare, _K2>::value, bool>::type
497 operator () (const _CP& __x, const _K2& __y) const
Erik Pilkingtond3fe2992018-06-04 20:38:23 +0000498 {return static_cast<const _Compare&>(*this) (__x.__get_value().first, __y);}
Marshall Clowebb57322013-08-13 22:18:47 +0000499#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000500};
501
Howard Hinnant90b91592013-07-05 18:06:00 +0000502template <class _Key, class _CP, class _Compare>
503class __map_value_compare<_Key, _CP, _Compare, false>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000504{
505 _Compare comp;
506
Howard Hinnantc51e1022010-05-11 19:42:16 +0000507public:
Howard Hinnant756c69b2010-09-22 16:48:34 +0000508 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000509 __map_value_compare()
510 _NOEXCEPT_(is_nothrow_default_constructible<_Compare>::value)
511 : comp() {}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000512 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000513 __map_value_compare(_Compare c)
514 _NOEXCEPT_(is_nothrow_copy_constructible<_Compare>::value)
515 : comp(c) {}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000516 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000517 const _Compare& key_comp() const _NOEXCEPT {return comp;}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000518
Howard Hinnant756c69b2010-09-22 16:48:34 +0000519 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000520 bool operator()(const _CP& __x, const _CP& __y) const
Erik Pilkingtond3fe2992018-06-04 20:38:23 +0000521 {return comp(__x.__get_value().first, __y.__get_value().first);}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000522 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000523 bool operator()(const _CP& __x, const _Key& __y) const
Erik Pilkingtond3fe2992018-06-04 20:38:23 +0000524 {return comp(__x.__get_value().first, __y);}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000525 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000526 bool operator()(const _Key& __x, const _CP& __y) const
Erik Pilkingtond3fe2992018-06-04 20:38:23 +0000527 {return comp(__x, __y.__get_value().first);}
Marshall Clow8982dcd2015-07-13 20:04:56 +0000528 void swap(__map_value_compare&__y)
529 _NOEXCEPT_(__is_nothrow_swappable<_Compare>::value)
530 {
531 using _VSTD::swap;
532 swap(comp, __y.comp);
533 }
Eric Fiseliercf8c0212017-01-05 06:06:18 +0000534
Marshall Clowebb57322013-08-13 22:18:47 +0000535#if _LIBCPP_STD_VER > 11
536 template <typename _K2>
537 _LIBCPP_INLINE_VISIBILITY
538 typename enable_if<__is_transparent<_Compare, _K2>::value, bool>::type
539 operator () ( const _K2& __x, const _CP& __y ) const
Erik Pilkingtond3fe2992018-06-04 20:38:23 +0000540 {return comp (__x, __y.__get_value().first);}
Marshall Clowebb57322013-08-13 22:18:47 +0000541
542 template <typename _K2>
543 _LIBCPP_INLINE_VISIBILITY
544 typename enable_if<__is_transparent<_Compare, _K2>::value, bool>::type
545 operator () (const _CP& __x, const _K2& __y) const
Erik Pilkingtond3fe2992018-06-04 20:38:23 +0000546 {return comp (__x.__get_value().first, __y);}
Marshall Clowebb57322013-08-13 22:18:47 +0000547#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000548};
549
Marshall Clow8982dcd2015-07-13 20:04:56 +0000550template <class _Key, class _CP, class _Compare, bool __b>
551inline _LIBCPP_INLINE_VISIBILITY
552void
553swap(__map_value_compare<_Key, _CP, _Compare, __b>& __x,
554 __map_value_compare<_Key, _CP, _Compare, __b>& __y)
555 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
556{
557 __x.swap(__y);
558}
559
Howard Hinnantc51e1022010-05-11 19:42:16 +0000560template <class _Allocator>
561class __map_node_destructor
562{
563 typedef _Allocator allocator_type;
564 typedef allocator_traits<allocator_type> __alloc_traits;
Eric Fiseliera00b4842016-02-20 05:28:30 +0000565
Howard Hinnantc51e1022010-05-11 19:42:16 +0000566public:
567 typedef typename __alloc_traits::pointer pointer;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000568
Eric Fiseliera00b4842016-02-20 05:28:30 +0000569private:
Howard Hinnantc51e1022010-05-11 19:42:16 +0000570 allocator_type& __na_;
571
572 __map_node_destructor& operator=(const __map_node_destructor&);
573
574public:
575 bool __first_constructed;
576 bool __second_constructed;
577
Howard Hinnant756c69b2010-09-22 16:48:34 +0000578 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000579 explicit __map_node_destructor(allocator_type& __na) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +0000580 : __na_(__na),
581 __first_constructed(false),
582 __second_constructed(false)
583 {}
584
Eric Fiseliera85b1282017-04-18 21:08:06 +0000585#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant756c69b2010-09-22 16:48:34 +0000586 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000587 __map_node_destructor(__tree_node_destructor<allocator_type>&& __x) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +0000588 : __na_(__x.__na_),
589 __first_constructed(__x.__value_constructed),
590 __second_constructed(__x.__value_constructed)
591 {
592 __x.__value_constructed = false;
593 }
Eric Fiseliera85b1282017-04-18 21:08:06 +0000594#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000595
Howard Hinnant756c69b2010-09-22 16:48:34 +0000596 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000597 void operator()(pointer __p) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +0000598 {
599 if (__second_constructed)
Erik Pilkingtond3fe2992018-06-04 20:38:23 +0000600 __alloc_traits::destroy(__na_, _VSTD::addressof(__p->__value_.__get_value().second));
Howard Hinnantc51e1022010-05-11 19:42:16 +0000601 if (__first_constructed)
Erik Pilkingtond3fe2992018-06-04 20:38:23 +0000602 __alloc_traits::destroy(__na_, _VSTD::addressof(__p->__value_.__get_value().first));
Howard Hinnantc51e1022010-05-11 19:42:16 +0000603 if (__p)
604 __alloc_traits::deallocate(__na_, __p, 1);
605 }
606};
607
Howard Hinnant944510a2011-06-14 19:58:17 +0000608template <class _Key, class _Tp, class _Compare, class _Allocator>
609 class map;
610template <class _Key, class _Tp, class _Compare, class _Allocator>
611 class multimap;
612template <class _TreeIterator> class __map_const_iterator;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000613
Eric Fiseliera00b4842016-02-20 05:28:30 +0000614#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant89f8b792013-09-30 19:08:22 +0000615
616template <class _Key, class _Tp>
Erik Pilkingtond3fe2992018-06-04 20:38:23 +0000617struct __value_type
Howard Hinnant89f8b792013-09-30 19:08:22 +0000618{
619 typedef _Key key_type;
620 typedef _Tp mapped_type;
621 typedef pair<const key_type, mapped_type> value_type;
Erik Pilkingtond3fe2992018-06-04 20:38:23 +0000622 typedef pair<key_type&, mapped_type&> __nc_ref_pair_type;
623 typedef pair<key_type&&, mapped_type&&> __nc_rref_pair_type;
Howard Hinnant89f8b792013-09-30 19:08:22 +0000624
Erik Pilkingtond3fe2992018-06-04 20:38:23 +0000625private:
Howard Hinnant89f8b792013-09-30 19:08:22 +0000626 value_type __cc;
Erik Pilkingtond3fe2992018-06-04 20:38:23 +0000627
628public:
629 _LIBCPP_INLINE_VISIBILITY
630 value_type& __get_value()
631 {
632#if _LIBCPP_STD_VER > 14
633 return *_VSTD::launder(_VSTD::addressof(__cc));
634#else
635 return __cc;
636#endif
637 }
638
639 _LIBCPP_INLINE_VISIBILITY
640 const value_type& __get_value() const
641 {
642#if _LIBCPP_STD_VER > 14
643 return *_VSTD::launder(_VSTD::addressof(__cc));
644#else
645 return __cc;
646#endif
647 }
648
649 _LIBCPP_INLINE_VISIBILITY
650 __nc_ref_pair_type __ref()
651 {
652 value_type& __v = __get_value();
653 return __nc_ref_pair_type(const_cast<key_type&>(__v.first), __v.second);
654 }
655
656 _LIBCPP_INLINE_VISIBILITY
657 __nc_rref_pair_type __move()
658 {
659 value_type& __v = __get_value();
660 return __nc_rref_pair_type(
661 _VSTD::move(const_cast<key_type&>(__v.first)),
662 _VSTD::move(__v.second));
663 }
Howard Hinnant89f8b792013-09-30 19:08:22 +0000664
Howard Hinnant89f8b792013-09-30 19:08:22 +0000665 _LIBCPP_INLINE_VISIBILITY
666 __value_type& operator=(const __value_type& __v)
Erik Pilkingtond3fe2992018-06-04 20:38:23 +0000667 {
668 __ref() = __v.__get_value();
669 return *this;
670 }
Howard Hinnant89f8b792013-09-30 19:08:22 +0000671
672 _LIBCPP_INLINE_VISIBILITY
673 __value_type& operator=(__value_type&& __v)
Erik Pilkingtond3fe2992018-06-04 20:38:23 +0000674 {
675 __ref() = __v.__move();
676 return *this;
677 }
Howard Hinnant89f8b792013-09-30 19:08:22 +0000678
Eric Fiselierd06276b2016-03-31 02:15:15 +0000679 template <class _ValueTp,
680 class = typename enable_if<
681 __is_same_uncvref<_ValueTp, value_type>::value
682 >::type
683 >
Howard Hinnant89f8b792013-09-30 19:08:22 +0000684 _LIBCPP_INLINE_VISIBILITY
Erik Pilkingtond3fe2992018-06-04 20:38:23 +0000685 __value_type& operator=(_ValueTp&& __v)
686 {
687 __ref() = _VSTD::forward<_ValueTp>(__v);
688 return *this;
Eric Fiselierd06276b2016-03-31 02:15:15 +0000689 }
690
691private:
692 __value_type() _LIBCPP_EQUAL_DELETE;
693 ~__value_type() _LIBCPP_EQUAL_DELETE;
694 __value_type(const __value_type& __v) _LIBCPP_EQUAL_DELETE;
695 __value_type(__value_type&& __v) _LIBCPP_EQUAL_DELETE;
Howard Hinnant89f8b792013-09-30 19:08:22 +0000696};
697
698#else
699
700template <class _Key, class _Tp>
701struct __value_type
702{
703 typedef _Key key_type;
704 typedef _Tp mapped_type;
705 typedef pair<const key_type, mapped_type> value_type;
706
Erik Pilkingtond3fe2992018-06-04 20:38:23 +0000707private:
Howard Hinnant89f8b792013-09-30 19:08:22 +0000708 value_type __cc;
709
Erik Pilkingtond3fe2992018-06-04 20:38:23 +0000710public:
711 _LIBCPP_INLINE_VISIBILITY
712 value_type& __get_value() { return __cc; }
713 _LIBCPP_INLINE_VISIBILITY
714 const value_type& __get_value() const { return __cc; }
715
Eric Fiselierd06276b2016-03-31 02:15:15 +0000716private:
717 __value_type();
718 __value_type(__value_type const&);
719 __value_type& operator=(__value_type const&);
720 ~__value_type();
Howard Hinnant89f8b792013-09-30 19:08:22 +0000721};
722
Eric Fiseliera85b1282017-04-18 21:08:06 +0000723#endif // _LIBCPP_CXX03_LANG
Howard Hinnant89f8b792013-09-30 19:08:22 +0000724
Eric Fiselier44f9fd02015-03-03 20:10:01 +0000725template <class _Tp>
726struct __extract_key_value_types;
727
728template <class _Key, class _Tp>
729struct __extract_key_value_types<__value_type<_Key, _Tp> >
730{
731 typedef _Key const __key_type;
732 typedef _Tp __mapped_type;
733};
734
Howard Hinnantc51e1022010-05-11 19:42:16 +0000735template <class _TreeIterator>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000736class _LIBCPP_TEMPLATE_VIS __map_iterator
Howard Hinnantc51e1022010-05-11 19:42:16 +0000737{
Eric Fiseliera00b4842016-02-20 05:28:30 +0000738 typedef typename _TreeIterator::_NodeTypes _NodeTypes;
739 typedef typename _TreeIterator::__pointer_traits __pointer_traits;
740
Howard Hinnantc51e1022010-05-11 19:42:16 +0000741 _TreeIterator __i_;
742
Howard Hinnantc51e1022010-05-11 19:42:16 +0000743public:
744 typedef bidirectional_iterator_tag iterator_category;
Eric Fiseliera00b4842016-02-20 05:28:30 +0000745 typedef typename _NodeTypes::__map_value_type value_type;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000746 typedef typename _TreeIterator::difference_type difference_type;
747 typedef value_type& reference;
Eric Fiseliera00b4842016-02-20 05:28:30 +0000748 typedef typename _NodeTypes::__map_value_type_pointer pointer;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000749
Howard Hinnant756c69b2010-09-22 16:48:34 +0000750 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000751 __map_iterator() _NOEXCEPT {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000752
Howard Hinnant756c69b2010-09-22 16:48:34 +0000753 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000754 __map_iterator(_TreeIterator __i) _NOEXCEPT : __i_(__i) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000755
Howard Hinnant756c69b2010-09-22 16:48:34 +0000756 _LIBCPP_INLINE_VISIBILITY
Erik Pilkingtond3fe2992018-06-04 20:38:23 +0000757 reference operator*() const {return __i_->__get_value();}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000758 _LIBCPP_INLINE_VISIBILITY
Erik Pilkingtond3fe2992018-06-04 20:38:23 +0000759 pointer operator->() const {return pointer_traits<pointer>::pointer_to(__i_->__get_value());}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000760
Howard Hinnant756c69b2010-09-22 16:48:34 +0000761 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000762 __map_iterator& operator++() {++__i_; return *this;}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000763 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000764 __map_iterator operator++(int)
765 {
766 __map_iterator __t(*this);
767 ++(*this);
768 return __t;
769 }
770
Howard Hinnant756c69b2010-09-22 16:48:34 +0000771 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000772 __map_iterator& operator--() {--__i_; return *this;}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000773 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000774 __map_iterator operator--(int)
775 {
776 __map_iterator __t(*this);
777 --(*this);
778 return __t;
779 }
780
Howard Hinnant756c69b2010-09-22 16:48:34 +0000781 friend _LIBCPP_INLINE_VISIBILITY
782 bool operator==(const __map_iterator& __x, const __map_iterator& __y)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000783 {return __x.__i_ == __y.__i_;}
Eric Fiseliercf8c0212017-01-05 06:06:18 +0000784 friend
Howard Hinnant756c69b2010-09-22 16:48:34 +0000785 _LIBCPP_INLINE_VISIBILITY
786 bool operator!=(const __map_iterator& __x, const __map_iterator& __y)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000787 {return __x.__i_ != __y.__i_;}
788
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000789 template <class, class, class, class> friend class _LIBCPP_TEMPLATE_VIS map;
790 template <class, class, class, class> friend class _LIBCPP_TEMPLATE_VIS multimap;
791 template <class> friend class _LIBCPP_TEMPLATE_VIS __map_const_iterator;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000792};
793
794template <class _TreeIterator>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000795class _LIBCPP_TEMPLATE_VIS __map_const_iterator
Howard Hinnantc51e1022010-05-11 19:42:16 +0000796{
Eric Fiseliera00b4842016-02-20 05:28:30 +0000797 typedef typename _TreeIterator::_NodeTypes _NodeTypes;
798 typedef typename _TreeIterator::__pointer_traits __pointer_traits;
799
Howard Hinnantc51e1022010-05-11 19:42:16 +0000800 _TreeIterator __i_;
801
Howard Hinnantc51e1022010-05-11 19:42:16 +0000802public:
803 typedef bidirectional_iterator_tag iterator_category;
Eric Fiseliera00b4842016-02-20 05:28:30 +0000804 typedef typename _NodeTypes::__map_value_type value_type;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000805 typedef typename _TreeIterator::difference_type difference_type;
806 typedef const value_type& reference;
Eric Fiseliera00b4842016-02-20 05:28:30 +0000807 typedef typename _NodeTypes::__const_map_value_type_pointer pointer;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000808
Howard Hinnant756c69b2010-09-22 16:48:34 +0000809 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000810 __map_const_iterator() _NOEXCEPT {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000811
Howard Hinnant756c69b2010-09-22 16:48:34 +0000812 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000813 __map_const_iterator(_TreeIterator __i) _NOEXCEPT : __i_(__i) {}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000814 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier44f9fd02015-03-03 20:10:01 +0000815 __map_const_iterator(__map_iterator<
816 typename _TreeIterator::__non_const_iterator> __i) _NOEXCEPT
817 : __i_(__i.__i_) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000818
Howard Hinnant756c69b2010-09-22 16:48:34 +0000819 _LIBCPP_INLINE_VISIBILITY
Erik Pilkingtond3fe2992018-06-04 20:38:23 +0000820 reference operator*() const {return __i_->__get_value();}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000821 _LIBCPP_INLINE_VISIBILITY
Erik Pilkingtond3fe2992018-06-04 20:38:23 +0000822 pointer operator->() const {return pointer_traits<pointer>::pointer_to(__i_->__get_value());}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000823
Howard Hinnant756c69b2010-09-22 16:48:34 +0000824 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000825 __map_const_iterator& operator++() {++__i_; return *this;}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000826 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000827 __map_const_iterator operator++(int)
828 {
829 __map_const_iterator __t(*this);
830 ++(*this);
831 return __t;
832 }
833
Howard Hinnant756c69b2010-09-22 16:48:34 +0000834 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000835 __map_const_iterator& operator--() {--__i_; return *this;}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000836 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000837 __map_const_iterator operator--(int)
838 {
839 __map_const_iterator __t(*this);
840 --(*this);
841 return __t;
842 }
843
Howard Hinnant756c69b2010-09-22 16:48:34 +0000844 friend _LIBCPP_INLINE_VISIBILITY
845 bool operator==(const __map_const_iterator& __x, const __map_const_iterator& __y)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000846 {return __x.__i_ == __y.__i_;}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000847 friend _LIBCPP_INLINE_VISIBILITY
848 bool operator!=(const __map_const_iterator& __x, const __map_const_iterator& __y)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000849 {return __x.__i_ != __y.__i_;}
850
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000851 template <class, class, class, class> friend class _LIBCPP_TEMPLATE_VIS map;
852 template <class, class, class, class> friend class _LIBCPP_TEMPLATE_VIS multimap;
853 template <class, class, class> friend class _LIBCPP_TEMPLATE_VIS __tree_const_iterator;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000854};
855
856template <class _Key, class _Tp, class _Compare = less<_Key>,
857 class _Allocator = allocator<pair<const _Key, _Tp> > >
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000858class _LIBCPP_TEMPLATE_VIS map
Howard Hinnantc51e1022010-05-11 19:42:16 +0000859{
860public:
861 // types:
862 typedef _Key key_type;
863 typedef _Tp mapped_type;
864 typedef pair<const key_type, mapped_type> value_type;
865 typedef _Compare key_compare;
866 typedef _Allocator allocator_type;
867 typedef value_type& reference;
868 typedef const value_type& const_reference;
869
Marshall Clow5128cf32015-11-26 01:24:04 +0000870 static_assert((is_same<typename allocator_type::value_type, value_type>::value),
871 "Allocator::value_type must be same type as value_type");
872
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000873 class _LIBCPP_TEMPLATE_VIS value_compare
Howard Hinnantc51e1022010-05-11 19:42:16 +0000874 : public binary_function<value_type, value_type, bool>
875 {
876 friend class map;
877 protected:
878 key_compare comp;
879
Howard Hinnant756c69b2010-09-22 16:48:34 +0000880 _LIBCPP_INLINE_VISIBILITY value_compare(key_compare c) : comp(c) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000881 public:
Howard Hinnant756c69b2010-09-22 16:48:34 +0000882 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000883 bool operator()(const value_type& __x, const value_type& __y) const
884 {return comp(__x.first, __y.first);}
885 };
886
887private:
Howard Hinnant2d0046b2013-06-19 21:29:40 +0000888
Howard Hinnant89f8b792013-09-30 19:08:22 +0000889 typedef _VSTD::__value_type<key_type, mapped_type> __value_type;
Howard Hinnant90b91592013-07-05 18:06:00 +0000890 typedef __map_value_compare<key_type, __value_type, key_compare> __vc;
Marshall Clow940e01c2015-04-07 05:21:38 +0000891 typedef typename __rebind_alloc_helper<allocator_traits<allocator_type>,
892 __value_type>::type __allocator_type;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000893 typedef __tree<__value_type, __vc, __allocator_type> __base;
894 typedef typename __base::__node_traits __node_traits;
895 typedef allocator_traits<allocator_type> __alloc_traits;
896
897 __base __tree_;
898
899public:
900 typedef typename __alloc_traits::pointer pointer;
901 typedef typename __alloc_traits::const_pointer const_pointer;
902 typedef typename __alloc_traits::size_type size_type;
903 typedef typename __alloc_traits::difference_type difference_type;
Eric Fiselier44f9fd02015-03-03 20:10:01 +0000904 typedef __map_iterator<typename __base::iterator> iterator;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000905 typedef __map_const_iterator<typename __base::const_iterator> const_iterator;
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000906 typedef _VSTD::reverse_iterator<iterator> reverse_iterator;
907 typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000908
Howard Hinnant756c69b2010-09-22 16:48:34 +0000909 _LIBCPP_INLINE_VISIBILITY
Marshall Clow7086a5a2014-03-10 04:50:10 +0000910 map()
911 _NOEXCEPT_(
912 is_nothrow_default_constructible<allocator_type>::value &&
913 is_nothrow_default_constructible<key_compare>::value &&
914 is_nothrow_copy_constructible<key_compare>::value)
915 : __tree_(__vc(key_compare())) {}
916
917 _LIBCPP_INLINE_VISIBILITY
918 explicit map(const key_compare& __comp)
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000919 _NOEXCEPT_(
920 is_nothrow_default_constructible<allocator_type>::value &&
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000921 is_nothrow_copy_constructible<key_compare>::value)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000922 : __tree_(__vc(__comp)) {}
923
Howard Hinnant756c69b2010-09-22 16:48:34 +0000924 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000925 explicit map(const key_compare& __comp, const allocator_type& __a)
Marshall Clow657cbc42016-08-17 05:58:40 +0000926 : __tree_(__vc(__comp), typename __base::allocator_type(__a)) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000927
928 template <class _InputIterator>
Howard Hinnant756c69b2010-09-22 16:48:34 +0000929 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000930 map(_InputIterator __f, _InputIterator __l,
931 const key_compare& __comp = key_compare())
932 : __tree_(__vc(__comp))
933 {
934 insert(__f, __l);
935 }
936
937 template <class _InputIterator>
Howard Hinnant756c69b2010-09-22 16:48:34 +0000938 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000939 map(_InputIterator __f, _InputIterator __l,
940 const key_compare& __comp, const allocator_type& __a)
Marshall Clow657cbc42016-08-17 05:58:40 +0000941 : __tree_(__vc(__comp), typename __base::allocator_type(__a))
Howard Hinnantc51e1022010-05-11 19:42:16 +0000942 {
943 insert(__f, __l);
944 }
945
Marshall Clow300abfb2013-09-11 01:15:47 +0000946#if _LIBCPP_STD_VER > 11
947 template <class _InputIterator>
Eric Fiseliercf8c0212017-01-05 06:06:18 +0000948 _LIBCPP_INLINE_VISIBILITY
Marshall Clow300abfb2013-09-11 01:15:47 +0000949 map(_InputIterator __f, _InputIterator __l, const allocator_type& __a)
950 : map(__f, __l, key_compare(), __a) {}
951#endif
952
Howard Hinnant756c69b2010-09-22 16:48:34 +0000953 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000954 map(const map& __m)
955 : __tree_(__m.__tree_)
956 {
957 insert(__m.begin(), __m.end());
958 }
959
Howard Hinnantd3a657f2011-07-01 19:24:36 +0000960 _LIBCPP_INLINE_VISIBILITY
961 map& operator=(const map& __m)
962 {
Marshall Clow476d3f42016-07-18 13:19:00 +0000963#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantd3a657f2011-07-01 19:24:36 +0000964 __tree_ = __m.__tree_;
Howard Hinnant2d0046b2013-06-19 21:29:40 +0000965#else
Marshall Clowdb3cfcb2014-02-08 04:03:14 +0000966 if (this != &__m) {
967 __tree_.clear();
968 __tree_.value_comp() = __m.__tree_.value_comp();
969 __tree_.__copy_assign_alloc(__m.__tree_);
970 insert(__m.begin(), __m.end());
971 }
Howard Hinnant2d0046b2013-06-19 21:29:40 +0000972#endif
Howard Hinnantd3a657f2011-07-01 19:24:36 +0000973 return *this;
974 }
975
Eric Fiseliera85b1282017-04-18 21:08:06 +0000976#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000977
Howard Hinnant756c69b2010-09-22 16:48:34 +0000978 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000979 map(map&& __m)
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000980 _NOEXCEPT_(is_nothrow_move_constructible<__base>::value)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000981 : __tree_(_VSTD::move(__m.__tree_))
Howard Hinnantc51e1022010-05-11 19:42:16 +0000982 {
983 }
984
985 map(map&& __m, const allocator_type& __a);
986
Howard Hinnant756c69b2010-09-22 16:48:34 +0000987 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant33711792011-08-12 21:56:02 +0000988 map& operator=(map&& __m)
989 _NOEXCEPT_(is_nothrow_move_assignable<__base>::value)
990 {
991 __tree_ = _VSTD::move(__m.__tree_);
992 return *this;
993 }
994
Howard Hinnant33711792011-08-12 21:56:02 +0000995 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000996 map(initializer_list<value_type> __il, const key_compare& __comp = key_compare())
997 : __tree_(__vc(__comp))
998 {
999 insert(__il.begin(), __il.end());
1000 }
1001
Howard Hinnant756c69b2010-09-22 16:48:34 +00001002 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001003 map(initializer_list<value_type> __il, const key_compare& __comp, const allocator_type& __a)
Marshall Clow657cbc42016-08-17 05:58:40 +00001004 : __tree_(__vc(__comp), typename __base::allocator_type(__a))
Howard Hinnantc51e1022010-05-11 19:42:16 +00001005 {
1006 insert(__il.begin(), __il.end());
1007 }
1008
Marshall Clow300abfb2013-09-11 01:15:47 +00001009#if _LIBCPP_STD_VER > 11
Eric Fiseliercf8c0212017-01-05 06:06:18 +00001010 _LIBCPP_INLINE_VISIBILITY
Marshall Clow300abfb2013-09-11 01:15:47 +00001011 map(initializer_list<value_type> __il, const allocator_type& __a)
1012 : map(__il, key_compare(), __a) {}
1013#endif
1014
Howard Hinnant756c69b2010-09-22 16:48:34 +00001015 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001016 map& operator=(initializer_list<value_type> __il)
1017 {
1018 __tree_.__assign_unique(__il.begin(), __il.end());
1019 return *this;
1020 }
1021
Eric Fiseliera85b1282017-04-18 21:08:06 +00001022#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001023
Howard Hinnant756c69b2010-09-22 16:48:34 +00001024 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001025 explicit map(const allocator_type& __a)
Marshall Clow657cbc42016-08-17 05:58:40 +00001026 : __tree_(typename __base::allocator_type(__a))
Howard Hinnantc51e1022010-05-11 19:42:16 +00001027 {
1028 }
1029
Howard Hinnant756c69b2010-09-22 16:48:34 +00001030 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001031 map(const map& __m, const allocator_type& __a)
Marshall Clow657cbc42016-08-17 05:58:40 +00001032 : __tree_(__m.__tree_.value_comp(), typename __base::allocator_type(__a))
Howard Hinnantc51e1022010-05-11 19:42:16 +00001033 {
1034 insert(__m.begin(), __m.end());
1035 }
1036
Howard Hinnant756c69b2010-09-22 16:48:34 +00001037 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001038 iterator begin() _NOEXCEPT {return __tree_.begin();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001039 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001040 const_iterator begin() const _NOEXCEPT {return __tree_.begin();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001041 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001042 iterator end() _NOEXCEPT {return __tree_.end();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001043 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001044 const_iterator end() const _NOEXCEPT {return __tree_.end();}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001045
Howard Hinnant756c69b2010-09-22 16:48:34 +00001046 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001047 reverse_iterator rbegin() _NOEXCEPT {return reverse_iterator(end());}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001048 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001049 const_reverse_iterator rbegin() const _NOEXCEPT
1050 {return const_reverse_iterator(end());}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001051 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001052 reverse_iterator rend() _NOEXCEPT
1053 {return reverse_iterator(begin());}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001054 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001055 const_reverse_iterator rend() const _NOEXCEPT
1056 {return const_reverse_iterator(begin());}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001057
Howard Hinnant756c69b2010-09-22 16:48:34 +00001058 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001059 const_iterator cbegin() const _NOEXCEPT {return begin();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001060 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001061 const_iterator cend() const _NOEXCEPT {return end();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001062 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001063 const_reverse_iterator crbegin() const _NOEXCEPT {return rbegin();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001064 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001065 const_reverse_iterator crend() const _NOEXCEPT {return rend();}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001066
Marshall Clow425f5752017-11-15 05:51:26 +00001067 _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001068 bool empty() const _NOEXCEPT {return __tree_.size() == 0;}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001069 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001070 size_type size() const _NOEXCEPT {return __tree_.size();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001071 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001072 size_type max_size() const _NOEXCEPT {return __tree_.max_size();}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001073
1074 mapped_type& operator[](const key_type& __k);
Eric Fiselierd63f38e2016-03-31 03:13:37 +00001075#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001076 mapped_type& operator[](key_type&& __k);
1077#endif
1078
1079 mapped_type& at(const key_type& __k);
1080 const mapped_type& at(const key_type& __k) const;
1081
Howard Hinnant756c69b2010-09-22 16:48:34 +00001082 _LIBCPP_INLINE_VISIBILITY
Marshall Clow657cbc42016-08-17 05:58:40 +00001083 allocator_type get_allocator() const _NOEXCEPT {return allocator_type(__tree_.__alloc());}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001084 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001085 key_compare key_comp() const {return __tree_.value_comp().key_comp();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001086 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001087 value_compare value_comp() const {return value_compare(__tree_.value_comp().key_comp());}
1088
Eric Fiselierd06276b2016-03-31 02:15:15 +00001089#ifndef _LIBCPP_CXX03_LANG
1090 template <class ..._Args>
1091 _LIBCPP_INLINE_VISIBILITY
1092 pair<iterator, bool> emplace(_Args&& ...__args) {
1093 return __tree_.__emplace_unique(_VSTD::forward<_Args>(__args)...);
1094 }
Howard Hinnant74279a52010-09-04 23:28:19 +00001095
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001096 template <class ..._Args>
Eric Fiselierd06276b2016-03-31 02:15:15 +00001097 _LIBCPP_INLINE_VISIBILITY
1098 iterator emplace_hint(const_iterator __p, _Args&& ...__args) {
1099 return __tree_.__emplace_hint_unique(__p.__i_, _VSTD::forward<_Args>(__args)...);
1100 }
Howard Hinnant74279a52010-09-04 23:28:19 +00001101
Howard Hinnantc834c512011-11-29 18:15:50 +00001102 template <class _Pp,
1103 class = typename enable_if<is_constructible<value_type, _Pp>::value>::type>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001104 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc834c512011-11-29 18:15:50 +00001105 pair<iterator, bool> insert(_Pp&& __p)
1106 {return __tree_.__insert_unique(_VSTD::forward<_Pp>(__p));}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001107
Howard Hinnantc834c512011-11-29 18:15:50 +00001108 template <class _Pp,
1109 class = typename enable_if<is_constructible<value_type, _Pp>::value>::type>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001110 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc834c512011-11-29 18:15:50 +00001111 iterator insert(const_iterator __pos, _Pp&& __p)
1112 {return __tree_.__insert_unique(__pos.__i_, _VSTD::forward<_Pp>(__p));}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001113
Eric Fiselierd06276b2016-03-31 02:15:15 +00001114#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001115
Howard Hinnant756c69b2010-09-22 16:48:34 +00001116 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001117 pair<iterator, bool>
1118 insert(const value_type& __v) {return __tree_.__insert_unique(__v);}
1119
Howard Hinnant756c69b2010-09-22 16:48:34 +00001120 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001121 iterator
1122 insert(const_iterator __p, const value_type& __v)
1123 {return __tree_.__insert_unique(__p.__i_, __v);}
1124
Eric Fiselierd6143132016-04-18 01:40:45 +00001125#ifndef _LIBCPP_CXX03_LANG
Marshall Clowd430d022016-01-05 19:32:41 +00001126 _LIBCPP_INLINE_VISIBILITY
1127 pair<iterator, bool>
Eric Fiselierd06276b2016-03-31 02:15:15 +00001128 insert(value_type&& __v) {return __tree_.__insert_unique(_VSTD::move(__v));}
Marshall Clowd430d022016-01-05 19:32:41 +00001129
1130 _LIBCPP_INLINE_VISIBILITY
Eric Fiselierd06276b2016-03-31 02:15:15 +00001131 iterator insert(const_iterator __p, value_type&& __v)
1132 {return __tree_.__insert_unique(__p.__i_, _VSTD::move(__v));}
Eric Fiseliera85b1282017-04-18 21:08:06 +00001133
1134 _LIBCPP_INLINE_VISIBILITY
1135 void insert(initializer_list<value_type> __il)
1136 {insert(__il.begin(), __il.end());}
Marshall Clowd430d022016-01-05 19:32:41 +00001137#endif
1138
Howard Hinnantc51e1022010-05-11 19:42:16 +00001139 template <class _InputIterator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001140 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001141 void insert(_InputIterator __f, _InputIterator __l)
1142 {
1143 for (const_iterator __e = cend(); __f != __l; ++__f)
1144 insert(__e.__i_, *__f);
1145 }
1146
Marshall Clow3223db82015-07-07 03:37:33 +00001147#if _LIBCPP_STD_VER > 14
Eric Fiselierd63f38e2016-03-31 03:13:37 +00001148
Marshall Clow3223db82015-07-07 03:37:33 +00001149 template <class... _Args>
1150 _LIBCPP_INLINE_VISIBILITY
1151 pair<iterator, bool> try_emplace(const key_type& __k, _Args&&... __args)
1152 {
Eric Fiselierd63f38e2016-03-31 03:13:37 +00001153 return __tree_.__emplace_unique_key_args(__k,
1154 _VSTD::piecewise_construct,
1155 _VSTD::forward_as_tuple(__k),
1156 _VSTD::forward_as_tuple(_VSTD::forward<_Args>(__args)...));
Marshall Clow3223db82015-07-07 03:37:33 +00001157 }
1158
1159 template <class... _Args>
1160 _LIBCPP_INLINE_VISIBILITY
1161 pair<iterator, bool> try_emplace(key_type&& __k, _Args&&... __args)
1162 {
Eric Fiselierd63f38e2016-03-31 03:13:37 +00001163 return __tree_.__emplace_unique_key_args(__k,
1164 _VSTD::piecewise_construct,
1165 _VSTD::forward_as_tuple(_VSTD::move(__k)),
1166 _VSTD::forward_as_tuple(_VSTD::forward<_Args>(__args)...));
Marshall Clow3223db82015-07-07 03:37:33 +00001167 }
1168
1169 template <class... _Args>
1170 _LIBCPP_INLINE_VISIBILITY
1171 iterator try_emplace(const_iterator __h, const key_type& __k, _Args&&... __args)
1172 {
Eric Fiselierd63f38e2016-03-31 03:13:37 +00001173 return __tree_.__emplace_hint_unique_key_args(__h.__i_, __k,
1174 _VSTD::piecewise_construct,
1175 _VSTD::forward_as_tuple(__k),
1176 _VSTD::forward_as_tuple(_VSTD::forward<_Args>(__args)...));
Marshall Clow3223db82015-07-07 03:37:33 +00001177 }
1178
1179 template <class... _Args>
1180 _LIBCPP_INLINE_VISIBILITY
1181 iterator try_emplace(const_iterator __h, key_type&& __k, _Args&&... __args)
1182 {
Eric Fiselierd63f38e2016-03-31 03:13:37 +00001183 return __tree_.__emplace_hint_unique_key_args(__h.__i_, __k,
1184 _VSTD::piecewise_construct,
1185 _VSTD::forward_as_tuple(_VSTD::move(__k)),
1186 _VSTD::forward_as_tuple(_VSTD::forward<_Args>(__args)...));
Marshall Clow3223db82015-07-07 03:37:33 +00001187 }
1188
1189 template <class _Vp>
1190 _LIBCPP_INLINE_VISIBILITY
1191 pair<iterator, bool> insert_or_assign(const key_type& __k, _Vp&& __v)
1192 {
1193 iterator __p = lower_bound(__k);
1194 if ( __p != end() && !key_comp()(__k, __p->first))
1195 {
1196 __p->second = _VSTD::forward<_Vp>(__v);
1197 return _VSTD::make_pair(__p, false);
1198 }
1199 return _VSTD::make_pair(emplace_hint(__p, __k, _VSTD::forward<_Vp>(__v)), true);
1200 }
Eric Fiselierd63f38e2016-03-31 03:13:37 +00001201
Marshall Clow3223db82015-07-07 03:37:33 +00001202 template <class _Vp>
1203 _LIBCPP_INLINE_VISIBILITY
1204 pair<iterator, bool> insert_or_assign(key_type&& __k, _Vp&& __v)
1205 {
1206 iterator __p = lower_bound(__k);
1207 if ( __p != end() && !key_comp()(__k, __p->first))
1208 {
1209 __p->second = _VSTD::forward<_Vp>(__v);
1210 return _VSTD::make_pair(__p, false);
1211 }
1212 return _VSTD::make_pair(emplace_hint(__p, _VSTD::move(__k), _VSTD::forward<_Vp>(__v)), true);
1213 }
1214
1215 template <class _Vp>
1216 _LIBCPP_INLINE_VISIBILITY
1217 iterator insert_or_assign(const_iterator __h, const key_type& __k, _Vp&& __v)
1218 {
1219 iterator __p = lower_bound(__k);
1220 if ( __p != end() && !key_comp()(__k, __p->first))
1221 {
1222 __p->second = _VSTD::forward<_Vp>(__v);
1223 return __p;
1224 }
1225 return emplace_hint(__h, __k, _VSTD::forward<_Vp>(__v));
1226 }
1227
1228 template <class _Vp>
1229 _LIBCPP_INLINE_VISIBILITY
1230 iterator insert_or_assign(const_iterator __h, key_type&& __k, _Vp&& __v)
1231 {
1232 iterator __p = lower_bound(__k);
1233 if ( __p != end() && !key_comp()(__k, __p->first))
1234 {
1235 __p->second = _VSTD::forward<_Vp>(__v);
1236 return __p;
1237 }
1238 return emplace_hint(__h, _VSTD::move(__k), _VSTD::forward<_Vp>(__v));
1239 }
Eric Fiselierd63f38e2016-03-31 03:13:37 +00001240
Eric Fiseliera85b1282017-04-18 21:08:06 +00001241#endif // _LIBCPP_STD_VER > 14
Marshall Clow3223db82015-07-07 03:37:33 +00001242
Howard Hinnant756c69b2010-09-22 16:48:34 +00001243 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001244 iterator erase(const_iterator __p) {return __tree_.erase(__p.__i_);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001245 _LIBCPP_INLINE_VISIBILITY
Marshall Clow22ea5b82015-05-10 13:35:00 +00001246 iterator erase(iterator __p) {return __tree_.erase(__p.__i_);}
1247 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001248 size_type erase(const key_type& __k)
1249 {return __tree_.__erase_unique(__k);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001250 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001251 iterator erase(const_iterator __f, const_iterator __l)
1252 {return __tree_.erase(__f.__i_, __l.__i_);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001253 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001254 void clear() _NOEXCEPT {__tree_.clear();}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001255
Howard Hinnant756c69b2010-09-22 16:48:34 +00001256 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001257 void swap(map& __m)
1258 _NOEXCEPT_(__is_nothrow_swappable<__base>::value)
1259 {__tree_.swap(__m.__tree_);}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001260
Howard Hinnant756c69b2010-09-22 16:48:34 +00001261 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001262 iterator find(const key_type& __k) {return __tree_.find(__k);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001263 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001264 const_iterator find(const key_type& __k) const {return __tree_.find(__k);}
Marshall Clowebb57322013-08-13 22:18:47 +00001265#if _LIBCPP_STD_VER > 11
1266 template <typename _K2>
1267 _LIBCPP_INLINE_VISIBILITY
1268 typename enable_if<__is_transparent<_Compare, _K2>::value,iterator>::type
1269 find(const _K2& __k) {return __tree_.find(__k);}
1270 template <typename _K2>
1271 _LIBCPP_INLINE_VISIBILITY
1272 typename enable_if<__is_transparent<_Compare, _K2>::value,const_iterator>::type
1273 find(const _K2& __k) const {return __tree_.find(__k);}
1274#endif
1275
Howard Hinnant756c69b2010-09-22 16:48:34 +00001276 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001277 size_type count(const key_type& __k) const
1278 {return __tree_.__count_unique(__k);}
Marshall Clowe6a5f522014-08-24 23:54:16 +00001279#if _LIBCPP_STD_VER > 11
1280 template <typename _K2>
1281 _LIBCPP_INLINE_VISIBILITY
1282 typename enable_if<__is_transparent<_Compare, _K2>::value,size_type>::type
Eric Fiseliera85c9e92018-02-10 02:53:47 +00001283 count(const _K2& __k) const {return __tree_.__count_multi(__k);}
Marshall Clowe6a5f522014-08-24 23:54:16 +00001284#endif
Howard Hinnant756c69b2010-09-22 16:48:34 +00001285 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001286 iterator lower_bound(const key_type& __k)
1287 {return __tree_.lower_bound(__k);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001288 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001289 const_iterator lower_bound(const key_type& __k) const
1290 {return __tree_.lower_bound(__k);}
Marshall Clowebb57322013-08-13 22:18:47 +00001291#if _LIBCPP_STD_VER > 11
1292 template <typename _K2>
1293 _LIBCPP_INLINE_VISIBILITY
1294 typename enable_if<__is_transparent<_Compare, _K2>::value,iterator>::type
1295 lower_bound(const _K2& __k) {return __tree_.lower_bound(__k);}
1296
1297 template <typename _K2>
1298 _LIBCPP_INLINE_VISIBILITY
1299 typename enable_if<__is_transparent<_Compare, _K2>::value,const_iterator>::type
1300 lower_bound(const _K2& __k) const {return __tree_.lower_bound(__k);}
1301#endif
1302
Howard Hinnant756c69b2010-09-22 16:48:34 +00001303 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001304 iterator upper_bound(const key_type& __k)
1305 {return __tree_.upper_bound(__k);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001306 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001307 const_iterator upper_bound(const key_type& __k) const
1308 {return __tree_.upper_bound(__k);}
Marshall Clowebb57322013-08-13 22:18:47 +00001309#if _LIBCPP_STD_VER > 11
1310 template <typename _K2>
1311 _LIBCPP_INLINE_VISIBILITY
1312 typename enable_if<__is_transparent<_Compare, _K2>::value,iterator>::type
1313 upper_bound(const _K2& __k) {return __tree_.upper_bound(__k);}
1314 template <typename _K2>
1315 _LIBCPP_INLINE_VISIBILITY
1316 typename enable_if<__is_transparent<_Compare, _K2>::value,const_iterator>::type
1317 upper_bound(const _K2& __k) const {return __tree_.upper_bound(__k);}
1318#endif
1319
Howard Hinnant756c69b2010-09-22 16:48:34 +00001320 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001321 pair<iterator,iterator> equal_range(const key_type& __k)
1322 {return __tree_.__equal_range_unique(__k);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001323 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001324 pair<const_iterator,const_iterator> equal_range(const key_type& __k) const
1325 {return __tree_.__equal_range_unique(__k);}
Marshall Clowebb57322013-08-13 22:18:47 +00001326#if _LIBCPP_STD_VER > 11
1327 template <typename _K2>
1328 _LIBCPP_INLINE_VISIBILITY
1329 typename enable_if<__is_transparent<_Compare, _K2>::value,pair<iterator,iterator>>::type
Eric Fiseliera85c9e92018-02-10 02:53:47 +00001330 equal_range(const _K2& __k) {return __tree_.__equal_range_multi(__k);}
Marshall Clowebb57322013-08-13 22:18:47 +00001331 template <typename _K2>
1332 _LIBCPP_INLINE_VISIBILITY
1333 typename enable_if<__is_transparent<_Compare, _K2>::value,pair<const_iterator,const_iterator>>::type
Eric Fiseliera85c9e92018-02-10 02:53:47 +00001334 equal_range(const _K2& __k) const {return __tree_.__equal_range_multi(__k);}
Marshall Clowebb57322013-08-13 22:18:47 +00001335#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001336
1337private:
1338 typedef typename __base::__node __node;
1339 typedef typename __base::__node_allocator __node_allocator;
1340 typedef typename __base::__node_pointer __node_pointer;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001341 typedef typename __base::__node_base_pointer __node_base_pointer;
Eric Fiseliercf8c0212017-01-05 06:06:18 +00001342 typedef typename __base::__parent_pointer __parent_pointer;
Eric Fiseliera92b0732016-02-20 07:12:17 +00001343
Howard Hinnantc834c512011-11-29 18:15:50 +00001344 typedef __map_node_destructor<__node_allocator> _Dp;
1345 typedef unique_ptr<__node, _Dp> __node_holder;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001346
Eric Fiselierd63f38e2016-03-31 03:13:37 +00001347#ifdef _LIBCPP_CXX03_LANG
Howard Hinnantac7e7482013-07-04 20:59:16 +00001348 __node_holder __construct_node_with_key(const key_type& __k);
Eric Fiselierd63f38e2016-03-31 03:13:37 +00001349#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001350};
1351
Eric Fiseliera92b0732016-02-20 07:12:17 +00001352
Eric Fiselierd06276b2016-03-31 02:15:15 +00001353#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001354template <class _Key, class _Tp, class _Compare, class _Allocator>
1355map<_Key, _Tp, _Compare, _Allocator>::map(map&& __m, const allocator_type& __a)
Marshall Clow657cbc42016-08-17 05:58:40 +00001356 : __tree_(_VSTD::move(__m.__tree_), typename __base::allocator_type(__a))
Howard Hinnantc51e1022010-05-11 19:42:16 +00001357{
1358 if (__a != __m.get_allocator())
1359 {
1360 const_iterator __e = cend();
1361 while (!__m.empty())
1362 __tree_.__insert_unique(__e.__i_,
Erik Pilkingtond3fe2992018-06-04 20:38:23 +00001363 __m.__tree_.remove(__m.begin().__i_)->__value_.__move());
Howard Hinnantc51e1022010-05-11 19:42:16 +00001364 }
1365}
1366
Eric Fiseliera85b1282017-04-18 21:08:06 +00001367template <class _Key, class _Tp, class _Compare, class _Allocator>
1368_Tp&
1369map<_Key, _Tp, _Compare, _Allocator>::operator[](const key_type& __k)
1370{
1371 return __tree_.__emplace_unique_key_args(__k,
1372 _VSTD::piecewise_construct,
1373 _VSTD::forward_as_tuple(__k),
Erik Pilkingtond3fe2992018-06-04 20:38:23 +00001374 _VSTD::forward_as_tuple()).first->__get_value().second;
Eric Fiseliera85b1282017-04-18 21:08:06 +00001375}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001376
Eric Fiseliera85b1282017-04-18 21:08:06 +00001377template <class _Key, class _Tp, class _Compare, class _Allocator>
1378_Tp&
1379map<_Key, _Tp, _Compare, _Allocator>::operator[](key_type&& __k)
1380{
1381 return __tree_.__emplace_unique_key_args(__k,
1382 _VSTD::piecewise_construct,
1383 _VSTD::forward_as_tuple(_VSTD::move(__k)),
Erik Pilkingtond3fe2992018-06-04 20:38:23 +00001384 _VSTD::forward_as_tuple()).first->__get_value().second;
Eric Fiseliera85b1282017-04-18 21:08:06 +00001385}
Eric Fiselierd63f38e2016-03-31 03:13:37 +00001386
Eric Fiseliera85b1282017-04-18 21:08:06 +00001387#else // _LIBCPP_CXX03_LANG
Eric Fiselierd63f38e2016-03-31 03:13:37 +00001388
Howard Hinnantc51e1022010-05-11 19:42:16 +00001389template <class _Key, class _Tp, class _Compare, class _Allocator>
1390typename map<_Key, _Tp, _Compare, _Allocator>::__node_holder
Howard Hinnantac7e7482013-07-04 20:59:16 +00001391map<_Key, _Tp, _Compare, _Allocator>::__construct_node_with_key(const key_type& __k)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001392{
1393 __node_allocator& __na = __tree_.__node_alloc();
Howard Hinnantc834c512011-11-29 18:15:50 +00001394 __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
Erik Pilkingtond3fe2992018-06-04 20:38:23 +00001395 __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__get_value().first), __k);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001396 __h.get_deleter().__first_constructed = true;
Erik Pilkingtond3fe2992018-06-04 20:38:23 +00001397 __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__get_value().second));
Howard Hinnantc51e1022010-05-11 19:42:16 +00001398 __h.get_deleter().__second_constructed = true;
Dimitry Andric830fb602015-08-19 06:43:33 +00001399 return _LIBCPP_EXPLICIT_MOVE(__h); // explicitly moved for C++03
Howard Hinnantc51e1022010-05-11 19:42:16 +00001400}
1401
Howard Hinnantc51e1022010-05-11 19:42:16 +00001402template <class _Key, class _Tp, class _Compare, class _Allocator>
1403_Tp&
1404map<_Key, _Tp, _Compare, _Allocator>::operator[](const key_type& __k)
1405{
Eric Fiseliercf8c0212017-01-05 06:06:18 +00001406 __parent_pointer __parent;
1407 __node_base_pointer& __child = __tree_.__find_equal(__parent, __k);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001408 __node_pointer __r = static_cast<__node_pointer>(__child);
1409 if (__child == nullptr)
1410 {
Howard Hinnantac7e7482013-07-04 20:59:16 +00001411 __node_holder __h = __construct_node_with_key(__k);
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001412 __tree_.__insert_node_at(__parent, __child, static_cast<__node_base_pointer>(__h.get()));
Howard Hinnantc51e1022010-05-11 19:42:16 +00001413 __r = __h.release();
1414 }
Erik Pilkingtond3fe2992018-06-04 20:38:23 +00001415 return __r->__value_.__get_value().second;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001416}
1417
Eric Fiseliera85b1282017-04-18 21:08:06 +00001418#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001419
1420template <class _Key, class _Tp, class _Compare, class _Allocator>
1421_Tp&
1422map<_Key, _Tp, _Compare, _Allocator>::at(const key_type& __k)
1423{
Eric Fiseliercf8c0212017-01-05 06:06:18 +00001424 __parent_pointer __parent;
1425 __node_base_pointer& __child = __tree_.__find_equal(__parent, __k);
Howard Hinnant72f73582010-08-11 17:04:31 +00001426#ifndef _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +00001427 if (__child == nullptr)
1428 throw out_of_range("map::at: key not found");
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001429#endif // _LIBCPP_NO_EXCEPTIONS
Erik Pilkingtond3fe2992018-06-04 20:38:23 +00001430 return static_cast<__node_pointer>(__child)->__value_.__get_value().second;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001431}
1432
1433template <class _Key, class _Tp, class _Compare, class _Allocator>
1434const _Tp&
1435map<_Key, _Tp, _Compare, _Allocator>::at(const key_type& __k) const
1436{
Eric Fiseliercf8c0212017-01-05 06:06:18 +00001437 __parent_pointer __parent;
1438 __node_base_pointer __child = __tree_.__find_equal(__parent, __k);
Howard Hinnant72f73582010-08-11 17:04:31 +00001439#ifndef _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +00001440 if (__child == nullptr)
1441 throw out_of_range("map::at: key not found");
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001442#endif // _LIBCPP_NO_EXCEPTIONS
Erik Pilkingtond3fe2992018-06-04 20:38:23 +00001443 return static_cast<__node_pointer>(__child)->__value_.__get_value().second;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001444}
1445
Howard Hinnantc51e1022010-05-11 19:42:16 +00001446
1447template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001448inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001449bool
1450operator==(const map<_Key, _Tp, _Compare, _Allocator>& __x,
1451 const map<_Key, _Tp, _Compare, _Allocator>& __y)
1452{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001453 return __x.size() == __y.size() && _VSTD::equal(__x.begin(), __x.end(), __y.begin());
Howard Hinnantc51e1022010-05-11 19:42:16 +00001454}
1455
1456template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001457inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001458bool
1459operator< (const map<_Key, _Tp, _Compare, _Allocator>& __x,
1460 const map<_Key, _Tp, _Compare, _Allocator>& __y)
1461{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001462 return _VSTD::lexicographical_compare(__x.begin(), __x.end(), __y.begin(), __y.end());
Howard Hinnantc51e1022010-05-11 19:42:16 +00001463}
1464
1465template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001466inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001467bool
1468operator!=(const map<_Key, _Tp, _Compare, _Allocator>& __x,
1469 const map<_Key, _Tp, _Compare, _Allocator>& __y)
1470{
1471 return !(__x == __y);
1472}
1473
1474template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001475inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001476bool
1477operator> (const map<_Key, _Tp, _Compare, _Allocator>& __x,
1478 const map<_Key, _Tp, _Compare, _Allocator>& __y)
1479{
1480 return __y < __x;
1481}
1482
1483template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001484inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001485bool
1486operator>=(const map<_Key, _Tp, _Compare, _Allocator>& __x,
1487 const map<_Key, _Tp, _Compare, _Allocator>& __y)
1488{
1489 return !(__x < __y);
1490}
1491
1492template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001493inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001494bool
1495operator<=(const map<_Key, _Tp, _Compare, _Allocator>& __x,
1496 const map<_Key, _Tp, _Compare, _Allocator>& __y)
1497{
1498 return !(__y < __x);
1499}
1500
1501template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001502inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001503void
1504swap(map<_Key, _Tp, _Compare, _Allocator>& __x,
1505 map<_Key, _Tp, _Compare, _Allocator>& __y)
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001506 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
Howard Hinnantc51e1022010-05-11 19:42:16 +00001507{
1508 __x.swap(__y);
1509}
1510
1511template <class _Key, class _Tp, class _Compare = less<_Key>,
1512 class _Allocator = allocator<pair<const _Key, _Tp> > >
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00001513class _LIBCPP_TEMPLATE_VIS multimap
Howard Hinnantc51e1022010-05-11 19:42:16 +00001514{
1515public:
1516 // types:
1517 typedef _Key key_type;
1518 typedef _Tp mapped_type;
1519 typedef pair<const key_type, mapped_type> value_type;
1520 typedef _Compare key_compare;
1521 typedef _Allocator allocator_type;
1522 typedef value_type& reference;
1523 typedef const value_type& const_reference;
1524
Marshall Clow5128cf32015-11-26 01:24:04 +00001525 static_assert((is_same<typename allocator_type::value_type, value_type>::value),
1526 "Allocator::value_type must be same type as value_type");
1527
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00001528 class _LIBCPP_TEMPLATE_VIS value_compare
Howard Hinnantc51e1022010-05-11 19:42:16 +00001529 : public binary_function<value_type, value_type, bool>
1530 {
1531 friend class multimap;
1532 protected:
1533 key_compare comp;
1534
Howard Hinnant756c69b2010-09-22 16:48:34 +00001535 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001536 value_compare(key_compare c) : comp(c) {}
1537 public:
Howard Hinnant756c69b2010-09-22 16:48:34 +00001538 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001539 bool operator()(const value_type& __x, const value_type& __y) const
1540 {return comp(__x.first, __y.first);}
1541 };
1542
1543private:
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001544
Howard Hinnant89f8b792013-09-30 19:08:22 +00001545 typedef _VSTD::__value_type<key_type, mapped_type> __value_type;
Howard Hinnant90b91592013-07-05 18:06:00 +00001546 typedef __map_value_compare<key_type, __value_type, key_compare> __vc;
Marshall Clow940e01c2015-04-07 05:21:38 +00001547 typedef typename __rebind_alloc_helper<allocator_traits<allocator_type>,
1548 __value_type>::type __allocator_type;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001549 typedef __tree<__value_type, __vc, __allocator_type> __base;
1550 typedef typename __base::__node_traits __node_traits;
1551 typedef allocator_traits<allocator_type> __alloc_traits;
1552
1553 __base __tree_;
1554
1555public:
1556 typedef typename __alloc_traits::pointer pointer;
1557 typedef typename __alloc_traits::const_pointer const_pointer;
1558 typedef typename __alloc_traits::size_type size_type;
1559 typedef typename __alloc_traits::difference_type difference_type;
1560 typedef __map_iterator<typename __base::iterator> iterator;
1561 typedef __map_const_iterator<typename __base::const_iterator> const_iterator;
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001562 typedef _VSTD::reverse_iterator<iterator> reverse_iterator;
1563 typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001564
Howard Hinnant756c69b2010-09-22 16:48:34 +00001565 _LIBCPP_INLINE_VISIBILITY
Marshall Clow7086a5a2014-03-10 04:50:10 +00001566 multimap()
1567 _NOEXCEPT_(
1568 is_nothrow_default_constructible<allocator_type>::value &&
1569 is_nothrow_default_constructible<key_compare>::value &&
1570 is_nothrow_copy_constructible<key_compare>::value)
1571 : __tree_(__vc(key_compare())) {}
1572
1573 _LIBCPP_INLINE_VISIBILITY
1574 explicit multimap(const key_compare& __comp)
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001575 _NOEXCEPT_(
1576 is_nothrow_default_constructible<allocator_type>::value &&
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001577 is_nothrow_copy_constructible<key_compare>::value)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001578 : __tree_(__vc(__comp)) {}
1579
Howard Hinnant756c69b2010-09-22 16:48:34 +00001580 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001581 explicit multimap(const key_compare& __comp, const allocator_type& __a)
Marshall Clow657cbc42016-08-17 05:58:40 +00001582 : __tree_(__vc(__comp), typename __base::allocator_type(__a)) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001583
1584 template <class _InputIterator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001585 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001586 multimap(_InputIterator __f, _InputIterator __l,
1587 const key_compare& __comp = key_compare())
1588 : __tree_(__vc(__comp))
1589 {
1590 insert(__f, __l);
1591 }
1592
1593 template <class _InputIterator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001594 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001595 multimap(_InputIterator __f, _InputIterator __l,
1596 const key_compare& __comp, const allocator_type& __a)
Marshall Clow657cbc42016-08-17 05:58:40 +00001597 : __tree_(__vc(__comp), typename __base::allocator_type(__a))
Howard Hinnantc51e1022010-05-11 19:42:16 +00001598 {
1599 insert(__f, __l);
1600 }
1601
Marshall Clow300abfb2013-09-11 01:15:47 +00001602#if _LIBCPP_STD_VER > 11
1603 template <class _InputIterator>
Eric Fiseliercf8c0212017-01-05 06:06:18 +00001604 _LIBCPP_INLINE_VISIBILITY
Marshall Clow300abfb2013-09-11 01:15:47 +00001605 multimap(_InputIterator __f, _InputIterator __l, const allocator_type& __a)
1606 : multimap(__f, __l, key_compare(), __a) {}
1607#endif
1608
Howard Hinnant756c69b2010-09-22 16:48:34 +00001609 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001610 multimap(const multimap& __m)
1611 : __tree_(__m.__tree_.value_comp(),
1612 __alloc_traits::select_on_container_copy_construction(__m.__tree_.__alloc()))
1613 {
1614 insert(__m.begin(), __m.end());
1615 }
1616
Howard Hinnantd3a657f2011-07-01 19:24:36 +00001617 _LIBCPP_INLINE_VISIBILITY
1618 multimap& operator=(const multimap& __m)
1619 {
Marshall Clow476d3f42016-07-18 13:19:00 +00001620#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantd3a657f2011-07-01 19:24:36 +00001621 __tree_ = __m.__tree_;
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001622#else
Marshall Clowdb3cfcb2014-02-08 04:03:14 +00001623 if (this != &__m) {
1624 __tree_.clear();
1625 __tree_.value_comp() = __m.__tree_.value_comp();
1626 __tree_.__copy_assign_alloc(__m.__tree_);
1627 insert(__m.begin(), __m.end());
1628 }
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001629#endif
Howard Hinnantd3a657f2011-07-01 19:24:36 +00001630 return *this;
1631 }
1632
Eric Fiseliera85b1282017-04-18 21:08:06 +00001633#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001634
Howard Hinnant756c69b2010-09-22 16:48:34 +00001635 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001636 multimap(multimap&& __m)
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001637 _NOEXCEPT_(is_nothrow_move_constructible<__base>::value)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001638 : __tree_(_VSTD::move(__m.__tree_))
Howard Hinnantc51e1022010-05-11 19:42:16 +00001639 {
1640 }
1641
1642 multimap(multimap&& __m, const allocator_type& __a);
1643
Howard Hinnant756c69b2010-09-22 16:48:34 +00001644 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant33711792011-08-12 21:56:02 +00001645 multimap& operator=(multimap&& __m)
1646 _NOEXCEPT_(is_nothrow_move_assignable<__base>::value)
1647 {
1648 __tree_ = _VSTD::move(__m.__tree_);
1649 return *this;
1650 }
1651
Howard Hinnant33711792011-08-12 21:56:02 +00001652 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001653 multimap(initializer_list<value_type> __il, const key_compare& __comp = key_compare())
1654 : __tree_(__vc(__comp))
1655 {
1656 insert(__il.begin(), __il.end());
1657 }
1658
Howard Hinnant756c69b2010-09-22 16:48:34 +00001659 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001660 multimap(initializer_list<value_type> __il, const key_compare& __comp, const allocator_type& __a)
Marshall Clow657cbc42016-08-17 05:58:40 +00001661 : __tree_(__vc(__comp), typename __base::allocator_type(__a))
Howard Hinnantc51e1022010-05-11 19:42:16 +00001662 {
1663 insert(__il.begin(), __il.end());
1664 }
1665
Marshall Clow300abfb2013-09-11 01:15:47 +00001666#if _LIBCPP_STD_VER > 11
Eric Fiseliercf8c0212017-01-05 06:06:18 +00001667 _LIBCPP_INLINE_VISIBILITY
Marshall Clow300abfb2013-09-11 01:15:47 +00001668 multimap(initializer_list<value_type> __il, const allocator_type& __a)
1669 : multimap(__il, key_compare(), __a) {}
1670#endif
1671
Howard Hinnant756c69b2010-09-22 16:48:34 +00001672 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001673 multimap& operator=(initializer_list<value_type> __il)
1674 {
1675 __tree_.__assign_multi(__il.begin(), __il.end());
1676 return *this;
1677 }
Howard Hinnant33711792011-08-12 21:56:02 +00001678
Eric Fiseliera85b1282017-04-18 21:08:06 +00001679#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001680
Howard Hinnant756c69b2010-09-22 16:48:34 +00001681 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001682 explicit multimap(const allocator_type& __a)
Marshall Clow657cbc42016-08-17 05:58:40 +00001683 : __tree_(typename __base::allocator_type(__a))
Howard Hinnantc51e1022010-05-11 19:42:16 +00001684 {
1685 }
1686
Howard Hinnant756c69b2010-09-22 16:48:34 +00001687 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001688 multimap(const multimap& __m, const allocator_type& __a)
Marshall Clow657cbc42016-08-17 05:58:40 +00001689 : __tree_(__m.__tree_.value_comp(), typename __base::allocator_type(__a))
Howard Hinnantc51e1022010-05-11 19:42:16 +00001690 {
1691 insert(__m.begin(), __m.end());
1692 }
1693
Howard Hinnant756c69b2010-09-22 16:48:34 +00001694 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001695 iterator begin() _NOEXCEPT {return __tree_.begin();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001696 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001697 const_iterator begin() const _NOEXCEPT {return __tree_.begin();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001698 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001699 iterator end() _NOEXCEPT {return __tree_.end();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001700 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001701 const_iterator end() const _NOEXCEPT {return __tree_.end();}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001702
Howard Hinnant756c69b2010-09-22 16:48:34 +00001703 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001704 reverse_iterator rbegin() _NOEXCEPT {return reverse_iterator(end());}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001705 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001706 const_reverse_iterator rbegin() const _NOEXCEPT
1707 {return const_reverse_iterator(end());}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001708 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001709 reverse_iterator rend() _NOEXCEPT {return reverse_iterator(begin());}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001710 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001711 const_reverse_iterator rend() const _NOEXCEPT
1712 {return const_reverse_iterator(begin());}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001713
Howard Hinnant756c69b2010-09-22 16:48:34 +00001714 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001715 const_iterator cbegin() const _NOEXCEPT {return begin();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001716 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001717 const_iterator cend() const _NOEXCEPT {return end();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001718 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001719 const_reverse_iterator crbegin() const _NOEXCEPT {return rbegin();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001720 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001721 const_reverse_iterator crend() const _NOEXCEPT {return rend();}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001722
Marshall Clow425f5752017-11-15 05:51:26 +00001723 _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001724 bool empty() const _NOEXCEPT {return __tree_.size() == 0;}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001725 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001726 size_type size() const _NOEXCEPT {return __tree_.size();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001727 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001728 size_type max_size() const _NOEXCEPT {return __tree_.max_size();}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001729
Howard Hinnant756c69b2010-09-22 16:48:34 +00001730 _LIBCPP_INLINE_VISIBILITY
Marshall Clow657cbc42016-08-17 05:58:40 +00001731 allocator_type get_allocator() const _NOEXCEPT {return allocator_type(__tree_.__alloc());}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001732 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001733 key_compare key_comp() const {return __tree_.value_comp().key_comp();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001734 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001735 value_compare value_comp() const
1736 {return value_compare(__tree_.value_comp().key_comp());}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001737
Eric Fiselierd06276b2016-03-31 02:15:15 +00001738#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant74279a52010-09-04 23:28:19 +00001739
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001740 template <class ..._Args>
Eric Fiselierd06276b2016-03-31 02:15:15 +00001741 _LIBCPP_INLINE_VISIBILITY
1742 iterator emplace(_Args&& ...__args) {
1743 return __tree_.__emplace_multi(_VSTD::forward<_Args>(__args)...);
1744 }
Howard Hinnantc51e1022010-05-11 19:42:16 +00001745
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001746 template <class ..._Args>
Eric Fiselierd06276b2016-03-31 02:15:15 +00001747 _LIBCPP_INLINE_VISIBILITY
1748 iterator emplace_hint(const_iterator __p, _Args&& ...__args) {
1749 return __tree_.__emplace_hint_multi(__p.__i_, _VSTD::forward<_Args>(__args)...);
1750 }
Howard Hinnant74279a52010-09-04 23:28:19 +00001751
Howard Hinnantc834c512011-11-29 18:15:50 +00001752 template <class _Pp,
1753 class = typename enable_if<is_constructible<value_type, _Pp>::value>::type>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001754 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc834c512011-11-29 18:15:50 +00001755 iterator insert(_Pp&& __p)
1756 {return __tree_.__insert_multi(_VSTD::forward<_Pp>(__p));}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001757
Howard Hinnantc834c512011-11-29 18:15:50 +00001758 template <class _Pp,
1759 class = typename enable_if<is_constructible<value_type, _Pp>::value>::type>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001760 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc834c512011-11-29 18:15:50 +00001761 iterator insert(const_iterator __pos, _Pp&& __p)
1762 {return __tree_.__insert_multi(__pos.__i_, _VSTD::forward<_Pp>(__p));}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001763
Eric Fiselierd6143132016-04-18 01:40:45 +00001764 _LIBCPP_INLINE_VISIBILITY
1765 iterator insert(value_type&& __v)
1766 {return __tree_.__insert_multi(_VSTD::move(__v));}
1767
1768 _LIBCPP_INLINE_VISIBILITY
1769 iterator insert(const_iterator __p, value_type&& __v)
1770 {return __tree_.__insert_multi(__p.__i_, _VSTD::move(__v));}
1771
Eric Fiseliera85b1282017-04-18 21:08:06 +00001772
1773 _LIBCPP_INLINE_VISIBILITY
1774 void insert(initializer_list<value_type> __il)
1775 {insert(__il.begin(), __il.end());}
1776
Eric Fiselierd06276b2016-03-31 02:15:15 +00001777#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001778
Howard Hinnant756c69b2010-09-22 16:48:34 +00001779 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001780 iterator insert(const value_type& __v) {return __tree_.__insert_multi(__v);}
1781
Howard Hinnant756c69b2010-09-22 16:48:34 +00001782 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001783 iterator insert(const_iterator __p, const value_type& __v)
1784 {return __tree_.__insert_multi(__p.__i_, __v);}
1785
1786 template <class _InputIterator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001787 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001788 void insert(_InputIterator __f, _InputIterator __l)
1789 {
1790 for (const_iterator __e = cend(); __f != __l; ++__f)
1791 __tree_.__insert_multi(__e.__i_, *__f);
1792 }
1793
Howard Hinnant756c69b2010-09-22 16:48:34 +00001794 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001795 iterator erase(const_iterator __p) {return __tree_.erase(__p.__i_);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001796 _LIBCPP_INLINE_VISIBILITY
Marshall Clow22ea5b82015-05-10 13:35:00 +00001797 iterator erase(iterator __p) {return __tree_.erase(__p.__i_);}
1798 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001799 size_type erase(const key_type& __k) {return __tree_.__erase_multi(__k);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001800 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001801 iterator erase(const_iterator __f, const_iterator __l)
1802 {return __tree_.erase(__f.__i_, __l.__i_);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001803 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001804 void clear() {__tree_.clear();}
1805
Howard Hinnant756c69b2010-09-22 16:48:34 +00001806 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001807 void swap(multimap& __m)
1808 _NOEXCEPT_(__is_nothrow_swappable<__base>::value)
1809 {__tree_.swap(__m.__tree_);}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001810
Howard Hinnant756c69b2010-09-22 16:48:34 +00001811 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001812 iterator find(const key_type& __k) {return __tree_.find(__k);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001813 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001814 const_iterator find(const key_type& __k) const {return __tree_.find(__k);}
Marshall Clowebb57322013-08-13 22:18:47 +00001815#if _LIBCPP_STD_VER > 11
1816 template <typename _K2>
1817 _LIBCPP_INLINE_VISIBILITY
1818 typename enable_if<__is_transparent<_Compare, _K2>::value,iterator>::type
1819 find(const _K2& __k) {return __tree_.find(__k);}
1820 template <typename _K2>
1821 _LIBCPP_INLINE_VISIBILITY
1822 typename enable_if<__is_transparent<_Compare, _K2>::value,const_iterator>::type
1823 find(const _K2& __k) const {return __tree_.find(__k);}
1824#endif
1825
Howard Hinnant756c69b2010-09-22 16:48:34 +00001826 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001827 size_type count(const key_type& __k) const
1828 {return __tree_.__count_multi(__k);}
Marshall Clowe6a5f522014-08-24 23:54:16 +00001829#if _LIBCPP_STD_VER > 11
1830 template <typename _K2>
1831 _LIBCPP_INLINE_VISIBILITY
1832 typename enable_if<__is_transparent<_Compare, _K2>::value,size_type>::type
Marshall Clow141e47b2015-06-30 18:15:41 +00001833 count(const _K2& __k) const {return __tree_.__count_multi(__k);}
Marshall Clowe6a5f522014-08-24 23:54:16 +00001834#endif
Howard Hinnant756c69b2010-09-22 16:48:34 +00001835 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001836 iterator lower_bound(const key_type& __k)
1837 {return __tree_.lower_bound(__k);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001838 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001839 const_iterator lower_bound(const key_type& __k) const
1840 {return __tree_.lower_bound(__k);}
Marshall Clowebb57322013-08-13 22:18:47 +00001841#if _LIBCPP_STD_VER > 11
1842 template <typename _K2>
1843 _LIBCPP_INLINE_VISIBILITY
1844 typename enable_if<__is_transparent<_Compare, _K2>::value,iterator>::type
1845 lower_bound(const _K2& __k) {return __tree_.lower_bound(__k);}
1846
1847 template <typename _K2>
1848 _LIBCPP_INLINE_VISIBILITY
1849 typename enable_if<__is_transparent<_Compare, _K2>::value,const_iterator>::type
1850 lower_bound(const _K2& __k) const {return __tree_.lower_bound(__k);}
1851#endif
1852
Howard Hinnant756c69b2010-09-22 16:48:34 +00001853 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001854 iterator upper_bound(const key_type& __k)
1855 {return __tree_.upper_bound(__k);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001856 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001857 const_iterator upper_bound(const key_type& __k) const
1858 {return __tree_.upper_bound(__k);}
Marshall Clowebb57322013-08-13 22:18:47 +00001859#if _LIBCPP_STD_VER > 11
1860 template <typename _K2>
1861 _LIBCPP_INLINE_VISIBILITY
1862 typename enable_if<__is_transparent<_Compare, _K2>::value,iterator>::type
1863 upper_bound(const _K2& __k) {return __tree_.upper_bound(__k);}
1864 template <typename _K2>
1865 _LIBCPP_INLINE_VISIBILITY
1866 typename enable_if<__is_transparent<_Compare, _K2>::value,const_iterator>::type
1867 upper_bound(const _K2& __k) const {return __tree_.upper_bound(__k);}
1868#endif
1869
Howard Hinnant756c69b2010-09-22 16:48:34 +00001870 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001871 pair<iterator,iterator> equal_range(const key_type& __k)
1872 {return __tree_.__equal_range_multi(__k);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001873 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001874 pair<const_iterator,const_iterator> equal_range(const key_type& __k) const
1875 {return __tree_.__equal_range_multi(__k);}
Marshall Clowebb57322013-08-13 22:18:47 +00001876#if _LIBCPP_STD_VER > 11
1877 template <typename _K2>
1878 _LIBCPP_INLINE_VISIBILITY
1879 typename enable_if<__is_transparent<_Compare, _K2>::value,pair<iterator,iterator>>::type
1880 equal_range(const _K2& __k) {return __tree_.__equal_range_multi(__k);}
1881 template <typename _K2>
1882 _LIBCPP_INLINE_VISIBILITY
1883 typename enable_if<__is_transparent<_Compare, _K2>::value,pair<const_iterator,const_iterator>>::type
1884 equal_range(const _K2& __k) const {return __tree_.__equal_range_multi(__k);}
1885#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001886
1887private:
1888 typedef typename __base::__node __node;
1889 typedef typename __base::__node_allocator __node_allocator;
1890 typedef typename __base::__node_pointer __node_pointer;
Eric Fiseliera92b0732016-02-20 07:12:17 +00001891
Howard Hinnantc834c512011-11-29 18:15:50 +00001892 typedef __map_node_destructor<__node_allocator> _Dp;
1893 typedef unique_ptr<__node, _Dp> __node_holder;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001894};
1895
Eric Fiselierd06276b2016-03-31 02:15:15 +00001896#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001897template <class _Key, class _Tp, class _Compare, class _Allocator>
1898multimap<_Key, _Tp, _Compare, _Allocator>::multimap(multimap&& __m, const allocator_type& __a)
Marshall Clow657cbc42016-08-17 05:58:40 +00001899 : __tree_(_VSTD::move(__m.__tree_), typename __base::allocator_type(__a))
Howard Hinnantc51e1022010-05-11 19:42:16 +00001900{
1901 if (__a != __m.get_allocator())
1902 {
1903 const_iterator __e = cend();
1904 while (!__m.empty())
1905 __tree_.__insert_multi(__e.__i_,
Erik Pilkingtond3fe2992018-06-04 20:38:23 +00001906 _VSTD::move(__m.__tree_.remove(__m.begin().__i_)->__value_.__move()));
Howard Hinnantc51e1022010-05-11 19:42:16 +00001907 }
1908}
Eric Fiselierd06276b2016-03-31 02:15:15 +00001909#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001910
1911template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001912inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001913bool
1914operator==(const multimap<_Key, _Tp, _Compare, _Allocator>& __x,
1915 const multimap<_Key, _Tp, _Compare, _Allocator>& __y)
1916{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001917 return __x.size() == __y.size() && _VSTD::equal(__x.begin(), __x.end(), __y.begin());
Howard Hinnantc51e1022010-05-11 19:42:16 +00001918}
1919
1920template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001921inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001922bool
1923operator< (const multimap<_Key, _Tp, _Compare, _Allocator>& __x,
1924 const multimap<_Key, _Tp, _Compare, _Allocator>& __y)
1925{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001926 return _VSTD::lexicographical_compare(__x.begin(), __x.end(), __y.begin(), __y.end());
Howard Hinnantc51e1022010-05-11 19:42:16 +00001927}
1928
1929template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001930inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001931bool
1932operator!=(const multimap<_Key, _Tp, _Compare, _Allocator>& __x,
1933 const multimap<_Key, _Tp, _Compare, _Allocator>& __y)
1934{
1935 return !(__x == __y);
1936}
1937
1938template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001939inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001940bool
1941operator> (const multimap<_Key, _Tp, _Compare, _Allocator>& __x,
1942 const multimap<_Key, _Tp, _Compare, _Allocator>& __y)
1943{
1944 return __y < __x;
1945}
1946
1947template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001948inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001949bool
1950operator>=(const multimap<_Key, _Tp, _Compare, _Allocator>& __x,
1951 const multimap<_Key, _Tp, _Compare, _Allocator>& __y)
1952{
1953 return !(__x < __y);
1954}
1955
1956template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001957inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001958bool
1959operator<=(const multimap<_Key, _Tp, _Compare, _Allocator>& __x,
1960 const multimap<_Key, _Tp, _Compare, _Allocator>& __y)
1961{
1962 return !(__y < __x);
1963}
1964
1965template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001966inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001967void
1968swap(multimap<_Key, _Tp, _Compare, _Allocator>& __x,
1969 multimap<_Key, _Tp, _Compare, _Allocator>& __y)
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001970 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
Howard Hinnantc51e1022010-05-11 19:42:16 +00001971{
1972 __x.swap(__y);
1973}
1974
1975_LIBCPP_END_NAMESPACE_STD
1976
1977#endif // _LIBCPP_MAP