blob: f6f2b6835be349b60abb708f352d502c4ec82807 [file] [log] [blame]
Howard Hinnantc51e1022010-05-11 19:42:16 +00001// -*- C++ -*-
2//===----------------------------- map ------------------------------------===//
3//
Howard Hinnantc566dc32010-05-11 21:36:01 +00004// The LLVM Compiler Infrastructure
Howard Hinnantc51e1022010-05-11 19:42:16 +00005//
Howard Hinnantee11c312010-11-16 22:09:02 +00006// This file is dual licensed under the MIT and the University of Illinois Open
7// Source Licenses. See LICENSE.TXT for details.
Howard Hinnantc51e1022010-05-11 19:42:16 +00008//
9//===----------------------------------------------------------------------===//
10
11#ifndef _LIBCPP_MAP
12#define _LIBCPP_MAP
13
14/*
15
16 map synopsis
17
18namespace std
19{
20
21template <class Key, class T, class Compare = less<Key>,
22 class Allocator = allocator<pair<const Key, T>>>
23class map
24{
25public:
26 // types:
27 typedef Key key_type;
28 typedef T mapped_type;
29 typedef pair<const key_type, mapped_type> value_type;
30 typedef Compare key_compare;
31 typedef Allocator allocator_type;
32 typedef typename allocator_type::reference reference;
33 typedef typename allocator_type::const_reference const_reference;
34 typedef typename allocator_type::pointer pointer;
35 typedef typename allocator_type::const_pointer const_pointer;
36 typedef typename allocator_type::size_type size_type;
37 typedef typename allocator_type::difference_type difference_type;
38
39 typedef implementation-defined iterator;
40 typedef implementation-defined const_iterator;
41 typedef std::reverse_iterator<iterator> reverse_iterator;
42 typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
Erik Pilkingtonc37a3d82018-08-01 01:33:38 +000043 typedef unspecified node_type; // C++17
44 typedef INSERT_RETURN_TYPE<iterator, node_type> insert_return_type; // C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +000045
46 class value_compare
47 : public binary_function<value_type, value_type, bool>
48 {
49 friend class map;
50 protected:
51 key_compare comp;
52
53 value_compare(key_compare c);
54 public:
55 bool operator()(const value_type& x, const value_type& y) const;
56 };
57
58 // construct/copy/destroy:
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +000059 map()
60 noexcept(
61 is_nothrow_default_constructible<allocator_type>::value &&
62 is_nothrow_default_constructible<key_compare>::value &&
63 is_nothrow_copy_constructible<key_compare>::value);
Howard Hinnantc51e1022010-05-11 19:42:16 +000064 explicit map(const key_compare& comp);
65 map(const key_compare& comp, const allocator_type& a);
66 template <class InputIterator>
67 map(InputIterator first, InputIterator last,
68 const key_compare& comp = key_compare());
69 template <class InputIterator>
70 map(InputIterator first, InputIterator last,
71 const key_compare& comp, const allocator_type& a);
72 map(const map& m);
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +000073 map(map&& m)
74 noexcept(
75 is_nothrow_move_constructible<allocator_type>::value &&
76 is_nothrow_move_constructible<key_compare>::value);
Howard Hinnantc51e1022010-05-11 19:42:16 +000077 explicit map(const allocator_type& a);
78 map(const map& m, const allocator_type& a);
79 map(map&& m, const allocator_type& a);
80 map(initializer_list<value_type> il, const key_compare& comp = key_compare());
81 map(initializer_list<value_type> il, const key_compare& comp, const allocator_type& a);
Marshall Clow300abfb2013-09-11 01:15:47 +000082 template <class InputIterator>
83 map(InputIterator first, InputIterator last, const allocator_type& a)
84 : map(first, last, Compare(), a) {} // C++14
85 map(initializer_list<value_type> il, const allocator_type& a)
86 : map(il, Compare(), a) {} // C++14
87 ~map();
Howard Hinnantc51e1022010-05-11 19:42:16 +000088
89 map& operator=(const map& m);
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +000090 map& operator=(map&& m)
91 noexcept(
92 allocator_type::propagate_on_container_move_assignment::value &&
93 is_nothrow_move_assignable<allocator_type>::value &&
Howard Hinnantf95f4f52011-06-04 15:22:34 +000094 is_nothrow_move_assignable<key_compare>::value);
Howard Hinnantc51e1022010-05-11 19:42:16 +000095 map& operator=(initializer_list<value_type> il);
96
97 // iterators:
Howard Hinnantf95f4f52011-06-04 15:22:34 +000098 iterator begin() noexcept;
99 const_iterator begin() const noexcept;
100 iterator end() noexcept;
101 const_iterator end() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000102
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000103 reverse_iterator rbegin() noexcept;
104 const_reverse_iterator rbegin() const noexcept;
105 reverse_iterator rend() noexcept;
106 const_reverse_iterator rend() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000107
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000108 const_iterator cbegin() const noexcept;
109 const_iterator cend() const noexcept;
110 const_reverse_iterator crbegin() const noexcept;
111 const_reverse_iterator crend() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000112
113 // capacity:
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000114 bool empty() const noexcept;
115 size_type size() const noexcept;
116 size_type max_size() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000117
118 // element access:
119 mapped_type& operator[](const key_type& k);
120 mapped_type& operator[](key_type&& k);
121
122 mapped_type& at(const key_type& k);
123 const mapped_type& at(const key_type& k) const;
124
125 // modifiers:
126 template <class... Args>
127 pair<iterator, bool> emplace(Args&&... args);
128 template <class... Args>
129 iterator emplace_hint(const_iterator position, Args&&... args);
130 pair<iterator, bool> insert(const value_type& v);
Marshall Clowd430d022016-01-05 19:32:41 +0000131 pair<iterator, bool> insert( value_type&& v); // C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000132 template <class P>
133 pair<iterator, bool> insert(P&& p);
134 iterator insert(const_iterator position, const value_type& v);
Marshall Clowd430d022016-01-05 19:32:41 +0000135 iterator insert(const_iterator position, value_type&& v); // C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000136 template <class P>
137 iterator insert(const_iterator position, P&& p);
138 template <class InputIterator>
139 void insert(InputIterator first, InputIterator last);
140 void insert(initializer_list<value_type> il);
141
Erik Pilkingtonc37a3d82018-08-01 01:33:38 +0000142 node_type extract(const_iterator position); // C++17
143 node_type extract(const key_type& x); // C++17
144 insert_return_type insert(node_type&& nh); // C++17
145 iterator insert(const_iterator hint, node_type&& nh); // C++17
146
Marshall Clow3223db82015-07-07 03:37:33 +0000147 template <class... Args>
148 pair<iterator, bool> try_emplace(const key_type& k, Args&&... args); // C++17
149 template <class... Args>
150 pair<iterator, bool> try_emplace(key_type&& k, Args&&... args); // C++17
151 template <class... Args>
152 iterator try_emplace(const_iterator hint, const key_type& k, Args&&... args); // C++17
153 template <class... Args>
154 iterator try_emplace(const_iterator hint, key_type&& k, Args&&... args); // C++17
155 template <class M>
156 pair<iterator, bool> insert_or_assign(const key_type& k, M&& obj); // C++17
157 template <class M>
158 pair<iterator, bool> insert_or_assign(key_type&& k, M&& obj); // C++17
159 template <class M>
160 iterator insert_or_assign(const_iterator hint, const key_type& k, M&& obj); // C++17
161 template <class M>
162 iterator insert_or_assign(const_iterator hint, key_type&& k, M&& obj); // C++17
163
Howard Hinnantc51e1022010-05-11 19:42:16 +0000164 iterator erase(const_iterator position);
Marshall Clow22ea5b82015-05-10 13:35:00 +0000165 iterator erase(iterator position); // C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000166 size_type erase(const key_type& k);
167 iterator erase(const_iterator first, const_iterator last);
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000168 void clear() noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000169
Erik Pilkington82a65ad2018-10-31 17:31:35 +0000170 template<class C2>
171 void merge(map<Key, T, C2, Allocator>& source); // C++17
172 template<class C2>
173 void merge(map<Key, T, C2, Allocator>&& source); // C++17
174 template<class C2>
175 void merge(multimap<Key, T, C2, Allocator>& source); // C++17
176 template<class C2>
177 void merge(multimap<Key, T, C2, Allocator>&& source); // C++17
178
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000179 void swap(map& m)
Marshall Clow8982dcd2015-07-13 20:04:56 +0000180 noexcept(allocator_traits<allocator_type>::is_always_equal::value &&
Eric Fiselier6bfed252016-04-21 23:38:59 +0000181 is_nothrow_swappable<key_compare>::value); // C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000182
183 // observers:
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000184 allocator_type get_allocator() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000185 key_compare key_comp() const;
186 value_compare value_comp() const;
187
188 // map operations:
189 iterator find(const key_type& k);
190 const_iterator find(const key_type& k) const;
Marshall Clowebb57322013-08-13 22:18:47 +0000191 template<typename K>
192 iterator find(const K& x); // C++14
193 template<typename K>
194 const_iterator find(const K& x) const; // C++14
195 template<typename K>
Marshall Clowe6a5f522014-08-24 23:54:16 +0000196 size_type count(const K& x) const; // C++14
Marshall Clowebb57322013-08-13 22:18:47 +0000197
Howard Hinnantc51e1022010-05-11 19:42:16 +0000198 size_type count(const key_type& k) const;
199 iterator lower_bound(const key_type& k);
200 const_iterator lower_bound(const key_type& k) const;
Marshall Clowebb57322013-08-13 22:18:47 +0000201 template<typename K>
202 iterator lower_bound(const K& x); // C++14
203 template<typename K>
204 const_iterator lower_bound(const K& x) const; // C++14
205
Howard Hinnantc51e1022010-05-11 19:42:16 +0000206 iterator upper_bound(const key_type& k);
207 const_iterator upper_bound(const key_type& k) const;
Marshall Clowebb57322013-08-13 22:18:47 +0000208 template<typename K>
209 iterator upper_bound(const K& x); // C++14
210 template<typename K>
211 const_iterator upper_bound(const K& x) const; // C++14
212
Howard Hinnantc51e1022010-05-11 19:42:16 +0000213 pair<iterator,iterator> equal_range(const key_type& k);
214 pair<const_iterator,const_iterator> equal_range(const key_type& k) const;
Marshall Clowebb57322013-08-13 22:18:47 +0000215 template<typename K>
216 pair<iterator,iterator> equal_range(const K& x); // C++14
217 template<typename K>
218 pair<const_iterator,const_iterator> equal_range(const K& x) const; // C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000219};
220
221template <class Key, class T, class Compare, class Allocator>
222bool
223operator==(const map<Key, T, Compare, Allocator>& x,
224 const map<Key, T, Compare, Allocator>& y);
225
226template <class Key, class T, class Compare, class Allocator>
227bool
228operator< (const map<Key, T, Compare, Allocator>& x,
229 const map<Key, T, Compare, Allocator>& y);
230
231template <class Key, class T, class Compare, class Allocator>
232bool
233operator!=(const map<Key, T, Compare, Allocator>& x,
234 const map<Key, T, Compare, Allocator>& y);
235
236template <class Key, class T, class Compare, class Allocator>
237bool
238operator> (const map<Key, T, Compare, Allocator>& x,
239 const map<Key, T, Compare, Allocator>& y);
240
241template <class Key, class T, class Compare, class Allocator>
242bool
243operator>=(const map<Key, T, Compare, Allocator>& x,
244 const map<Key, T, Compare, Allocator>& y);
245
246template <class Key, class T, class Compare, class Allocator>
247bool
248operator<=(const map<Key, T, Compare, Allocator>& x,
249 const map<Key, T, Compare, Allocator>& y);
250
251// specialized algorithms:
252template <class Key, class T, class Compare, class Allocator>
253void
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000254swap(map<Key, T, Compare, Allocator>& x, map<Key, T, Compare, Allocator>& y)
255 noexcept(noexcept(x.swap(y)));
Howard Hinnantc51e1022010-05-11 19:42:16 +0000256
257template <class Key, class T, class Compare = less<Key>,
258 class Allocator = allocator<pair<const Key, T>>>
259class multimap
260{
261public:
262 // types:
263 typedef Key key_type;
264 typedef T mapped_type;
265 typedef pair<const key_type,mapped_type> value_type;
266 typedef Compare key_compare;
267 typedef Allocator allocator_type;
268 typedef typename allocator_type::reference reference;
269 typedef typename allocator_type::const_reference const_reference;
270 typedef typename allocator_type::size_type size_type;
271 typedef typename allocator_type::difference_type difference_type;
272 typedef typename allocator_type::pointer pointer;
273 typedef typename allocator_type::const_pointer const_pointer;
274
275 typedef implementation-defined iterator;
276 typedef implementation-defined const_iterator;
277 typedef std::reverse_iterator<iterator> reverse_iterator;
278 typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
Erik Pilkingtonc37a3d82018-08-01 01:33:38 +0000279 typedef unspecified node_type; // C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000280
281 class value_compare
282 : public binary_function<value_type,value_type,bool>
283 {
284 friend class multimap;
285 protected:
286 key_compare comp;
287 value_compare(key_compare c);
288 public:
289 bool operator()(const value_type& x, const value_type& y) const;
290 };
291
292 // construct/copy/destroy:
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000293 multimap()
294 noexcept(
295 is_nothrow_default_constructible<allocator_type>::value &&
296 is_nothrow_default_constructible<key_compare>::value &&
297 is_nothrow_copy_constructible<key_compare>::value);
298 explicit multimap(const key_compare& comp);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000299 multimap(const key_compare& comp, const allocator_type& a);
300 template <class InputIterator>
301 multimap(InputIterator first, InputIterator last, const key_compare& comp);
302 template <class InputIterator>
303 multimap(InputIterator first, InputIterator last, const key_compare& comp,
304 const allocator_type& a);
305 multimap(const multimap& m);
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000306 multimap(multimap&& m)
307 noexcept(
308 is_nothrow_move_constructible<allocator_type>::value &&
309 is_nothrow_move_constructible<key_compare>::value);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000310 explicit multimap(const allocator_type& a);
311 multimap(const multimap& m, const allocator_type& a);
312 multimap(multimap&& m, const allocator_type& a);
313 multimap(initializer_list<value_type> il, const key_compare& comp = key_compare());
314 multimap(initializer_list<value_type> il, const key_compare& comp,
315 const allocator_type& a);
Marshall Clow300abfb2013-09-11 01:15:47 +0000316 template <class InputIterator>
317 multimap(InputIterator first, InputIterator last, const allocator_type& a)
318 : multimap(first, last, Compare(), a) {} // C++14
319 multimap(initializer_list<value_type> il, const allocator_type& a)
320 : multimap(il, Compare(), a) {} // C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000321 ~multimap();
322
323 multimap& operator=(const multimap& m);
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000324 multimap& operator=(multimap&& m)
325 noexcept(
326 allocator_type::propagate_on_container_move_assignment::value &&
327 is_nothrow_move_assignable<allocator_type>::value &&
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000328 is_nothrow_move_assignable<key_compare>::value);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000329 multimap& operator=(initializer_list<value_type> il);
330
331 // iterators:
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000332 iterator begin() noexcept;
333 const_iterator begin() const noexcept;
334 iterator end() noexcept;
335 const_iterator end() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000336
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000337 reverse_iterator rbegin() noexcept;
338 const_reverse_iterator rbegin() const noexcept;
339 reverse_iterator rend() noexcept;
340 const_reverse_iterator rend() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000341
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000342 const_iterator cbegin() const noexcept;
343 const_iterator cend() const noexcept;
344 const_reverse_iterator crbegin() const noexcept;
345 const_reverse_iterator crend() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000346
347 // capacity:
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000348 bool empty() const noexcept;
349 size_type size() const noexcept;
350 size_type max_size() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000351
352 // modifiers:
353 template <class... Args>
354 iterator emplace(Args&&... args);
355 template <class... Args>
356 iterator emplace_hint(const_iterator position, Args&&... args);
357 iterator insert(const value_type& v);
Marshall Clowd430d022016-01-05 19:32:41 +0000358 iterator insert( value_type&& v); // C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000359 template <class P>
360 iterator insert(P&& p);
361 iterator insert(const_iterator position, const value_type& v);
Marshall Clowd430d022016-01-05 19:32:41 +0000362 iterator insert(const_iterator position, value_type&& v); // C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000363 template <class P>
364 iterator insert(const_iterator position, P&& p);
365 template <class InputIterator>
366 void insert(InputIterator first, InputIterator last);
367 void insert(initializer_list<value_type> il);
368
Erik Pilkingtonc37a3d82018-08-01 01:33:38 +0000369 node_type extract(const_iterator position); // C++17
370 node_type extract(const key_type& x); // C++17
371 iterator insert(node_type&& nh); // C++17
372 iterator insert(const_iterator hint, node_type&& nh); // C++17
373
Howard Hinnantc51e1022010-05-11 19:42:16 +0000374 iterator erase(const_iterator position);
Marshall Clow22ea5b82015-05-10 13:35:00 +0000375 iterator erase(iterator position); // C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000376 size_type erase(const key_type& k);
377 iterator erase(const_iterator first, const_iterator last);
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000378 void clear() noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000379
Erik Pilkington82a65ad2018-10-31 17:31:35 +0000380 template<class C2>
381 void merge(multimap<Key, T, C2, Allocator>& source); // C++17
382 template<class C2>
383 void merge(multimap<Key, T, C2, Allocator>&& source); // C++17
384 template<class C2>
385 void merge(map<Key, T, C2, Allocator>& source); // C++17
386 template<class C2>
387 void merge(map<Key, T, C2, Allocator>&& source); // C++17
388
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000389 void swap(multimap& m)
Marshall Clow8982dcd2015-07-13 20:04:56 +0000390 noexcept(allocator_traits<allocator_type>::is_always_equal::value &&
Eric Fiselier6bfed252016-04-21 23:38:59 +0000391 is_nothrow_swappable<key_compare>::value); // C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000392
393 // observers:
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000394 allocator_type get_allocator() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000395 key_compare key_comp() const;
396 value_compare value_comp() const;
397
398 // map operations:
399 iterator find(const key_type& k);
400 const_iterator find(const key_type& k) const;
Marshall Clowebb57322013-08-13 22:18:47 +0000401 template<typename K>
402 iterator find(const K& x); // C++14
403 template<typename K>
404 const_iterator find(const K& x) const; // C++14
405 template<typename K>
Marshall Clowe6a5f522014-08-24 23:54:16 +0000406 size_type count(const K& x) const; // C++14
Marshall Clowebb57322013-08-13 22:18:47 +0000407
Howard Hinnantc51e1022010-05-11 19:42:16 +0000408 size_type count(const key_type& k) const;
409 iterator lower_bound(const key_type& k);
410 const_iterator lower_bound(const key_type& k) const;
Marshall Clowebb57322013-08-13 22:18:47 +0000411 template<typename K>
412 iterator lower_bound(const K& x); // C++14
413 template<typename K>
414 const_iterator lower_bound(const K& x) const; // C++14
415
Howard Hinnantc51e1022010-05-11 19:42:16 +0000416 iterator upper_bound(const key_type& k);
417 const_iterator upper_bound(const key_type& k) const;
Marshall Clowebb57322013-08-13 22:18:47 +0000418 template<typename K>
419 iterator upper_bound(const K& x); // C++14
420 template<typename K>
421 const_iterator upper_bound(const K& x) const; // C++14
422
Howard Hinnantc51e1022010-05-11 19:42:16 +0000423 pair<iterator,iterator> equal_range(const key_type& k);
424 pair<const_iterator,const_iterator> equal_range(const key_type& k) const;
Marshall Clowebb57322013-08-13 22:18:47 +0000425 template<typename K>
426 pair<iterator,iterator> equal_range(const K& x); // C++14
427 template<typename K>
428 pair<const_iterator,const_iterator> equal_range(const K& x) const; // C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000429};
430
431template <class Key, class T, class Compare, class Allocator>
432bool
433operator==(const multimap<Key, T, Compare, Allocator>& x,
434 const multimap<Key, T, Compare, Allocator>& y);
435
436template <class Key, class T, class Compare, class Allocator>
437bool
438operator< (const multimap<Key, T, Compare, Allocator>& x,
439 const multimap<Key, T, Compare, Allocator>& y);
440
441template <class Key, class T, class Compare, class Allocator>
442bool
443operator!=(const multimap<Key, T, Compare, Allocator>& x,
444 const multimap<Key, T, Compare, Allocator>& y);
445
446template <class Key, class T, class Compare, class Allocator>
447bool
448operator> (const multimap<Key, T, Compare, Allocator>& x,
449 const multimap<Key, T, Compare, Allocator>& y);
450
451template <class Key, class T, class Compare, class Allocator>
452bool
453operator>=(const multimap<Key, T, Compare, Allocator>& x,
454 const multimap<Key, T, Compare, Allocator>& y);
455
456template <class Key, class T, class Compare, class Allocator>
457bool
458operator<=(const multimap<Key, T, Compare, Allocator>& x,
459 const multimap<Key, T, Compare, Allocator>& y);
460
461// specialized algorithms:
462template <class Key, class T, class Compare, class Allocator>
463void
464swap(multimap<Key, T, Compare, Allocator>& x,
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000465 multimap<Key, T, Compare, Allocator>& y)
466 noexcept(noexcept(x.swap(y)));
Howard Hinnantc51e1022010-05-11 19:42:16 +0000467
468} // std
469
470*/
471
472#include <__config>
473#include <__tree>
Erik Pilkingtonc37a3d82018-08-01 01:33:38 +0000474#include <__node_handle>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000475#include <iterator>
476#include <memory>
477#include <utility>
478#include <functional>
479#include <initializer_list>
Eric Fiselierf7394302015-06-13 07:08:02 +0000480#include <type_traits>
Marshall Clow0a1e7502018-09-12 19:41:40 +0000481#include <version>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000482
Howard Hinnantaaaa52b2011-10-17 20:05:10 +0000483#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000484#pragma GCC system_header
Howard Hinnantaaaa52b2011-10-17 20:05:10 +0000485#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000486
487_LIBCPP_BEGIN_NAMESPACE_STD
488
Louis Dionne878a3a82018-12-06 21:46:17 +0000489template <class _Key, class _CP, class _Compare,
490 bool = is_empty<_Compare>::value && !__libcpp_is_final<_Compare>::value>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000491class __map_value_compare
492 : private _Compare
493{
Howard Hinnantc51e1022010-05-11 19:42:16 +0000494public:
Howard Hinnant756c69b2010-09-22 16:48:34 +0000495 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000496 __map_value_compare()
497 _NOEXCEPT_(is_nothrow_default_constructible<_Compare>::value)
498 : _Compare() {}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000499 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000500 __map_value_compare(_Compare c)
501 _NOEXCEPT_(is_nothrow_copy_constructible<_Compare>::value)
502 : _Compare(c) {}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000503 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000504 const _Compare& key_comp() const _NOEXCEPT {return *this;}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000505 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000506 bool operator()(const _CP& __x, const _CP& __y) const
Erik Pilkingtond3fe2992018-06-04 20:38:23 +0000507 {return static_cast<const _Compare&>(*this)(__x.__get_value().first, __y.__get_value().first);}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000508 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000509 bool operator()(const _CP& __x, const _Key& __y) const
Erik Pilkingtond3fe2992018-06-04 20:38:23 +0000510 {return static_cast<const _Compare&>(*this)(__x.__get_value().first, __y);}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000511 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000512 bool operator()(const _Key& __x, const _CP& __y) const
Erik Pilkingtond3fe2992018-06-04 20:38:23 +0000513 {return static_cast<const _Compare&>(*this)(__x, __y.__get_value().first);}
Marshall Clow8982dcd2015-07-13 20:04:56 +0000514 void swap(__map_value_compare&__y)
515 _NOEXCEPT_(__is_nothrow_swappable<_Compare>::value)
516 {
Eric Fiselier68b5f0b2017-04-13 00:34:24 +0000517 using _VSTD::swap;
518 swap(static_cast<_Compare&>(*this), static_cast<_Compare&>(__y));
Marshall Clow8982dcd2015-07-13 20:04:56 +0000519 }
Marshall Clowebb57322013-08-13 22:18:47 +0000520
521#if _LIBCPP_STD_VER > 11
522 template <typename _K2>
523 _LIBCPP_INLINE_VISIBILITY
524 typename enable_if<__is_transparent<_Compare, _K2>::value, bool>::type
525 operator () ( const _K2& __x, const _CP& __y ) const
Erik Pilkingtond3fe2992018-06-04 20:38:23 +0000526 {return static_cast<const _Compare&>(*this) (__x, __y.__get_value().first);}
Marshall Clowebb57322013-08-13 22:18:47 +0000527
528 template <typename _K2>
529 _LIBCPP_INLINE_VISIBILITY
530 typename enable_if<__is_transparent<_Compare, _K2>::value, bool>::type
531 operator () (const _CP& __x, const _K2& __y) const
Erik Pilkingtond3fe2992018-06-04 20:38:23 +0000532 {return static_cast<const _Compare&>(*this) (__x.__get_value().first, __y);}
Marshall Clowebb57322013-08-13 22:18:47 +0000533#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000534};
535
Howard Hinnant90b91592013-07-05 18:06:00 +0000536template <class _Key, class _CP, class _Compare>
537class __map_value_compare<_Key, _CP, _Compare, false>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000538{
539 _Compare comp;
540
Howard Hinnantc51e1022010-05-11 19:42:16 +0000541public:
Howard Hinnant756c69b2010-09-22 16:48:34 +0000542 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000543 __map_value_compare()
544 _NOEXCEPT_(is_nothrow_default_constructible<_Compare>::value)
545 : comp() {}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000546 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000547 __map_value_compare(_Compare c)
548 _NOEXCEPT_(is_nothrow_copy_constructible<_Compare>::value)
549 : comp(c) {}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000550 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000551 const _Compare& key_comp() const _NOEXCEPT {return comp;}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000552
Howard Hinnant756c69b2010-09-22 16:48:34 +0000553 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000554 bool operator()(const _CP& __x, const _CP& __y) const
Erik Pilkingtond3fe2992018-06-04 20:38:23 +0000555 {return comp(__x.__get_value().first, __y.__get_value().first);}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000556 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000557 bool operator()(const _CP& __x, const _Key& __y) const
Erik Pilkingtond3fe2992018-06-04 20:38:23 +0000558 {return comp(__x.__get_value().first, __y);}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000559 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000560 bool operator()(const _Key& __x, const _CP& __y) const
Erik Pilkingtond3fe2992018-06-04 20:38:23 +0000561 {return comp(__x, __y.__get_value().first);}
Marshall Clow8982dcd2015-07-13 20:04:56 +0000562 void swap(__map_value_compare&__y)
563 _NOEXCEPT_(__is_nothrow_swappable<_Compare>::value)
564 {
565 using _VSTD::swap;
566 swap(comp, __y.comp);
567 }
Eric Fiseliercf8c0212017-01-05 06:06:18 +0000568
Marshall Clowebb57322013-08-13 22:18:47 +0000569#if _LIBCPP_STD_VER > 11
570 template <typename _K2>
571 _LIBCPP_INLINE_VISIBILITY
572 typename enable_if<__is_transparent<_Compare, _K2>::value, bool>::type
573 operator () ( const _K2& __x, const _CP& __y ) const
Erik Pilkingtond3fe2992018-06-04 20:38:23 +0000574 {return comp (__x, __y.__get_value().first);}
Marshall Clowebb57322013-08-13 22:18:47 +0000575
576 template <typename _K2>
577 _LIBCPP_INLINE_VISIBILITY
578 typename enable_if<__is_transparent<_Compare, _K2>::value, bool>::type
579 operator () (const _CP& __x, const _K2& __y) const
Erik Pilkingtond3fe2992018-06-04 20:38:23 +0000580 {return comp (__x.__get_value().first, __y);}
Marshall Clowebb57322013-08-13 22:18:47 +0000581#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000582};
583
Marshall Clow8982dcd2015-07-13 20:04:56 +0000584template <class _Key, class _CP, class _Compare, bool __b>
585inline _LIBCPP_INLINE_VISIBILITY
586void
587swap(__map_value_compare<_Key, _CP, _Compare, __b>& __x,
588 __map_value_compare<_Key, _CP, _Compare, __b>& __y)
589 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
590{
591 __x.swap(__y);
592}
593
Howard Hinnantc51e1022010-05-11 19:42:16 +0000594template <class _Allocator>
595class __map_node_destructor
596{
597 typedef _Allocator allocator_type;
598 typedef allocator_traits<allocator_type> __alloc_traits;
Eric Fiseliera00b4842016-02-20 05:28:30 +0000599
Howard Hinnantc51e1022010-05-11 19:42:16 +0000600public:
601 typedef typename __alloc_traits::pointer pointer;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000602
Eric Fiseliera00b4842016-02-20 05:28:30 +0000603private:
Howard Hinnantc51e1022010-05-11 19:42:16 +0000604 allocator_type& __na_;
605
606 __map_node_destructor& operator=(const __map_node_destructor&);
607
608public:
609 bool __first_constructed;
610 bool __second_constructed;
611
Howard Hinnant756c69b2010-09-22 16:48:34 +0000612 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000613 explicit __map_node_destructor(allocator_type& __na) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +0000614 : __na_(__na),
615 __first_constructed(false),
616 __second_constructed(false)
617 {}
618
Eric Fiseliera85b1282017-04-18 21:08:06 +0000619#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant756c69b2010-09-22 16:48:34 +0000620 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000621 __map_node_destructor(__tree_node_destructor<allocator_type>&& __x) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +0000622 : __na_(__x.__na_),
623 __first_constructed(__x.__value_constructed),
624 __second_constructed(__x.__value_constructed)
625 {
626 __x.__value_constructed = false;
627 }
Eric Fiseliera85b1282017-04-18 21:08:06 +0000628#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000629
Howard Hinnant756c69b2010-09-22 16:48:34 +0000630 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000631 void operator()(pointer __p) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +0000632 {
633 if (__second_constructed)
Erik Pilkingtond3fe2992018-06-04 20:38:23 +0000634 __alloc_traits::destroy(__na_, _VSTD::addressof(__p->__value_.__get_value().second));
Howard Hinnantc51e1022010-05-11 19:42:16 +0000635 if (__first_constructed)
Erik Pilkingtond3fe2992018-06-04 20:38:23 +0000636 __alloc_traits::destroy(__na_, _VSTD::addressof(__p->__value_.__get_value().first));
Howard Hinnantc51e1022010-05-11 19:42:16 +0000637 if (__p)
638 __alloc_traits::deallocate(__na_, __p, 1);
639 }
640};
641
Howard Hinnant944510a2011-06-14 19:58:17 +0000642template <class _Key, class _Tp, class _Compare, class _Allocator>
643 class map;
644template <class _Key, class _Tp, class _Compare, class _Allocator>
645 class multimap;
646template <class _TreeIterator> class __map_const_iterator;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000647
Eric Fiseliera00b4842016-02-20 05:28:30 +0000648#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant89f8b792013-09-30 19:08:22 +0000649
650template <class _Key, class _Tp>
Erik Pilkingtond3fe2992018-06-04 20:38:23 +0000651struct __value_type
Howard Hinnant89f8b792013-09-30 19:08:22 +0000652{
653 typedef _Key key_type;
654 typedef _Tp mapped_type;
655 typedef pair<const key_type, mapped_type> value_type;
Erik Pilkingtond3fe2992018-06-04 20:38:23 +0000656 typedef pair<key_type&, mapped_type&> __nc_ref_pair_type;
657 typedef pair<key_type&&, mapped_type&&> __nc_rref_pair_type;
Howard Hinnant89f8b792013-09-30 19:08:22 +0000658
Erik Pilkingtond3fe2992018-06-04 20:38:23 +0000659private:
Howard Hinnant89f8b792013-09-30 19:08:22 +0000660 value_type __cc;
Erik Pilkingtond3fe2992018-06-04 20:38:23 +0000661
662public:
663 _LIBCPP_INLINE_VISIBILITY
664 value_type& __get_value()
665 {
666#if _LIBCPP_STD_VER > 14
667 return *_VSTD::launder(_VSTD::addressof(__cc));
668#else
669 return __cc;
670#endif
671 }
672
673 _LIBCPP_INLINE_VISIBILITY
674 const value_type& __get_value() const
675 {
676#if _LIBCPP_STD_VER > 14
677 return *_VSTD::launder(_VSTD::addressof(__cc));
678#else
679 return __cc;
680#endif
681 }
682
683 _LIBCPP_INLINE_VISIBILITY
684 __nc_ref_pair_type __ref()
685 {
686 value_type& __v = __get_value();
687 return __nc_ref_pair_type(const_cast<key_type&>(__v.first), __v.second);
688 }
689
690 _LIBCPP_INLINE_VISIBILITY
691 __nc_rref_pair_type __move()
692 {
693 value_type& __v = __get_value();
694 return __nc_rref_pair_type(
695 _VSTD::move(const_cast<key_type&>(__v.first)),
696 _VSTD::move(__v.second));
697 }
Howard Hinnant89f8b792013-09-30 19:08:22 +0000698
Howard Hinnant89f8b792013-09-30 19:08:22 +0000699 _LIBCPP_INLINE_VISIBILITY
700 __value_type& operator=(const __value_type& __v)
Erik Pilkingtond3fe2992018-06-04 20:38:23 +0000701 {
702 __ref() = __v.__get_value();
703 return *this;
704 }
Howard Hinnant89f8b792013-09-30 19:08:22 +0000705
706 _LIBCPP_INLINE_VISIBILITY
707 __value_type& operator=(__value_type&& __v)
Erik Pilkingtond3fe2992018-06-04 20:38:23 +0000708 {
709 __ref() = __v.__move();
710 return *this;
711 }
Howard Hinnant89f8b792013-09-30 19:08:22 +0000712
Eric Fiselierd06276b2016-03-31 02:15:15 +0000713 template <class _ValueTp,
714 class = typename enable_if<
715 __is_same_uncvref<_ValueTp, value_type>::value
716 >::type
717 >
Howard Hinnant89f8b792013-09-30 19:08:22 +0000718 _LIBCPP_INLINE_VISIBILITY
Erik Pilkingtond3fe2992018-06-04 20:38:23 +0000719 __value_type& operator=(_ValueTp&& __v)
720 {
721 __ref() = _VSTD::forward<_ValueTp>(__v);
722 return *this;
Eric Fiselierd06276b2016-03-31 02:15:15 +0000723 }
724
725private:
726 __value_type() _LIBCPP_EQUAL_DELETE;
727 ~__value_type() _LIBCPP_EQUAL_DELETE;
728 __value_type(const __value_type& __v) _LIBCPP_EQUAL_DELETE;
729 __value_type(__value_type&& __v) _LIBCPP_EQUAL_DELETE;
Howard Hinnant89f8b792013-09-30 19:08:22 +0000730};
731
732#else
733
734template <class _Key, class _Tp>
735struct __value_type
736{
737 typedef _Key key_type;
738 typedef _Tp mapped_type;
739 typedef pair<const key_type, mapped_type> value_type;
740
Erik Pilkingtond3fe2992018-06-04 20:38:23 +0000741private:
Howard Hinnant89f8b792013-09-30 19:08:22 +0000742 value_type __cc;
743
Erik Pilkingtond3fe2992018-06-04 20:38:23 +0000744public:
745 _LIBCPP_INLINE_VISIBILITY
746 value_type& __get_value() { return __cc; }
747 _LIBCPP_INLINE_VISIBILITY
748 const value_type& __get_value() const { return __cc; }
749
Eric Fiselierd06276b2016-03-31 02:15:15 +0000750private:
751 __value_type();
752 __value_type(__value_type const&);
753 __value_type& operator=(__value_type const&);
754 ~__value_type();
Howard Hinnant89f8b792013-09-30 19:08:22 +0000755};
756
Eric Fiseliera85b1282017-04-18 21:08:06 +0000757#endif // _LIBCPP_CXX03_LANG
Howard Hinnant89f8b792013-09-30 19:08:22 +0000758
Eric Fiselier44f9fd02015-03-03 20:10:01 +0000759template <class _Tp>
760struct __extract_key_value_types;
761
762template <class _Key, class _Tp>
763struct __extract_key_value_types<__value_type<_Key, _Tp> >
764{
765 typedef _Key const __key_type;
766 typedef _Tp __mapped_type;
767};
768
Howard Hinnantc51e1022010-05-11 19:42:16 +0000769template <class _TreeIterator>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000770class _LIBCPP_TEMPLATE_VIS __map_iterator
Howard Hinnantc51e1022010-05-11 19:42:16 +0000771{
Eric Fiseliera00b4842016-02-20 05:28:30 +0000772 typedef typename _TreeIterator::_NodeTypes _NodeTypes;
773 typedef typename _TreeIterator::__pointer_traits __pointer_traits;
774
Howard Hinnantc51e1022010-05-11 19:42:16 +0000775 _TreeIterator __i_;
776
Howard Hinnantc51e1022010-05-11 19:42:16 +0000777public:
778 typedef bidirectional_iterator_tag iterator_category;
Eric Fiseliera00b4842016-02-20 05:28:30 +0000779 typedef typename _NodeTypes::__map_value_type value_type;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000780 typedef typename _TreeIterator::difference_type difference_type;
781 typedef value_type& reference;
Eric Fiseliera00b4842016-02-20 05:28:30 +0000782 typedef typename _NodeTypes::__map_value_type_pointer pointer;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000783
Howard Hinnant756c69b2010-09-22 16:48:34 +0000784 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000785 __map_iterator() _NOEXCEPT {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000786
Howard Hinnant756c69b2010-09-22 16:48:34 +0000787 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000788 __map_iterator(_TreeIterator __i) _NOEXCEPT : __i_(__i) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000789
Howard Hinnant756c69b2010-09-22 16:48:34 +0000790 _LIBCPP_INLINE_VISIBILITY
Erik Pilkingtond3fe2992018-06-04 20:38:23 +0000791 reference operator*() const {return __i_->__get_value();}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000792 _LIBCPP_INLINE_VISIBILITY
Erik Pilkingtond3fe2992018-06-04 20:38:23 +0000793 pointer operator->() const {return pointer_traits<pointer>::pointer_to(__i_->__get_value());}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000794
Howard Hinnant756c69b2010-09-22 16:48:34 +0000795 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000796 __map_iterator& operator++() {++__i_; return *this;}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000797 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000798 __map_iterator operator++(int)
799 {
800 __map_iterator __t(*this);
801 ++(*this);
802 return __t;
803 }
804
Howard Hinnant756c69b2010-09-22 16:48:34 +0000805 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000806 __map_iterator& operator--() {--__i_; return *this;}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000807 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000808 __map_iterator operator--(int)
809 {
810 __map_iterator __t(*this);
811 --(*this);
812 return __t;
813 }
814
Howard Hinnant756c69b2010-09-22 16:48:34 +0000815 friend _LIBCPP_INLINE_VISIBILITY
816 bool operator==(const __map_iterator& __x, const __map_iterator& __y)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000817 {return __x.__i_ == __y.__i_;}
Eric Fiseliercf8c0212017-01-05 06:06:18 +0000818 friend
Howard Hinnant756c69b2010-09-22 16:48:34 +0000819 _LIBCPP_INLINE_VISIBILITY
820 bool operator!=(const __map_iterator& __x, const __map_iterator& __y)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000821 {return __x.__i_ != __y.__i_;}
822
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000823 template <class, class, class, class> friend class _LIBCPP_TEMPLATE_VIS map;
824 template <class, class, class, class> friend class _LIBCPP_TEMPLATE_VIS multimap;
825 template <class> friend class _LIBCPP_TEMPLATE_VIS __map_const_iterator;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000826};
827
828template <class _TreeIterator>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000829class _LIBCPP_TEMPLATE_VIS __map_const_iterator
Howard Hinnantc51e1022010-05-11 19:42:16 +0000830{
Eric Fiseliera00b4842016-02-20 05:28:30 +0000831 typedef typename _TreeIterator::_NodeTypes _NodeTypes;
832 typedef typename _TreeIterator::__pointer_traits __pointer_traits;
833
Howard Hinnantc51e1022010-05-11 19:42:16 +0000834 _TreeIterator __i_;
835
Howard Hinnantc51e1022010-05-11 19:42:16 +0000836public:
837 typedef bidirectional_iterator_tag iterator_category;
Eric Fiseliera00b4842016-02-20 05:28:30 +0000838 typedef typename _NodeTypes::__map_value_type value_type;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000839 typedef typename _TreeIterator::difference_type difference_type;
840 typedef const value_type& reference;
Eric Fiseliera00b4842016-02-20 05:28:30 +0000841 typedef typename _NodeTypes::__const_map_value_type_pointer pointer;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000842
Howard Hinnant756c69b2010-09-22 16:48:34 +0000843 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000844 __map_const_iterator() _NOEXCEPT {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000845
Howard Hinnant756c69b2010-09-22 16:48:34 +0000846 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000847 __map_const_iterator(_TreeIterator __i) _NOEXCEPT : __i_(__i) {}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000848 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier44f9fd02015-03-03 20:10:01 +0000849 __map_const_iterator(__map_iterator<
850 typename _TreeIterator::__non_const_iterator> __i) _NOEXCEPT
851 : __i_(__i.__i_) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000852
Howard Hinnant756c69b2010-09-22 16:48:34 +0000853 _LIBCPP_INLINE_VISIBILITY
Erik Pilkingtond3fe2992018-06-04 20:38:23 +0000854 reference operator*() const {return __i_->__get_value();}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000855 _LIBCPP_INLINE_VISIBILITY
Erik Pilkingtond3fe2992018-06-04 20:38:23 +0000856 pointer operator->() const {return pointer_traits<pointer>::pointer_to(__i_->__get_value());}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000857
Howard Hinnant756c69b2010-09-22 16:48:34 +0000858 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000859 __map_const_iterator& operator++() {++__i_; return *this;}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000860 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000861 __map_const_iterator operator++(int)
862 {
863 __map_const_iterator __t(*this);
864 ++(*this);
865 return __t;
866 }
867
Howard Hinnant756c69b2010-09-22 16:48:34 +0000868 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000869 __map_const_iterator& operator--() {--__i_; return *this;}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000870 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000871 __map_const_iterator operator--(int)
872 {
873 __map_const_iterator __t(*this);
874 --(*this);
875 return __t;
876 }
877
Howard Hinnant756c69b2010-09-22 16:48:34 +0000878 friend _LIBCPP_INLINE_VISIBILITY
879 bool operator==(const __map_const_iterator& __x, const __map_const_iterator& __y)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000880 {return __x.__i_ == __y.__i_;}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000881 friend _LIBCPP_INLINE_VISIBILITY
882 bool operator!=(const __map_const_iterator& __x, const __map_const_iterator& __y)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000883 {return __x.__i_ != __y.__i_;}
884
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000885 template <class, class, class, class> friend class _LIBCPP_TEMPLATE_VIS map;
886 template <class, class, class, class> friend class _LIBCPP_TEMPLATE_VIS multimap;
887 template <class, class, class> friend class _LIBCPP_TEMPLATE_VIS __tree_const_iterator;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000888};
889
890template <class _Key, class _Tp, class _Compare = less<_Key>,
891 class _Allocator = allocator<pair<const _Key, _Tp> > >
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000892class _LIBCPP_TEMPLATE_VIS map
Howard Hinnantc51e1022010-05-11 19:42:16 +0000893{
894public:
895 // types:
896 typedef _Key key_type;
897 typedef _Tp mapped_type;
898 typedef pair<const key_type, mapped_type> value_type;
899 typedef _Compare key_compare;
900 typedef _Allocator allocator_type;
901 typedef value_type& reference;
902 typedef const value_type& const_reference;
903
Louis Dionne878a3a82018-12-06 21:46:17 +0000904 static_assert(sizeof(__diagnose_non_const_comparator<_Key, _Compare>()), "");
Marshall Clow5128cf32015-11-26 01:24:04 +0000905 static_assert((is_same<typename allocator_type::value_type, value_type>::value),
906 "Allocator::value_type must be same type as value_type");
907
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000908 class _LIBCPP_TEMPLATE_VIS value_compare
Howard Hinnantc51e1022010-05-11 19:42:16 +0000909 : public binary_function<value_type, value_type, bool>
910 {
911 friend class map;
912 protected:
913 key_compare comp;
914
Howard Hinnant756c69b2010-09-22 16:48:34 +0000915 _LIBCPP_INLINE_VISIBILITY value_compare(key_compare c) : comp(c) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000916 public:
Howard Hinnant756c69b2010-09-22 16:48:34 +0000917 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000918 bool operator()(const value_type& __x, const value_type& __y) const
919 {return comp(__x.first, __y.first);}
920 };
921
922private:
Howard Hinnant2d0046b2013-06-19 21:29:40 +0000923
Howard Hinnant89f8b792013-09-30 19:08:22 +0000924 typedef _VSTD::__value_type<key_type, mapped_type> __value_type;
Howard Hinnant90b91592013-07-05 18:06:00 +0000925 typedef __map_value_compare<key_type, __value_type, key_compare> __vc;
Marshall Clow940e01c2015-04-07 05:21:38 +0000926 typedef typename __rebind_alloc_helper<allocator_traits<allocator_type>,
927 __value_type>::type __allocator_type;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000928 typedef __tree<__value_type, __vc, __allocator_type> __base;
929 typedef typename __base::__node_traits __node_traits;
930 typedef allocator_traits<allocator_type> __alloc_traits;
931
932 __base __tree_;
933
934public:
935 typedef typename __alloc_traits::pointer pointer;
936 typedef typename __alloc_traits::const_pointer const_pointer;
937 typedef typename __alloc_traits::size_type size_type;
938 typedef typename __alloc_traits::difference_type difference_type;
Eric Fiselier44f9fd02015-03-03 20:10:01 +0000939 typedef __map_iterator<typename __base::iterator> iterator;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000940 typedef __map_const_iterator<typename __base::const_iterator> const_iterator;
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000941 typedef _VSTD::reverse_iterator<iterator> reverse_iterator;
942 typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000943
Erik Pilkingtonc37a3d82018-08-01 01:33:38 +0000944#if _LIBCPP_STD_VER > 14
945 typedef __map_node_handle<typename __base::__node, allocator_type> node_type;
946 typedef __insert_return_type<iterator, node_type> insert_return_type;
947#endif
948
Erik Pilkington82a65ad2018-10-31 17:31:35 +0000949 template <class _Key2, class _Value2, class _Comp2, class _Alloc2>
950 friend class _LIBCPP_TEMPLATE_VIS map;
951 template <class _Key2, class _Value2, class _Comp2, class _Alloc2>
952 friend class _LIBCPP_TEMPLATE_VIS multimap;
953
Howard Hinnant756c69b2010-09-22 16:48:34 +0000954 _LIBCPP_INLINE_VISIBILITY
Marshall Clow7086a5a2014-03-10 04:50:10 +0000955 map()
956 _NOEXCEPT_(
957 is_nothrow_default_constructible<allocator_type>::value &&
958 is_nothrow_default_constructible<key_compare>::value &&
959 is_nothrow_copy_constructible<key_compare>::value)
960 : __tree_(__vc(key_compare())) {}
961
962 _LIBCPP_INLINE_VISIBILITY
963 explicit map(const key_compare& __comp)
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000964 _NOEXCEPT_(
965 is_nothrow_default_constructible<allocator_type>::value &&
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000966 is_nothrow_copy_constructible<key_compare>::value)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000967 : __tree_(__vc(__comp)) {}
968
Howard Hinnant756c69b2010-09-22 16:48:34 +0000969 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000970 explicit map(const key_compare& __comp, const allocator_type& __a)
Marshall Clow657cbc42016-08-17 05:58:40 +0000971 : __tree_(__vc(__comp), typename __base::allocator_type(__a)) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000972
973 template <class _InputIterator>
Howard Hinnant756c69b2010-09-22 16:48:34 +0000974 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000975 map(_InputIterator __f, _InputIterator __l,
976 const key_compare& __comp = key_compare())
977 : __tree_(__vc(__comp))
978 {
979 insert(__f, __l);
980 }
981
982 template <class _InputIterator>
Howard Hinnant756c69b2010-09-22 16:48:34 +0000983 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000984 map(_InputIterator __f, _InputIterator __l,
985 const key_compare& __comp, const allocator_type& __a)
Marshall Clow657cbc42016-08-17 05:58:40 +0000986 : __tree_(__vc(__comp), typename __base::allocator_type(__a))
Howard Hinnantc51e1022010-05-11 19:42:16 +0000987 {
988 insert(__f, __l);
989 }
990
Marshall Clow300abfb2013-09-11 01:15:47 +0000991#if _LIBCPP_STD_VER > 11
992 template <class _InputIterator>
Eric Fiseliercf8c0212017-01-05 06:06:18 +0000993 _LIBCPP_INLINE_VISIBILITY
Marshall Clow300abfb2013-09-11 01:15:47 +0000994 map(_InputIterator __f, _InputIterator __l, const allocator_type& __a)
995 : map(__f, __l, key_compare(), __a) {}
996#endif
997
Howard Hinnant756c69b2010-09-22 16:48:34 +0000998 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000999 map(const map& __m)
1000 : __tree_(__m.__tree_)
1001 {
1002 insert(__m.begin(), __m.end());
1003 }
1004
Howard Hinnantd3a657f2011-07-01 19:24:36 +00001005 _LIBCPP_INLINE_VISIBILITY
1006 map& operator=(const map& __m)
1007 {
Marshall Clow476d3f42016-07-18 13:19:00 +00001008#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantd3a657f2011-07-01 19:24:36 +00001009 __tree_ = __m.__tree_;
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001010#else
Marshall Clowdb3cfcb2014-02-08 04:03:14 +00001011 if (this != &__m) {
1012 __tree_.clear();
1013 __tree_.value_comp() = __m.__tree_.value_comp();
1014 __tree_.__copy_assign_alloc(__m.__tree_);
1015 insert(__m.begin(), __m.end());
1016 }
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001017#endif
Howard Hinnantd3a657f2011-07-01 19:24:36 +00001018 return *this;
1019 }
1020
Eric Fiseliera85b1282017-04-18 21:08:06 +00001021#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001022
Howard Hinnant756c69b2010-09-22 16:48:34 +00001023 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001024 map(map&& __m)
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001025 _NOEXCEPT_(is_nothrow_move_constructible<__base>::value)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001026 : __tree_(_VSTD::move(__m.__tree_))
Howard Hinnantc51e1022010-05-11 19:42:16 +00001027 {
1028 }
1029
1030 map(map&& __m, const allocator_type& __a);
1031
Howard Hinnant756c69b2010-09-22 16:48:34 +00001032 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant33711792011-08-12 21:56:02 +00001033 map& operator=(map&& __m)
1034 _NOEXCEPT_(is_nothrow_move_assignable<__base>::value)
1035 {
1036 __tree_ = _VSTD::move(__m.__tree_);
1037 return *this;
1038 }
1039
Howard Hinnant33711792011-08-12 21:56:02 +00001040 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001041 map(initializer_list<value_type> __il, const key_compare& __comp = key_compare())
1042 : __tree_(__vc(__comp))
1043 {
1044 insert(__il.begin(), __il.end());
1045 }
1046
Howard Hinnant756c69b2010-09-22 16:48:34 +00001047 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001048 map(initializer_list<value_type> __il, const key_compare& __comp, const allocator_type& __a)
Marshall Clow657cbc42016-08-17 05:58:40 +00001049 : __tree_(__vc(__comp), typename __base::allocator_type(__a))
Howard Hinnantc51e1022010-05-11 19:42:16 +00001050 {
1051 insert(__il.begin(), __il.end());
1052 }
1053
Marshall Clow300abfb2013-09-11 01:15:47 +00001054#if _LIBCPP_STD_VER > 11
Eric Fiseliercf8c0212017-01-05 06:06:18 +00001055 _LIBCPP_INLINE_VISIBILITY
Marshall Clow300abfb2013-09-11 01:15:47 +00001056 map(initializer_list<value_type> __il, const allocator_type& __a)
1057 : map(__il, key_compare(), __a) {}
1058#endif
1059
Howard Hinnant756c69b2010-09-22 16:48:34 +00001060 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001061 map& operator=(initializer_list<value_type> __il)
1062 {
1063 __tree_.__assign_unique(__il.begin(), __il.end());
1064 return *this;
1065 }
1066
Eric Fiseliera85b1282017-04-18 21:08:06 +00001067#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001068
Howard Hinnant756c69b2010-09-22 16:48:34 +00001069 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001070 explicit map(const allocator_type& __a)
Marshall Clow657cbc42016-08-17 05:58:40 +00001071 : __tree_(typename __base::allocator_type(__a))
Howard Hinnantc51e1022010-05-11 19:42:16 +00001072 {
1073 }
1074
Howard Hinnant756c69b2010-09-22 16:48:34 +00001075 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001076 map(const map& __m, const allocator_type& __a)
Marshall Clow657cbc42016-08-17 05:58:40 +00001077 : __tree_(__m.__tree_.value_comp(), typename __base::allocator_type(__a))
Howard Hinnantc51e1022010-05-11 19:42:16 +00001078 {
1079 insert(__m.begin(), __m.end());
1080 }
1081
Howard Hinnant756c69b2010-09-22 16:48:34 +00001082 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001083 iterator begin() _NOEXCEPT {return __tree_.begin();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001084 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001085 const_iterator begin() const _NOEXCEPT {return __tree_.begin();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001086 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001087 iterator end() _NOEXCEPT {return __tree_.end();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001088 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001089 const_iterator end() const _NOEXCEPT {return __tree_.end();}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001090
Howard Hinnant756c69b2010-09-22 16:48:34 +00001091 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001092 reverse_iterator rbegin() _NOEXCEPT {return reverse_iterator(end());}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001093 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001094 const_reverse_iterator rbegin() const _NOEXCEPT
1095 {return const_reverse_iterator(end());}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001096 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001097 reverse_iterator rend() _NOEXCEPT
1098 {return reverse_iterator(begin());}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001099 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001100 const_reverse_iterator rend() const _NOEXCEPT
1101 {return const_reverse_iterator(begin());}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001102
Howard Hinnant756c69b2010-09-22 16:48:34 +00001103 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001104 const_iterator cbegin() const _NOEXCEPT {return begin();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001105 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001106 const_iterator cend() const _NOEXCEPT {return end();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001107 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001108 const_reverse_iterator crbegin() const _NOEXCEPT {return rbegin();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001109 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001110 const_reverse_iterator crend() const _NOEXCEPT {return rend();}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001111
Marshall Clow425f5752017-11-15 05:51:26 +00001112 _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001113 bool empty() const _NOEXCEPT {return __tree_.size() == 0;}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001114 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001115 size_type size() const _NOEXCEPT {return __tree_.size();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001116 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001117 size_type max_size() const _NOEXCEPT {return __tree_.max_size();}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001118
1119 mapped_type& operator[](const key_type& __k);
Eric Fiselierd63f38e2016-03-31 03:13:37 +00001120#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001121 mapped_type& operator[](key_type&& __k);
1122#endif
1123
1124 mapped_type& at(const key_type& __k);
1125 const mapped_type& at(const key_type& __k) const;
1126
Howard Hinnant756c69b2010-09-22 16:48:34 +00001127 _LIBCPP_INLINE_VISIBILITY
Marshall Clow657cbc42016-08-17 05:58:40 +00001128 allocator_type get_allocator() const _NOEXCEPT {return allocator_type(__tree_.__alloc());}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001129 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001130 key_compare key_comp() const {return __tree_.value_comp().key_comp();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001131 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001132 value_compare value_comp() const {return value_compare(__tree_.value_comp().key_comp());}
1133
Eric Fiselierd06276b2016-03-31 02:15:15 +00001134#ifndef _LIBCPP_CXX03_LANG
1135 template <class ..._Args>
1136 _LIBCPP_INLINE_VISIBILITY
1137 pair<iterator, bool> emplace(_Args&& ...__args) {
1138 return __tree_.__emplace_unique(_VSTD::forward<_Args>(__args)...);
1139 }
Howard Hinnant74279a52010-09-04 23:28:19 +00001140
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001141 template <class ..._Args>
Eric Fiselierd06276b2016-03-31 02:15:15 +00001142 _LIBCPP_INLINE_VISIBILITY
1143 iterator emplace_hint(const_iterator __p, _Args&& ...__args) {
1144 return __tree_.__emplace_hint_unique(__p.__i_, _VSTD::forward<_Args>(__args)...);
1145 }
Howard Hinnant74279a52010-09-04 23:28:19 +00001146
Howard Hinnantc834c512011-11-29 18:15:50 +00001147 template <class _Pp,
1148 class = typename enable_if<is_constructible<value_type, _Pp>::value>::type>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001149 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc834c512011-11-29 18:15:50 +00001150 pair<iterator, bool> insert(_Pp&& __p)
1151 {return __tree_.__insert_unique(_VSTD::forward<_Pp>(__p));}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001152
Howard Hinnantc834c512011-11-29 18:15:50 +00001153 template <class _Pp,
1154 class = typename enable_if<is_constructible<value_type, _Pp>::value>::type>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001155 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc834c512011-11-29 18:15:50 +00001156 iterator insert(const_iterator __pos, _Pp&& __p)
1157 {return __tree_.__insert_unique(__pos.__i_, _VSTD::forward<_Pp>(__p));}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001158
Eric Fiselierd06276b2016-03-31 02:15:15 +00001159#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001160
Howard Hinnant756c69b2010-09-22 16:48:34 +00001161 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001162 pair<iterator, bool>
1163 insert(const value_type& __v) {return __tree_.__insert_unique(__v);}
1164
Howard Hinnant756c69b2010-09-22 16:48:34 +00001165 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001166 iterator
1167 insert(const_iterator __p, const value_type& __v)
1168 {return __tree_.__insert_unique(__p.__i_, __v);}
1169
Eric Fiselierd6143132016-04-18 01:40:45 +00001170#ifndef _LIBCPP_CXX03_LANG
Marshall Clowd430d022016-01-05 19:32:41 +00001171 _LIBCPP_INLINE_VISIBILITY
1172 pair<iterator, bool>
Eric Fiselierd06276b2016-03-31 02:15:15 +00001173 insert(value_type&& __v) {return __tree_.__insert_unique(_VSTD::move(__v));}
Marshall Clowd430d022016-01-05 19:32:41 +00001174
1175 _LIBCPP_INLINE_VISIBILITY
Eric Fiselierd06276b2016-03-31 02:15:15 +00001176 iterator insert(const_iterator __p, value_type&& __v)
1177 {return __tree_.__insert_unique(__p.__i_, _VSTD::move(__v));}
Eric Fiseliera85b1282017-04-18 21:08:06 +00001178
1179 _LIBCPP_INLINE_VISIBILITY
1180 void insert(initializer_list<value_type> __il)
1181 {insert(__il.begin(), __il.end());}
Marshall Clowd430d022016-01-05 19:32:41 +00001182#endif
1183
Howard Hinnantc51e1022010-05-11 19:42:16 +00001184 template <class _InputIterator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001185 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001186 void insert(_InputIterator __f, _InputIterator __l)
1187 {
1188 for (const_iterator __e = cend(); __f != __l; ++__f)
1189 insert(__e.__i_, *__f);
1190 }
1191
Marshall Clow3223db82015-07-07 03:37:33 +00001192#if _LIBCPP_STD_VER > 14
Eric Fiselierd63f38e2016-03-31 03:13:37 +00001193
Marshall Clow3223db82015-07-07 03:37:33 +00001194 template <class... _Args>
1195 _LIBCPP_INLINE_VISIBILITY
1196 pair<iterator, bool> try_emplace(const key_type& __k, _Args&&... __args)
1197 {
Eric Fiselierd63f38e2016-03-31 03:13:37 +00001198 return __tree_.__emplace_unique_key_args(__k,
1199 _VSTD::piecewise_construct,
1200 _VSTD::forward_as_tuple(__k),
1201 _VSTD::forward_as_tuple(_VSTD::forward<_Args>(__args)...));
Marshall Clow3223db82015-07-07 03:37:33 +00001202 }
1203
1204 template <class... _Args>
1205 _LIBCPP_INLINE_VISIBILITY
1206 pair<iterator, bool> try_emplace(key_type&& __k, _Args&&... __args)
1207 {
Eric Fiselierd63f38e2016-03-31 03:13:37 +00001208 return __tree_.__emplace_unique_key_args(__k,
1209 _VSTD::piecewise_construct,
1210 _VSTD::forward_as_tuple(_VSTD::move(__k)),
1211 _VSTD::forward_as_tuple(_VSTD::forward<_Args>(__args)...));
Marshall Clow3223db82015-07-07 03:37:33 +00001212 }
1213
1214 template <class... _Args>
1215 _LIBCPP_INLINE_VISIBILITY
1216 iterator try_emplace(const_iterator __h, const key_type& __k, _Args&&... __args)
1217 {
Eric Fiselierd63f38e2016-03-31 03:13:37 +00001218 return __tree_.__emplace_hint_unique_key_args(__h.__i_, __k,
1219 _VSTD::piecewise_construct,
1220 _VSTD::forward_as_tuple(__k),
1221 _VSTD::forward_as_tuple(_VSTD::forward<_Args>(__args)...));
Marshall Clow3223db82015-07-07 03:37:33 +00001222 }
1223
1224 template <class... _Args>
1225 _LIBCPP_INLINE_VISIBILITY
1226 iterator try_emplace(const_iterator __h, key_type&& __k, _Args&&... __args)
1227 {
Eric Fiselierd63f38e2016-03-31 03:13:37 +00001228 return __tree_.__emplace_hint_unique_key_args(__h.__i_, __k,
1229 _VSTD::piecewise_construct,
1230 _VSTD::forward_as_tuple(_VSTD::move(__k)),
1231 _VSTD::forward_as_tuple(_VSTD::forward<_Args>(__args)...));
Marshall Clow3223db82015-07-07 03:37:33 +00001232 }
1233
1234 template <class _Vp>
1235 _LIBCPP_INLINE_VISIBILITY
1236 pair<iterator, bool> insert_or_assign(const key_type& __k, _Vp&& __v)
1237 {
1238 iterator __p = lower_bound(__k);
1239 if ( __p != end() && !key_comp()(__k, __p->first))
1240 {
1241 __p->second = _VSTD::forward<_Vp>(__v);
1242 return _VSTD::make_pair(__p, false);
1243 }
1244 return _VSTD::make_pair(emplace_hint(__p, __k, _VSTD::forward<_Vp>(__v)), true);
1245 }
Eric Fiselierd63f38e2016-03-31 03:13:37 +00001246
Marshall Clow3223db82015-07-07 03:37:33 +00001247 template <class _Vp>
1248 _LIBCPP_INLINE_VISIBILITY
1249 pair<iterator, bool> insert_or_assign(key_type&& __k, _Vp&& __v)
1250 {
1251 iterator __p = lower_bound(__k);
1252 if ( __p != end() && !key_comp()(__k, __p->first))
1253 {
1254 __p->second = _VSTD::forward<_Vp>(__v);
1255 return _VSTD::make_pair(__p, false);
1256 }
1257 return _VSTD::make_pair(emplace_hint(__p, _VSTD::move(__k), _VSTD::forward<_Vp>(__v)), true);
1258 }
1259
1260 template <class _Vp>
1261 _LIBCPP_INLINE_VISIBILITY
1262 iterator insert_or_assign(const_iterator __h, const key_type& __k, _Vp&& __v)
1263 {
1264 iterator __p = lower_bound(__k);
1265 if ( __p != end() && !key_comp()(__k, __p->first))
1266 {
1267 __p->second = _VSTD::forward<_Vp>(__v);
1268 return __p;
1269 }
1270 return emplace_hint(__h, __k, _VSTD::forward<_Vp>(__v));
1271 }
1272
1273 template <class _Vp>
1274 _LIBCPP_INLINE_VISIBILITY
1275 iterator insert_or_assign(const_iterator __h, key_type&& __k, _Vp&& __v)
1276 {
1277 iterator __p = lower_bound(__k);
1278 if ( __p != end() && !key_comp()(__k, __p->first))
1279 {
1280 __p->second = _VSTD::forward<_Vp>(__v);
1281 return __p;
1282 }
1283 return emplace_hint(__h, _VSTD::move(__k), _VSTD::forward<_Vp>(__v));
1284 }
Eric Fiselierd63f38e2016-03-31 03:13:37 +00001285
Eric Fiseliera85b1282017-04-18 21:08:06 +00001286#endif // _LIBCPP_STD_VER > 14
Marshall Clow3223db82015-07-07 03:37:33 +00001287
Howard Hinnant756c69b2010-09-22 16:48:34 +00001288 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001289 iterator erase(const_iterator __p) {return __tree_.erase(__p.__i_);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001290 _LIBCPP_INLINE_VISIBILITY
Marshall Clow22ea5b82015-05-10 13:35:00 +00001291 iterator erase(iterator __p) {return __tree_.erase(__p.__i_);}
1292 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001293 size_type erase(const key_type& __k)
1294 {return __tree_.__erase_unique(__k);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001295 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001296 iterator erase(const_iterator __f, const_iterator __l)
1297 {return __tree_.erase(__f.__i_, __l.__i_);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001298 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001299 void clear() _NOEXCEPT {__tree_.clear();}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001300
Erik Pilkingtonc37a3d82018-08-01 01:33:38 +00001301#if _LIBCPP_STD_VER > 14
1302 _LIBCPP_INLINE_VISIBILITY
1303 insert_return_type insert(node_type&& __nh)
1304 {
1305 _LIBCPP_ASSERT(__nh.empty() || __nh.get_allocator() == get_allocator(),
1306 "node_type with incompatible allocator passed to map::insert()");
1307 return __tree_.template __node_handle_insert_unique<
1308 node_type, insert_return_type>(_VSTD::move(__nh));
1309 }
1310 _LIBCPP_INLINE_VISIBILITY
1311 iterator insert(const_iterator __hint, node_type&& __nh)
1312 {
1313 _LIBCPP_ASSERT(__nh.empty() || __nh.get_allocator() == get_allocator(),
1314 "node_type with incompatible allocator passed to map::insert()");
1315 return __tree_.template __node_handle_insert_unique<node_type>(
1316 __hint.__i_, _VSTD::move(__nh));
1317 }
1318 _LIBCPP_INLINE_VISIBILITY
1319 node_type extract(key_type const& __key)
1320 {
1321 return __tree_.template __node_handle_extract<node_type>(__key);
1322 }
1323 _LIBCPP_INLINE_VISIBILITY
1324 node_type extract(const_iterator __it)
1325 {
1326 return __tree_.template __node_handle_extract<node_type>(__it.__i_);
1327 }
Louis Dionned2322c82018-11-01 14:41:37 +00001328 template <class _Compare2>
Erik Pilkington82a65ad2018-10-31 17:31:35 +00001329 _LIBCPP_INLINE_VISIBILITY
Louis Dionned2322c82018-11-01 14:41:37 +00001330 void merge(map<key_type, mapped_type, _Compare2, allocator_type>& __source)
Erik Pilkington82a65ad2018-10-31 17:31:35 +00001331 {
1332 _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
1333 "merging container with incompatible allocator");
1334 __tree_.__node_handle_merge_unique(__source.__tree_);
1335 }
Louis Dionned2322c82018-11-01 14:41:37 +00001336 template <class _Compare2>
Erik Pilkington82a65ad2018-10-31 17:31:35 +00001337 _LIBCPP_INLINE_VISIBILITY
Louis Dionned2322c82018-11-01 14:41:37 +00001338 void merge(map<key_type, mapped_type, _Compare2, allocator_type>&& __source)
Erik Pilkington82a65ad2018-10-31 17:31:35 +00001339 {
1340 _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
1341 "merging container with incompatible allocator");
1342 __tree_.__node_handle_merge_unique(__source.__tree_);
1343 }
Louis Dionned2322c82018-11-01 14:41:37 +00001344 template <class _Compare2>
Erik Pilkington82a65ad2018-10-31 17:31:35 +00001345 _LIBCPP_INLINE_VISIBILITY
Louis Dionned2322c82018-11-01 14:41:37 +00001346 void merge(multimap<key_type, mapped_type, _Compare2, allocator_type>& __source)
Erik Pilkington82a65ad2018-10-31 17:31:35 +00001347 {
1348 _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
1349 "merging container with incompatible allocator");
1350 __tree_.__node_handle_merge_unique(__source.__tree_);
1351 }
Louis Dionned2322c82018-11-01 14:41:37 +00001352 template <class _Compare2>
Erik Pilkington82a65ad2018-10-31 17:31:35 +00001353 _LIBCPP_INLINE_VISIBILITY
Louis Dionned2322c82018-11-01 14:41:37 +00001354 void merge(multimap<key_type, mapped_type, _Compare2, allocator_type>&& __source)
Erik Pilkington82a65ad2018-10-31 17:31:35 +00001355 {
1356 _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
1357 "merging container with incompatible allocator");
1358 __tree_.__node_handle_merge_unique(__source.__tree_);
1359 }
Erik Pilkingtonc37a3d82018-08-01 01:33:38 +00001360#endif
1361
Howard Hinnant756c69b2010-09-22 16:48:34 +00001362 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001363 void swap(map& __m)
1364 _NOEXCEPT_(__is_nothrow_swappable<__base>::value)
1365 {__tree_.swap(__m.__tree_);}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001366
Howard Hinnant756c69b2010-09-22 16:48:34 +00001367 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001368 iterator find(const key_type& __k) {return __tree_.find(__k);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001369 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001370 const_iterator find(const key_type& __k) const {return __tree_.find(__k);}
Marshall Clowebb57322013-08-13 22:18:47 +00001371#if _LIBCPP_STD_VER > 11
1372 template <typename _K2>
1373 _LIBCPP_INLINE_VISIBILITY
1374 typename enable_if<__is_transparent<_Compare, _K2>::value,iterator>::type
1375 find(const _K2& __k) {return __tree_.find(__k);}
1376 template <typename _K2>
1377 _LIBCPP_INLINE_VISIBILITY
1378 typename enable_if<__is_transparent<_Compare, _K2>::value,const_iterator>::type
1379 find(const _K2& __k) const {return __tree_.find(__k);}
1380#endif
1381
Howard Hinnant756c69b2010-09-22 16:48:34 +00001382 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001383 size_type count(const key_type& __k) const
1384 {return __tree_.__count_unique(__k);}
Marshall Clowe6a5f522014-08-24 23:54:16 +00001385#if _LIBCPP_STD_VER > 11
1386 template <typename _K2>
1387 _LIBCPP_INLINE_VISIBILITY
1388 typename enable_if<__is_transparent<_Compare, _K2>::value,size_type>::type
Eric Fiseliera85c9e92018-02-10 02:53:47 +00001389 count(const _K2& __k) const {return __tree_.__count_multi(__k);}
Marshall Clowe6a5f522014-08-24 23:54:16 +00001390#endif
Howard Hinnant756c69b2010-09-22 16:48:34 +00001391 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001392 iterator lower_bound(const key_type& __k)
1393 {return __tree_.lower_bound(__k);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001394 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001395 const_iterator lower_bound(const key_type& __k) const
1396 {return __tree_.lower_bound(__k);}
Marshall Clowebb57322013-08-13 22:18:47 +00001397#if _LIBCPP_STD_VER > 11
1398 template <typename _K2>
1399 _LIBCPP_INLINE_VISIBILITY
1400 typename enable_if<__is_transparent<_Compare, _K2>::value,iterator>::type
1401 lower_bound(const _K2& __k) {return __tree_.lower_bound(__k);}
1402
1403 template <typename _K2>
1404 _LIBCPP_INLINE_VISIBILITY
1405 typename enable_if<__is_transparent<_Compare, _K2>::value,const_iterator>::type
1406 lower_bound(const _K2& __k) const {return __tree_.lower_bound(__k);}
1407#endif
1408
Howard Hinnant756c69b2010-09-22 16:48:34 +00001409 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001410 iterator upper_bound(const key_type& __k)
1411 {return __tree_.upper_bound(__k);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001412 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001413 const_iterator upper_bound(const key_type& __k) const
1414 {return __tree_.upper_bound(__k);}
Marshall Clowebb57322013-08-13 22:18:47 +00001415#if _LIBCPP_STD_VER > 11
1416 template <typename _K2>
1417 _LIBCPP_INLINE_VISIBILITY
1418 typename enable_if<__is_transparent<_Compare, _K2>::value,iterator>::type
1419 upper_bound(const _K2& __k) {return __tree_.upper_bound(__k);}
1420 template <typename _K2>
1421 _LIBCPP_INLINE_VISIBILITY
1422 typename enable_if<__is_transparent<_Compare, _K2>::value,const_iterator>::type
1423 upper_bound(const _K2& __k) const {return __tree_.upper_bound(__k);}
1424#endif
1425
Howard Hinnant756c69b2010-09-22 16:48:34 +00001426 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001427 pair<iterator,iterator> equal_range(const key_type& __k)
1428 {return __tree_.__equal_range_unique(__k);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001429 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001430 pair<const_iterator,const_iterator> equal_range(const key_type& __k) const
1431 {return __tree_.__equal_range_unique(__k);}
Marshall Clowebb57322013-08-13 22:18:47 +00001432#if _LIBCPP_STD_VER > 11
1433 template <typename _K2>
1434 _LIBCPP_INLINE_VISIBILITY
1435 typename enable_if<__is_transparent<_Compare, _K2>::value,pair<iterator,iterator>>::type
Eric Fiseliera85c9e92018-02-10 02:53:47 +00001436 equal_range(const _K2& __k) {return __tree_.__equal_range_multi(__k);}
Marshall Clowebb57322013-08-13 22:18:47 +00001437 template <typename _K2>
1438 _LIBCPP_INLINE_VISIBILITY
1439 typename enable_if<__is_transparent<_Compare, _K2>::value,pair<const_iterator,const_iterator>>::type
Eric Fiseliera85c9e92018-02-10 02:53:47 +00001440 equal_range(const _K2& __k) const {return __tree_.__equal_range_multi(__k);}
Marshall Clowebb57322013-08-13 22:18:47 +00001441#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001442
1443private:
1444 typedef typename __base::__node __node;
1445 typedef typename __base::__node_allocator __node_allocator;
1446 typedef typename __base::__node_pointer __node_pointer;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001447 typedef typename __base::__node_base_pointer __node_base_pointer;
Eric Fiseliercf8c0212017-01-05 06:06:18 +00001448 typedef typename __base::__parent_pointer __parent_pointer;
Eric Fiseliera92b0732016-02-20 07:12:17 +00001449
Howard Hinnantc834c512011-11-29 18:15:50 +00001450 typedef __map_node_destructor<__node_allocator> _Dp;
1451 typedef unique_ptr<__node, _Dp> __node_holder;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001452
Eric Fiselierd63f38e2016-03-31 03:13:37 +00001453#ifdef _LIBCPP_CXX03_LANG
Howard Hinnantac7e7482013-07-04 20:59:16 +00001454 __node_holder __construct_node_with_key(const key_type& __k);
Eric Fiselierd63f38e2016-03-31 03:13:37 +00001455#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001456};
1457
Eric Fiseliera92b0732016-02-20 07:12:17 +00001458
Eric Fiselierd06276b2016-03-31 02:15:15 +00001459#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001460template <class _Key, class _Tp, class _Compare, class _Allocator>
1461map<_Key, _Tp, _Compare, _Allocator>::map(map&& __m, const allocator_type& __a)
Marshall Clow657cbc42016-08-17 05:58:40 +00001462 : __tree_(_VSTD::move(__m.__tree_), typename __base::allocator_type(__a))
Howard Hinnantc51e1022010-05-11 19:42:16 +00001463{
1464 if (__a != __m.get_allocator())
1465 {
1466 const_iterator __e = cend();
1467 while (!__m.empty())
1468 __tree_.__insert_unique(__e.__i_,
Erik Pilkingtond3fe2992018-06-04 20:38:23 +00001469 __m.__tree_.remove(__m.begin().__i_)->__value_.__move());
Howard Hinnantc51e1022010-05-11 19:42:16 +00001470 }
1471}
1472
Eric Fiseliera85b1282017-04-18 21:08:06 +00001473template <class _Key, class _Tp, class _Compare, class _Allocator>
1474_Tp&
1475map<_Key, _Tp, _Compare, _Allocator>::operator[](const key_type& __k)
1476{
1477 return __tree_.__emplace_unique_key_args(__k,
1478 _VSTD::piecewise_construct,
1479 _VSTD::forward_as_tuple(__k),
Erik Pilkingtond3fe2992018-06-04 20:38:23 +00001480 _VSTD::forward_as_tuple()).first->__get_value().second;
Eric Fiseliera85b1282017-04-18 21:08:06 +00001481}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001482
Eric Fiseliera85b1282017-04-18 21:08:06 +00001483template <class _Key, class _Tp, class _Compare, class _Allocator>
1484_Tp&
1485map<_Key, _Tp, _Compare, _Allocator>::operator[](key_type&& __k)
1486{
1487 return __tree_.__emplace_unique_key_args(__k,
1488 _VSTD::piecewise_construct,
1489 _VSTD::forward_as_tuple(_VSTD::move(__k)),
Erik Pilkingtond3fe2992018-06-04 20:38:23 +00001490 _VSTD::forward_as_tuple()).first->__get_value().second;
Eric Fiseliera85b1282017-04-18 21:08:06 +00001491}
Eric Fiselierd63f38e2016-03-31 03:13:37 +00001492
Eric Fiseliera85b1282017-04-18 21:08:06 +00001493#else // _LIBCPP_CXX03_LANG
Eric Fiselierd63f38e2016-03-31 03:13:37 +00001494
Howard Hinnantc51e1022010-05-11 19:42:16 +00001495template <class _Key, class _Tp, class _Compare, class _Allocator>
1496typename map<_Key, _Tp, _Compare, _Allocator>::__node_holder
Howard Hinnantac7e7482013-07-04 20:59:16 +00001497map<_Key, _Tp, _Compare, _Allocator>::__construct_node_with_key(const key_type& __k)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001498{
1499 __node_allocator& __na = __tree_.__node_alloc();
Howard Hinnantc834c512011-11-29 18:15:50 +00001500 __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
Erik Pilkingtond3fe2992018-06-04 20:38:23 +00001501 __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__get_value().first), __k);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001502 __h.get_deleter().__first_constructed = true;
Erik Pilkingtond3fe2992018-06-04 20:38:23 +00001503 __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__get_value().second));
Howard Hinnantc51e1022010-05-11 19:42:16 +00001504 __h.get_deleter().__second_constructed = true;
Dimitry Andric830fb602015-08-19 06:43:33 +00001505 return _LIBCPP_EXPLICIT_MOVE(__h); // explicitly moved for C++03
Howard Hinnantc51e1022010-05-11 19:42:16 +00001506}
1507
Howard Hinnantc51e1022010-05-11 19:42:16 +00001508template <class _Key, class _Tp, class _Compare, class _Allocator>
1509_Tp&
1510map<_Key, _Tp, _Compare, _Allocator>::operator[](const key_type& __k)
1511{
Eric Fiseliercf8c0212017-01-05 06:06:18 +00001512 __parent_pointer __parent;
1513 __node_base_pointer& __child = __tree_.__find_equal(__parent, __k);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001514 __node_pointer __r = static_cast<__node_pointer>(__child);
1515 if (__child == nullptr)
1516 {
Howard Hinnantac7e7482013-07-04 20:59:16 +00001517 __node_holder __h = __construct_node_with_key(__k);
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001518 __tree_.__insert_node_at(__parent, __child, static_cast<__node_base_pointer>(__h.get()));
Howard Hinnantc51e1022010-05-11 19:42:16 +00001519 __r = __h.release();
1520 }
Erik Pilkingtond3fe2992018-06-04 20:38:23 +00001521 return __r->__value_.__get_value().second;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001522}
1523
Eric Fiseliera85b1282017-04-18 21:08:06 +00001524#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001525
1526template <class _Key, class _Tp, class _Compare, class _Allocator>
1527_Tp&
1528map<_Key, _Tp, _Compare, _Allocator>::at(const key_type& __k)
1529{
Eric Fiseliercf8c0212017-01-05 06:06:18 +00001530 __parent_pointer __parent;
1531 __node_base_pointer& __child = __tree_.__find_equal(__parent, __k);
Howard Hinnant72f73582010-08-11 17:04:31 +00001532#ifndef _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +00001533 if (__child == nullptr)
1534 throw out_of_range("map::at: key not found");
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001535#endif // _LIBCPP_NO_EXCEPTIONS
Erik Pilkingtond3fe2992018-06-04 20:38:23 +00001536 return static_cast<__node_pointer>(__child)->__value_.__get_value().second;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001537}
1538
1539template <class _Key, class _Tp, class _Compare, class _Allocator>
1540const _Tp&
1541map<_Key, _Tp, _Compare, _Allocator>::at(const key_type& __k) const
1542{
Eric Fiseliercf8c0212017-01-05 06:06:18 +00001543 __parent_pointer __parent;
1544 __node_base_pointer __child = __tree_.__find_equal(__parent, __k);
Howard Hinnant72f73582010-08-11 17:04:31 +00001545#ifndef _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +00001546 if (__child == nullptr)
1547 throw out_of_range("map::at: key not found");
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001548#endif // _LIBCPP_NO_EXCEPTIONS
Erik Pilkingtond3fe2992018-06-04 20:38:23 +00001549 return static_cast<__node_pointer>(__child)->__value_.__get_value().second;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001550}
1551
Howard Hinnantc51e1022010-05-11 19:42:16 +00001552
1553template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001554inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001555bool
1556operator==(const map<_Key, _Tp, _Compare, _Allocator>& __x,
1557 const map<_Key, _Tp, _Compare, _Allocator>& __y)
1558{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001559 return __x.size() == __y.size() && _VSTD::equal(__x.begin(), __x.end(), __y.begin());
Howard Hinnantc51e1022010-05-11 19:42:16 +00001560}
1561
1562template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001563inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001564bool
1565operator< (const map<_Key, _Tp, _Compare, _Allocator>& __x,
1566 const map<_Key, _Tp, _Compare, _Allocator>& __y)
1567{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001568 return _VSTD::lexicographical_compare(__x.begin(), __x.end(), __y.begin(), __y.end());
Howard Hinnantc51e1022010-05-11 19:42:16 +00001569}
1570
1571template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001572inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001573bool
1574operator!=(const map<_Key, _Tp, _Compare, _Allocator>& __x,
1575 const map<_Key, _Tp, _Compare, _Allocator>& __y)
1576{
1577 return !(__x == __y);
1578}
1579
1580template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001581inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001582bool
1583operator> (const map<_Key, _Tp, _Compare, _Allocator>& __x,
1584 const map<_Key, _Tp, _Compare, _Allocator>& __y)
1585{
1586 return __y < __x;
1587}
1588
1589template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001590inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001591bool
1592operator>=(const map<_Key, _Tp, _Compare, _Allocator>& __x,
1593 const map<_Key, _Tp, _Compare, _Allocator>& __y)
1594{
1595 return !(__x < __y);
1596}
1597
1598template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001599inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001600bool
1601operator<=(const map<_Key, _Tp, _Compare, _Allocator>& __x,
1602 const map<_Key, _Tp, _Compare, _Allocator>& __y)
1603{
1604 return !(__y < __x);
1605}
1606
1607template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001608inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001609void
1610swap(map<_Key, _Tp, _Compare, _Allocator>& __x,
1611 map<_Key, _Tp, _Compare, _Allocator>& __y)
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001612 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
Howard Hinnantc51e1022010-05-11 19:42:16 +00001613{
1614 __x.swap(__y);
1615}
1616
1617template <class _Key, class _Tp, class _Compare = less<_Key>,
1618 class _Allocator = allocator<pair<const _Key, _Tp> > >
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00001619class _LIBCPP_TEMPLATE_VIS multimap
Howard Hinnantc51e1022010-05-11 19:42:16 +00001620{
1621public:
1622 // types:
1623 typedef _Key key_type;
1624 typedef _Tp mapped_type;
1625 typedef pair<const key_type, mapped_type> value_type;
1626 typedef _Compare key_compare;
1627 typedef _Allocator allocator_type;
1628 typedef value_type& reference;
1629 typedef const value_type& const_reference;
1630
Louis Dionne878a3a82018-12-06 21:46:17 +00001631 static_assert(sizeof(__diagnose_non_const_comparator<_Key, _Compare>()), "");
Marshall Clow5128cf32015-11-26 01:24:04 +00001632 static_assert((is_same<typename allocator_type::value_type, value_type>::value),
1633 "Allocator::value_type must be same type as value_type");
1634
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00001635 class _LIBCPP_TEMPLATE_VIS value_compare
Howard Hinnantc51e1022010-05-11 19:42:16 +00001636 : public binary_function<value_type, value_type, bool>
1637 {
1638 friend class multimap;
1639 protected:
1640 key_compare comp;
1641
Howard Hinnant756c69b2010-09-22 16:48:34 +00001642 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001643 value_compare(key_compare c) : comp(c) {}
1644 public:
Howard Hinnant756c69b2010-09-22 16:48:34 +00001645 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001646 bool operator()(const value_type& __x, const value_type& __y) const
1647 {return comp(__x.first, __y.first);}
1648 };
1649
1650private:
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001651
Howard Hinnant89f8b792013-09-30 19:08:22 +00001652 typedef _VSTD::__value_type<key_type, mapped_type> __value_type;
Howard Hinnant90b91592013-07-05 18:06:00 +00001653 typedef __map_value_compare<key_type, __value_type, key_compare> __vc;
Marshall Clow940e01c2015-04-07 05:21:38 +00001654 typedef typename __rebind_alloc_helper<allocator_traits<allocator_type>,
1655 __value_type>::type __allocator_type;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001656 typedef __tree<__value_type, __vc, __allocator_type> __base;
1657 typedef typename __base::__node_traits __node_traits;
1658 typedef allocator_traits<allocator_type> __alloc_traits;
1659
1660 __base __tree_;
1661
1662public:
1663 typedef typename __alloc_traits::pointer pointer;
1664 typedef typename __alloc_traits::const_pointer const_pointer;
1665 typedef typename __alloc_traits::size_type size_type;
1666 typedef typename __alloc_traits::difference_type difference_type;
1667 typedef __map_iterator<typename __base::iterator> iterator;
1668 typedef __map_const_iterator<typename __base::const_iterator> const_iterator;
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001669 typedef _VSTD::reverse_iterator<iterator> reverse_iterator;
1670 typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001671
Erik Pilkingtonc37a3d82018-08-01 01:33:38 +00001672#if _LIBCPP_STD_VER > 14
1673 typedef __map_node_handle<typename __base::__node, allocator_type> node_type;
1674#endif
1675
Erik Pilkington82a65ad2018-10-31 17:31:35 +00001676 template <class _Key2, class _Value2, class _Comp2, class _Alloc2>
1677 friend class _LIBCPP_TEMPLATE_VIS map;
1678 template <class _Key2, class _Value2, class _Comp2, class _Alloc2>
1679 friend class _LIBCPP_TEMPLATE_VIS multimap;
1680
Howard Hinnant756c69b2010-09-22 16:48:34 +00001681 _LIBCPP_INLINE_VISIBILITY
Marshall Clow7086a5a2014-03-10 04:50:10 +00001682 multimap()
1683 _NOEXCEPT_(
1684 is_nothrow_default_constructible<allocator_type>::value &&
1685 is_nothrow_default_constructible<key_compare>::value &&
1686 is_nothrow_copy_constructible<key_compare>::value)
1687 : __tree_(__vc(key_compare())) {}
1688
1689 _LIBCPP_INLINE_VISIBILITY
1690 explicit multimap(const key_compare& __comp)
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001691 _NOEXCEPT_(
1692 is_nothrow_default_constructible<allocator_type>::value &&
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001693 is_nothrow_copy_constructible<key_compare>::value)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001694 : __tree_(__vc(__comp)) {}
1695
Howard Hinnant756c69b2010-09-22 16:48:34 +00001696 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001697 explicit multimap(const key_compare& __comp, const allocator_type& __a)
Marshall Clow657cbc42016-08-17 05:58:40 +00001698 : __tree_(__vc(__comp), typename __base::allocator_type(__a)) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001699
1700 template <class _InputIterator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001701 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001702 multimap(_InputIterator __f, _InputIterator __l,
1703 const key_compare& __comp = key_compare())
1704 : __tree_(__vc(__comp))
1705 {
1706 insert(__f, __l);
1707 }
1708
1709 template <class _InputIterator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001710 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001711 multimap(_InputIterator __f, _InputIterator __l,
1712 const key_compare& __comp, const allocator_type& __a)
Marshall Clow657cbc42016-08-17 05:58:40 +00001713 : __tree_(__vc(__comp), typename __base::allocator_type(__a))
Howard Hinnantc51e1022010-05-11 19:42:16 +00001714 {
1715 insert(__f, __l);
1716 }
1717
Marshall Clow300abfb2013-09-11 01:15:47 +00001718#if _LIBCPP_STD_VER > 11
1719 template <class _InputIterator>
Eric Fiseliercf8c0212017-01-05 06:06:18 +00001720 _LIBCPP_INLINE_VISIBILITY
Marshall Clow300abfb2013-09-11 01:15:47 +00001721 multimap(_InputIterator __f, _InputIterator __l, const allocator_type& __a)
1722 : multimap(__f, __l, key_compare(), __a) {}
1723#endif
1724
Howard Hinnant756c69b2010-09-22 16:48:34 +00001725 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001726 multimap(const multimap& __m)
1727 : __tree_(__m.__tree_.value_comp(),
1728 __alloc_traits::select_on_container_copy_construction(__m.__tree_.__alloc()))
1729 {
1730 insert(__m.begin(), __m.end());
1731 }
1732
Howard Hinnantd3a657f2011-07-01 19:24:36 +00001733 _LIBCPP_INLINE_VISIBILITY
1734 multimap& operator=(const multimap& __m)
1735 {
Marshall Clow476d3f42016-07-18 13:19:00 +00001736#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantd3a657f2011-07-01 19:24:36 +00001737 __tree_ = __m.__tree_;
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001738#else
Marshall Clowdb3cfcb2014-02-08 04:03:14 +00001739 if (this != &__m) {
1740 __tree_.clear();
1741 __tree_.value_comp() = __m.__tree_.value_comp();
1742 __tree_.__copy_assign_alloc(__m.__tree_);
1743 insert(__m.begin(), __m.end());
1744 }
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001745#endif
Howard Hinnantd3a657f2011-07-01 19:24:36 +00001746 return *this;
1747 }
1748
Eric Fiseliera85b1282017-04-18 21:08:06 +00001749#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001750
Howard Hinnant756c69b2010-09-22 16:48:34 +00001751 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001752 multimap(multimap&& __m)
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001753 _NOEXCEPT_(is_nothrow_move_constructible<__base>::value)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001754 : __tree_(_VSTD::move(__m.__tree_))
Howard Hinnantc51e1022010-05-11 19:42:16 +00001755 {
1756 }
1757
1758 multimap(multimap&& __m, const allocator_type& __a);
1759
Howard Hinnant756c69b2010-09-22 16:48:34 +00001760 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant33711792011-08-12 21:56:02 +00001761 multimap& operator=(multimap&& __m)
1762 _NOEXCEPT_(is_nothrow_move_assignable<__base>::value)
1763 {
1764 __tree_ = _VSTD::move(__m.__tree_);
1765 return *this;
1766 }
1767
Howard Hinnant33711792011-08-12 21:56:02 +00001768 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001769 multimap(initializer_list<value_type> __il, const key_compare& __comp = key_compare())
1770 : __tree_(__vc(__comp))
1771 {
1772 insert(__il.begin(), __il.end());
1773 }
1774
Howard Hinnant756c69b2010-09-22 16:48:34 +00001775 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001776 multimap(initializer_list<value_type> __il, const key_compare& __comp, const allocator_type& __a)
Marshall Clow657cbc42016-08-17 05:58:40 +00001777 : __tree_(__vc(__comp), typename __base::allocator_type(__a))
Howard Hinnantc51e1022010-05-11 19:42:16 +00001778 {
1779 insert(__il.begin(), __il.end());
1780 }
1781
Marshall Clow300abfb2013-09-11 01:15:47 +00001782#if _LIBCPP_STD_VER > 11
Eric Fiseliercf8c0212017-01-05 06:06:18 +00001783 _LIBCPP_INLINE_VISIBILITY
Marshall Clow300abfb2013-09-11 01:15:47 +00001784 multimap(initializer_list<value_type> __il, const allocator_type& __a)
1785 : multimap(__il, key_compare(), __a) {}
1786#endif
1787
Howard Hinnant756c69b2010-09-22 16:48:34 +00001788 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001789 multimap& operator=(initializer_list<value_type> __il)
1790 {
1791 __tree_.__assign_multi(__il.begin(), __il.end());
1792 return *this;
1793 }
Howard Hinnant33711792011-08-12 21:56:02 +00001794
Eric Fiseliera85b1282017-04-18 21:08:06 +00001795#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001796
Howard Hinnant756c69b2010-09-22 16:48:34 +00001797 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001798 explicit multimap(const allocator_type& __a)
Marshall Clow657cbc42016-08-17 05:58:40 +00001799 : __tree_(typename __base::allocator_type(__a))
Howard Hinnantc51e1022010-05-11 19:42:16 +00001800 {
1801 }
1802
Howard Hinnant756c69b2010-09-22 16:48:34 +00001803 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001804 multimap(const multimap& __m, const allocator_type& __a)
Marshall Clow657cbc42016-08-17 05:58:40 +00001805 : __tree_(__m.__tree_.value_comp(), typename __base::allocator_type(__a))
Howard Hinnantc51e1022010-05-11 19:42:16 +00001806 {
1807 insert(__m.begin(), __m.end());
1808 }
1809
Howard Hinnant756c69b2010-09-22 16:48:34 +00001810 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001811 iterator begin() _NOEXCEPT {return __tree_.begin();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001812 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001813 const_iterator begin() const _NOEXCEPT {return __tree_.begin();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001814 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001815 iterator end() _NOEXCEPT {return __tree_.end();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001816 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001817 const_iterator end() const _NOEXCEPT {return __tree_.end();}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001818
Howard Hinnant756c69b2010-09-22 16:48:34 +00001819 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001820 reverse_iterator rbegin() _NOEXCEPT {return reverse_iterator(end());}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001821 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001822 const_reverse_iterator rbegin() const _NOEXCEPT
1823 {return const_reverse_iterator(end());}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001824 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001825 reverse_iterator rend() _NOEXCEPT {return reverse_iterator(begin());}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001826 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001827 const_reverse_iterator rend() const _NOEXCEPT
1828 {return const_reverse_iterator(begin());}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001829
Howard Hinnant756c69b2010-09-22 16:48:34 +00001830 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001831 const_iterator cbegin() const _NOEXCEPT {return begin();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001832 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001833 const_iterator cend() const _NOEXCEPT {return end();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001834 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001835 const_reverse_iterator crbegin() const _NOEXCEPT {return rbegin();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001836 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001837 const_reverse_iterator crend() const _NOEXCEPT {return rend();}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001838
Marshall Clow425f5752017-11-15 05:51:26 +00001839 _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001840 bool empty() const _NOEXCEPT {return __tree_.size() == 0;}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001841 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001842 size_type size() const _NOEXCEPT {return __tree_.size();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001843 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001844 size_type max_size() const _NOEXCEPT {return __tree_.max_size();}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001845
Howard Hinnant756c69b2010-09-22 16:48:34 +00001846 _LIBCPP_INLINE_VISIBILITY
Marshall Clow657cbc42016-08-17 05:58:40 +00001847 allocator_type get_allocator() const _NOEXCEPT {return allocator_type(__tree_.__alloc());}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001848 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001849 key_compare key_comp() const {return __tree_.value_comp().key_comp();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001850 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001851 value_compare value_comp() const
1852 {return value_compare(__tree_.value_comp().key_comp());}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001853
Eric Fiselierd06276b2016-03-31 02:15:15 +00001854#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant74279a52010-09-04 23:28:19 +00001855
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001856 template <class ..._Args>
Eric Fiselierd06276b2016-03-31 02:15:15 +00001857 _LIBCPP_INLINE_VISIBILITY
1858 iterator emplace(_Args&& ...__args) {
1859 return __tree_.__emplace_multi(_VSTD::forward<_Args>(__args)...);
1860 }
Howard Hinnantc51e1022010-05-11 19:42:16 +00001861
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001862 template <class ..._Args>
Eric Fiselierd06276b2016-03-31 02:15:15 +00001863 _LIBCPP_INLINE_VISIBILITY
1864 iterator emplace_hint(const_iterator __p, _Args&& ...__args) {
1865 return __tree_.__emplace_hint_multi(__p.__i_, _VSTD::forward<_Args>(__args)...);
1866 }
Howard Hinnant74279a52010-09-04 23:28:19 +00001867
Howard Hinnantc834c512011-11-29 18:15:50 +00001868 template <class _Pp,
1869 class = typename enable_if<is_constructible<value_type, _Pp>::value>::type>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001870 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc834c512011-11-29 18:15:50 +00001871 iterator insert(_Pp&& __p)
1872 {return __tree_.__insert_multi(_VSTD::forward<_Pp>(__p));}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001873
Howard Hinnantc834c512011-11-29 18:15:50 +00001874 template <class _Pp,
1875 class = typename enable_if<is_constructible<value_type, _Pp>::value>::type>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001876 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc834c512011-11-29 18:15:50 +00001877 iterator insert(const_iterator __pos, _Pp&& __p)
1878 {return __tree_.__insert_multi(__pos.__i_, _VSTD::forward<_Pp>(__p));}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001879
Eric Fiselierd6143132016-04-18 01:40:45 +00001880 _LIBCPP_INLINE_VISIBILITY
1881 iterator insert(value_type&& __v)
1882 {return __tree_.__insert_multi(_VSTD::move(__v));}
1883
1884 _LIBCPP_INLINE_VISIBILITY
1885 iterator insert(const_iterator __p, value_type&& __v)
1886 {return __tree_.__insert_multi(__p.__i_, _VSTD::move(__v));}
1887
Eric Fiseliera85b1282017-04-18 21:08:06 +00001888
1889 _LIBCPP_INLINE_VISIBILITY
1890 void insert(initializer_list<value_type> __il)
1891 {insert(__il.begin(), __il.end());}
1892
Eric Fiselierd06276b2016-03-31 02:15:15 +00001893#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001894
Howard Hinnant756c69b2010-09-22 16:48:34 +00001895 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001896 iterator insert(const value_type& __v) {return __tree_.__insert_multi(__v);}
1897
Howard Hinnant756c69b2010-09-22 16:48:34 +00001898 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001899 iterator insert(const_iterator __p, const value_type& __v)
1900 {return __tree_.__insert_multi(__p.__i_, __v);}
1901
1902 template <class _InputIterator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001903 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001904 void insert(_InputIterator __f, _InputIterator __l)
1905 {
1906 for (const_iterator __e = cend(); __f != __l; ++__f)
1907 __tree_.__insert_multi(__e.__i_, *__f);
1908 }
1909
Howard Hinnant756c69b2010-09-22 16:48:34 +00001910 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001911 iterator erase(const_iterator __p) {return __tree_.erase(__p.__i_);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001912 _LIBCPP_INLINE_VISIBILITY
Marshall Clow22ea5b82015-05-10 13:35:00 +00001913 iterator erase(iterator __p) {return __tree_.erase(__p.__i_);}
1914 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001915 size_type erase(const key_type& __k) {return __tree_.__erase_multi(__k);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001916 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001917 iterator erase(const_iterator __f, const_iterator __l)
1918 {return __tree_.erase(__f.__i_, __l.__i_);}
Erik Pilkingtonc37a3d82018-08-01 01:33:38 +00001919
1920#if _LIBCPP_STD_VER > 14
1921 _LIBCPP_INLINE_VISIBILITY
1922 iterator insert(node_type&& __nh)
1923 {
1924 _LIBCPP_ASSERT(__nh.empty() || __nh.get_allocator() == get_allocator(),
1925 "node_type with incompatible allocator passed to multimap::insert()");
1926 return __tree_.template __node_handle_insert_multi<node_type>(
1927 _VSTD::move(__nh));
1928 }
1929 _LIBCPP_INLINE_VISIBILITY
1930 iterator insert(const_iterator __hint, node_type&& __nh)
1931 {
1932 _LIBCPP_ASSERT(__nh.empty() || __nh.get_allocator() == get_allocator(),
1933 "node_type with incompatible allocator passed to multimap::insert()");
1934 return __tree_.template __node_handle_insert_multi<node_type>(
1935 __hint.__i_, _VSTD::move(__nh));
1936 }
1937 _LIBCPP_INLINE_VISIBILITY
1938 node_type extract(key_type const& __key)
1939 {
1940 return __tree_.template __node_handle_extract<node_type>(__key);
1941 }
1942 _LIBCPP_INLINE_VISIBILITY
1943 node_type extract(const_iterator __it)
1944 {
1945 return __tree_.template __node_handle_extract<node_type>(
1946 __it.__i_);
1947 }
Louis Dionned2322c82018-11-01 14:41:37 +00001948 template <class _Compare2>
Erik Pilkington82a65ad2018-10-31 17:31:35 +00001949 _LIBCPP_INLINE_VISIBILITY
Louis Dionned2322c82018-11-01 14:41:37 +00001950 void merge(multimap<key_type, mapped_type, _Compare2, allocator_type>& __source)
Erik Pilkington82a65ad2018-10-31 17:31:35 +00001951 {
1952 _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
1953 "merging container with incompatible allocator");
1954 return __tree_.__node_handle_merge_multi(__source.__tree_);
1955 }
Louis Dionned2322c82018-11-01 14:41:37 +00001956 template <class _Compare2>
Erik Pilkington82a65ad2018-10-31 17:31:35 +00001957 _LIBCPP_INLINE_VISIBILITY
Louis Dionned2322c82018-11-01 14:41:37 +00001958 void merge(multimap<key_type, mapped_type, _Compare2, allocator_type>&& __source)
Erik Pilkington82a65ad2018-10-31 17:31:35 +00001959 {
1960 _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
1961 "merging container with incompatible allocator");
1962 return __tree_.__node_handle_merge_multi(__source.__tree_);
1963 }
Louis Dionned2322c82018-11-01 14:41:37 +00001964 template <class _Compare2>
Erik Pilkington82a65ad2018-10-31 17:31:35 +00001965 _LIBCPP_INLINE_VISIBILITY
Louis Dionned2322c82018-11-01 14:41:37 +00001966 void merge(map<key_type, mapped_type, _Compare2, allocator_type>& __source)
Erik Pilkington82a65ad2018-10-31 17:31:35 +00001967 {
1968 _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
1969 "merging container with incompatible allocator");
1970 return __tree_.__node_handle_merge_multi(__source.__tree_);
1971 }
Louis Dionned2322c82018-11-01 14:41:37 +00001972 template <class _Compare2>
Erik Pilkington82a65ad2018-10-31 17:31:35 +00001973 _LIBCPP_INLINE_VISIBILITY
Louis Dionned2322c82018-11-01 14:41:37 +00001974 void merge(map<key_type, mapped_type, _Compare2, allocator_type>&& __source)
Erik Pilkington82a65ad2018-10-31 17:31:35 +00001975 {
1976 _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
1977 "merging container with incompatible allocator");
1978 return __tree_.__node_handle_merge_multi(__source.__tree_);
1979 }
Erik Pilkingtonc37a3d82018-08-01 01:33:38 +00001980#endif
1981
Howard Hinnant756c69b2010-09-22 16:48:34 +00001982 _LIBCPP_INLINE_VISIBILITY
Marshall Clowde1312a2018-08-22 04:28:43 +00001983 void clear() _NOEXCEPT {__tree_.clear();}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001984
Howard Hinnant756c69b2010-09-22 16:48:34 +00001985 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001986 void swap(multimap& __m)
1987 _NOEXCEPT_(__is_nothrow_swappable<__base>::value)
1988 {__tree_.swap(__m.__tree_);}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001989
Howard Hinnant756c69b2010-09-22 16:48:34 +00001990 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001991 iterator find(const key_type& __k) {return __tree_.find(__k);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001992 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001993 const_iterator find(const key_type& __k) const {return __tree_.find(__k);}
Marshall Clowebb57322013-08-13 22:18:47 +00001994#if _LIBCPP_STD_VER > 11
1995 template <typename _K2>
1996 _LIBCPP_INLINE_VISIBILITY
1997 typename enable_if<__is_transparent<_Compare, _K2>::value,iterator>::type
1998 find(const _K2& __k) {return __tree_.find(__k);}
1999 template <typename _K2>
2000 _LIBCPP_INLINE_VISIBILITY
2001 typename enable_if<__is_transparent<_Compare, _K2>::value,const_iterator>::type
2002 find(const _K2& __k) const {return __tree_.find(__k);}
2003#endif
2004
Howard Hinnant756c69b2010-09-22 16:48:34 +00002005 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002006 size_type count(const key_type& __k) const
2007 {return __tree_.__count_multi(__k);}
Marshall Clowe6a5f522014-08-24 23:54:16 +00002008#if _LIBCPP_STD_VER > 11
2009 template <typename _K2>
2010 _LIBCPP_INLINE_VISIBILITY
2011 typename enable_if<__is_transparent<_Compare, _K2>::value,size_type>::type
Marshall Clow141e47b2015-06-30 18:15:41 +00002012 count(const _K2& __k) const {return __tree_.__count_multi(__k);}
Marshall Clowe6a5f522014-08-24 23:54:16 +00002013#endif
Howard Hinnant756c69b2010-09-22 16:48:34 +00002014 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002015 iterator lower_bound(const key_type& __k)
2016 {return __tree_.lower_bound(__k);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00002017 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002018 const_iterator lower_bound(const key_type& __k) const
2019 {return __tree_.lower_bound(__k);}
Marshall Clowebb57322013-08-13 22:18:47 +00002020#if _LIBCPP_STD_VER > 11
2021 template <typename _K2>
2022 _LIBCPP_INLINE_VISIBILITY
2023 typename enable_if<__is_transparent<_Compare, _K2>::value,iterator>::type
2024 lower_bound(const _K2& __k) {return __tree_.lower_bound(__k);}
2025
2026 template <typename _K2>
2027 _LIBCPP_INLINE_VISIBILITY
2028 typename enable_if<__is_transparent<_Compare, _K2>::value,const_iterator>::type
2029 lower_bound(const _K2& __k) const {return __tree_.lower_bound(__k);}
2030#endif
2031
Howard Hinnant756c69b2010-09-22 16:48:34 +00002032 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002033 iterator upper_bound(const key_type& __k)
2034 {return __tree_.upper_bound(__k);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00002035 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002036 const_iterator upper_bound(const key_type& __k) const
2037 {return __tree_.upper_bound(__k);}
Marshall Clowebb57322013-08-13 22:18:47 +00002038#if _LIBCPP_STD_VER > 11
2039 template <typename _K2>
2040 _LIBCPP_INLINE_VISIBILITY
2041 typename enable_if<__is_transparent<_Compare, _K2>::value,iterator>::type
2042 upper_bound(const _K2& __k) {return __tree_.upper_bound(__k);}
2043 template <typename _K2>
2044 _LIBCPP_INLINE_VISIBILITY
2045 typename enable_if<__is_transparent<_Compare, _K2>::value,const_iterator>::type
2046 upper_bound(const _K2& __k) const {return __tree_.upper_bound(__k);}
2047#endif
2048
Howard Hinnant756c69b2010-09-22 16:48:34 +00002049 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002050 pair<iterator,iterator> equal_range(const key_type& __k)
2051 {return __tree_.__equal_range_multi(__k);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00002052 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002053 pair<const_iterator,const_iterator> equal_range(const key_type& __k) const
2054 {return __tree_.__equal_range_multi(__k);}
Marshall Clowebb57322013-08-13 22:18:47 +00002055#if _LIBCPP_STD_VER > 11
2056 template <typename _K2>
2057 _LIBCPP_INLINE_VISIBILITY
2058 typename enable_if<__is_transparent<_Compare, _K2>::value,pair<iterator,iterator>>::type
2059 equal_range(const _K2& __k) {return __tree_.__equal_range_multi(__k);}
2060 template <typename _K2>
2061 _LIBCPP_INLINE_VISIBILITY
2062 typename enable_if<__is_transparent<_Compare, _K2>::value,pair<const_iterator,const_iterator>>::type
2063 equal_range(const _K2& __k) const {return __tree_.__equal_range_multi(__k);}
2064#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00002065
2066private:
2067 typedef typename __base::__node __node;
2068 typedef typename __base::__node_allocator __node_allocator;
2069 typedef typename __base::__node_pointer __node_pointer;
Eric Fiseliera92b0732016-02-20 07:12:17 +00002070
Howard Hinnantc834c512011-11-29 18:15:50 +00002071 typedef __map_node_destructor<__node_allocator> _Dp;
2072 typedef unique_ptr<__node, _Dp> __node_holder;
Howard Hinnantc51e1022010-05-11 19:42:16 +00002073};
2074
Eric Fiselierd06276b2016-03-31 02:15:15 +00002075#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00002076template <class _Key, class _Tp, class _Compare, class _Allocator>
2077multimap<_Key, _Tp, _Compare, _Allocator>::multimap(multimap&& __m, const allocator_type& __a)
Marshall Clow657cbc42016-08-17 05:58:40 +00002078 : __tree_(_VSTD::move(__m.__tree_), typename __base::allocator_type(__a))
Howard Hinnantc51e1022010-05-11 19:42:16 +00002079{
2080 if (__a != __m.get_allocator())
2081 {
2082 const_iterator __e = cend();
2083 while (!__m.empty())
2084 __tree_.__insert_multi(__e.__i_,
Erik Pilkingtond3fe2992018-06-04 20:38:23 +00002085 _VSTD::move(__m.__tree_.remove(__m.begin().__i_)->__value_.__move()));
Howard Hinnantc51e1022010-05-11 19:42:16 +00002086 }
2087}
Eric Fiselierd06276b2016-03-31 02:15:15 +00002088#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00002089
2090template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00002091inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002092bool
2093operator==(const multimap<_Key, _Tp, _Compare, _Allocator>& __x,
2094 const multimap<_Key, _Tp, _Compare, _Allocator>& __y)
2095{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00002096 return __x.size() == __y.size() && _VSTD::equal(__x.begin(), __x.end(), __y.begin());
Howard Hinnantc51e1022010-05-11 19:42:16 +00002097}
2098
2099template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00002100inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002101bool
2102operator< (const multimap<_Key, _Tp, _Compare, _Allocator>& __x,
2103 const multimap<_Key, _Tp, _Compare, _Allocator>& __y)
2104{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00002105 return _VSTD::lexicographical_compare(__x.begin(), __x.end(), __y.begin(), __y.end());
Howard Hinnantc51e1022010-05-11 19:42:16 +00002106}
2107
2108template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00002109inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002110bool
2111operator!=(const multimap<_Key, _Tp, _Compare, _Allocator>& __x,
2112 const multimap<_Key, _Tp, _Compare, _Allocator>& __y)
2113{
2114 return !(__x == __y);
2115}
2116
2117template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00002118inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002119bool
2120operator> (const multimap<_Key, _Tp, _Compare, _Allocator>& __x,
2121 const multimap<_Key, _Tp, _Compare, _Allocator>& __y)
2122{
2123 return __y < __x;
2124}
2125
2126template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00002127inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002128bool
2129operator>=(const multimap<_Key, _Tp, _Compare, _Allocator>& __x,
2130 const multimap<_Key, _Tp, _Compare, _Allocator>& __y)
2131{
2132 return !(__x < __y);
2133}
2134
2135template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00002136inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002137bool
2138operator<=(const multimap<_Key, _Tp, _Compare, _Allocator>& __x,
2139 const multimap<_Key, _Tp, _Compare, _Allocator>& __y)
2140{
2141 return !(__y < __x);
2142}
2143
2144template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00002145inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002146void
2147swap(multimap<_Key, _Tp, _Compare, _Allocator>& __x,
2148 multimap<_Key, _Tp, _Compare, _Allocator>& __y)
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00002149 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
Howard Hinnantc51e1022010-05-11 19:42:16 +00002150{
2151 __x.swap(__y);
2152}
2153
2154_LIBCPP_END_NAMESPACE_STD
2155
2156#endif // _LIBCPP_MAP