blob: 559ec484aca052015b1db3a62fa0f5df626ca839 [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
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000170 void swap(map& m)
Marshall Clow8982dcd2015-07-13 20:04:56 +0000171 noexcept(allocator_traits<allocator_type>::is_always_equal::value &&
Eric Fiselier6bfed252016-04-21 23:38:59 +0000172 is_nothrow_swappable<key_compare>::value); // C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000173
174 // observers:
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000175 allocator_type get_allocator() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000176 key_compare key_comp() const;
177 value_compare value_comp() const;
178
179 // map operations:
180 iterator find(const key_type& k);
181 const_iterator find(const key_type& k) const;
Marshall Clowebb57322013-08-13 22:18:47 +0000182 template<typename K>
183 iterator find(const K& x); // C++14
184 template<typename K>
185 const_iterator find(const K& x) const; // C++14
186 template<typename K>
Marshall Clowe6a5f522014-08-24 23:54:16 +0000187 size_type count(const K& x) const; // C++14
Marshall Clowebb57322013-08-13 22:18:47 +0000188
Howard Hinnantc51e1022010-05-11 19:42:16 +0000189 size_type count(const key_type& k) const;
190 iterator lower_bound(const key_type& k);
191 const_iterator lower_bound(const key_type& k) const;
Marshall Clowebb57322013-08-13 22:18:47 +0000192 template<typename K>
193 iterator lower_bound(const K& x); // C++14
194 template<typename K>
195 const_iterator lower_bound(const K& x) const; // C++14
196
Howard Hinnantc51e1022010-05-11 19:42:16 +0000197 iterator upper_bound(const key_type& k);
198 const_iterator upper_bound(const key_type& k) const;
Marshall Clowebb57322013-08-13 22:18:47 +0000199 template<typename K>
200 iterator upper_bound(const K& x); // C++14
201 template<typename K>
202 const_iterator upper_bound(const K& x) const; // C++14
203
Howard Hinnantc51e1022010-05-11 19:42:16 +0000204 pair<iterator,iterator> equal_range(const key_type& k);
205 pair<const_iterator,const_iterator> equal_range(const key_type& k) const;
Marshall Clowebb57322013-08-13 22:18:47 +0000206 template<typename K>
207 pair<iterator,iterator> equal_range(const K& x); // C++14
208 template<typename K>
209 pair<const_iterator,const_iterator> equal_range(const K& x) const; // C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000210};
211
212template <class Key, class T, class Compare, class Allocator>
213bool
214operator==(const map<Key, T, Compare, Allocator>& x,
215 const map<Key, T, Compare, Allocator>& y);
216
217template <class Key, class T, class Compare, class Allocator>
218bool
219operator< (const map<Key, T, Compare, Allocator>& x,
220 const map<Key, T, Compare, Allocator>& y);
221
222template <class Key, class T, class Compare, class Allocator>
223bool
224operator!=(const map<Key, T, Compare, Allocator>& x,
225 const map<Key, T, Compare, Allocator>& y);
226
227template <class Key, class T, class Compare, class Allocator>
228bool
229operator> (const map<Key, T, Compare, Allocator>& x,
230 const map<Key, T, Compare, Allocator>& y);
231
232template <class Key, class T, class Compare, class Allocator>
233bool
234operator>=(const map<Key, T, Compare, Allocator>& x,
235 const map<Key, T, Compare, Allocator>& y);
236
237template <class Key, class T, class Compare, class Allocator>
238bool
239operator<=(const map<Key, T, Compare, Allocator>& x,
240 const map<Key, T, Compare, Allocator>& y);
241
242// specialized algorithms:
243template <class Key, class T, class Compare, class Allocator>
244void
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000245swap(map<Key, T, Compare, Allocator>& x, map<Key, T, Compare, Allocator>& y)
246 noexcept(noexcept(x.swap(y)));
Howard Hinnantc51e1022010-05-11 19:42:16 +0000247
248template <class Key, class T, class Compare = less<Key>,
249 class Allocator = allocator<pair<const Key, T>>>
250class multimap
251{
252public:
253 // types:
254 typedef Key key_type;
255 typedef T mapped_type;
256 typedef pair<const key_type,mapped_type> value_type;
257 typedef Compare key_compare;
258 typedef Allocator allocator_type;
259 typedef typename allocator_type::reference reference;
260 typedef typename allocator_type::const_reference const_reference;
261 typedef typename allocator_type::size_type size_type;
262 typedef typename allocator_type::difference_type difference_type;
263 typedef typename allocator_type::pointer pointer;
264 typedef typename allocator_type::const_pointer const_pointer;
265
266 typedef implementation-defined iterator;
267 typedef implementation-defined const_iterator;
268 typedef std::reverse_iterator<iterator> reverse_iterator;
269 typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
Erik Pilkingtonc37a3d82018-08-01 01:33:38 +0000270 typedef unspecified node_type; // C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000271
272 class value_compare
273 : public binary_function<value_type,value_type,bool>
274 {
275 friend class multimap;
276 protected:
277 key_compare comp;
278 value_compare(key_compare c);
279 public:
280 bool operator()(const value_type& x, const value_type& y) const;
281 };
282
283 // construct/copy/destroy:
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000284 multimap()
285 noexcept(
286 is_nothrow_default_constructible<allocator_type>::value &&
287 is_nothrow_default_constructible<key_compare>::value &&
288 is_nothrow_copy_constructible<key_compare>::value);
289 explicit multimap(const key_compare& comp);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000290 multimap(const key_compare& comp, const allocator_type& a);
291 template <class InputIterator>
292 multimap(InputIterator first, InputIterator last, const key_compare& comp);
293 template <class InputIterator>
294 multimap(InputIterator first, InputIterator last, const key_compare& comp,
295 const allocator_type& a);
296 multimap(const multimap& m);
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000297 multimap(multimap&& m)
298 noexcept(
299 is_nothrow_move_constructible<allocator_type>::value &&
300 is_nothrow_move_constructible<key_compare>::value);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000301 explicit multimap(const allocator_type& a);
302 multimap(const multimap& m, const allocator_type& a);
303 multimap(multimap&& m, const allocator_type& a);
304 multimap(initializer_list<value_type> il, const key_compare& comp = key_compare());
305 multimap(initializer_list<value_type> il, const key_compare& comp,
306 const allocator_type& a);
Marshall Clow300abfb2013-09-11 01:15:47 +0000307 template <class InputIterator>
308 multimap(InputIterator first, InputIterator last, const allocator_type& a)
309 : multimap(first, last, Compare(), a) {} // C++14
310 multimap(initializer_list<value_type> il, const allocator_type& a)
311 : multimap(il, Compare(), a) {} // C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000312 ~multimap();
313
314 multimap& operator=(const multimap& m);
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000315 multimap& operator=(multimap&& m)
316 noexcept(
317 allocator_type::propagate_on_container_move_assignment::value &&
318 is_nothrow_move_assignable<allocator_type>::value &&
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000319 is_nothrow_move_assignable<key_compare>::value);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000320 multimap& operator=(initializer_list<value_type> il);
321
322 // iterators:
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000323 iterator begin() noexcept;
324 const_iterator begin() const noexcept;
325 iterator end() noexcept;
326 const_iterator end() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000327
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000328 reverse_iterator rbegin() noexcept;
329 const_reverse_iterator rbegin() const noexcept;
330 reverse_iterator rend() noexcept;
331 const_reverse_iterator rend() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000332
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000333 const_iterator cbegin() const noexcept;
334 const_iterator cend() const noexcept;
335 const_reverse_iterator crbegin() const noexcept;
336 const_reverse_iterator crend() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000337
338 // capacity:
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000339 bool empty() const noexcept;
340 size_type size() const noexcept;
341 size_type max_size() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000342
343 // modifiers:
344 template <class... Args>
345 iterator emplace(Args&&... args);
346 template <class... Args>
347 iterator emplace_hint(const_iterator position, Args&&... args);
348 iterator insert(const value_type& v);
Marshall Clowd430d022016-01-05 19:32:41 +0000349 iterator insert( value_type&& v); // C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000350 template <class P>
351 iterator insert(P&& p);
352 iterator insert(const_iterator position, const value_type& v);
Marshall Clowd430d022016-01-05 19:32:41 +0000353 iterator insert(const_iterator position, value_type&& v); // C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000354 template <class P>
355 iterator insert(const_iterator position, P&& p);
356 template <class InputIterator>
357 void insert(InputIterator first, InputIterator last);
358 void insert(initializer_list<value_type> il);
359
Erik Pilkingtonc37a3d82018-08-01 01:33:38 +0000360 node_type extract(const_iterator position); // C++17
361 node_type extract(const key_type& x); // C++17
362 iterator insert(node_type&& nh); // C++17
363 iterator insert(const_iterator hint, node_type&& nh); // C++17
364
Howard Hinnantc51e1022010-05-11 19:42:16 +0000365 iterator erase(const_iterator position);
Marshall Clow22ea5b82015-05-10 13:35:00 +0000366 iterator erase(iterator position); // C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000367 size_type erase(const key_type& k);
368 iterator erase(const_iterator first, const_iterator last);
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000369 void clear() noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000370
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000371 void swap(multimap& m)
Marshall Clow8982dcd2015-07-13 20:04:56 +0000372 noexcept(allocator_traits<allocator_type>::is_always_equal::value &&
Eric Fiselier6bfed252016-04-21 23:38:59 +0000373 is_nothrow_swappable<key_compare>::value); // C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000374
375 // observers:
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000376 allocator_type get_allocator() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000377 key_compare key_comp() const;
378 value_compare value_comp() const;
379
380 // map operations:
381 iterator find(const key_type& k);
382 const_iterator find(const key_type& k) const;
Marshall Clowebb57322013-08-13 22:18:47 +0000383 template<typename K>
384 iterator find(const K& x); // C++14
385 template<typename K>
386 const_iterator find(const K& x) const; // C++14
387 template<typename K>
Marshall Clowe6a5f522014-08-24 23:54:16 +0000388 size_type count(const K& x) const; // C++14
Marshall Clowebb57322013-08-13 22:18:47 +0000389
Howard Hinnantc51e1022010-05-11 19:42:16 +0000390 size_type count(const key_type& k) const;
391 iterator lower_bound(const key_type& k);
392 const_iterator lower_bound(const key_type& k) const;
Marshall Clowebb57322013-08-13 22:18:47 +0000393 template<typename K>
394 iterator lower_bound(const K& x); // C++14
395 template<typename K>
396 const_iterator lower_bound(const K& x) const; // C++14
397
Howard Hinnantc51e1022010-05-11 19:42:16 +0000398 iterator upper_bound(const key_type& k);
399 const_iterator upper_bound(const key_type& k) const;
Marshall Clowebb57322013-08-13 22:18:47 +0000400 template<typename K>
401 iterator upper_bound(const K& x); // C++14
402 template<typename K>
403 const_iterator upper_bound(const K& x) const; // C++14
404
Howard Hinnantc51e1022010-05-11 19:42:16 +0000405 pair<iterator,iterator> equal_range(const key_type& k);
406 pair<const_iterator,const_iterator> equal_range(const key_type& k) const;
Marshall Clowebb57322013-08-13 22:18:47 +0000407 template<typename K>
408 pair<iterator,iterator> equal_range(const K& x); // C++14
409 template<typename K>
410 pair<const_iterator,const_iterator> equal_range(const K& x) const; // C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000411};
412
413template <class Key, class T, class Compare, class Allocator>
414bool
415operator==(const multimap<Key, T, Compare, Allocator>& x,
416 const multimap<Key, T, Compare, Allocator>& y);
417
418template <class Key, class T, class Compare, class Allocator>
419bool
420operator< (const multimap<Key, T, Compare, Allocator>& x,
421 const multimap<Key, T, Compare, Allocator>& y);
422
423template <class Key, class T, class Compare, class Allocator>
424bool
425operator!=(const multimap<Key, T, Compare, Allocator>& x,
426 const multimap<Key, T, Compare, Allocator>& y);
427
428template <class Key, class T, class Compare, class Allocator>
429bool
430operator> (const multimap<Key, T, Compare, Allocator>& x,
431 const multimap<Key, T, Compare, Allocator>& y);
432
433template <class Key, class T, class Compare, class Allocator>
434bool
435operator>=(const multimap<Key, T, Compare, Allocator>& x,
436 const multimap<Key, T, Compare, Allocator>& y);
437
438template <class Key, class T, class Compare, class Allocator>
439bool
440operator<=(const multimap<Key, T, Compare, Allocator>& x,
441 const multimap<Key, T, Compare, Allocator>& y);
442
443// specialized algorithms:
444template <class Key, class T, class Compare, class Allocator>
445void
446swap(multimap<Key, T, Compare, Allocator>& x,
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000447 multimap<Key, T, Compare, Allocator>& y)
448 noexcept(noexcept(x.swap(y)));
Howard Hinnantc51e1022010-05-11 19:42:16 +0000449
450} // std
451
452*/
453
454#include <__config>
455#include <__tree>
Erik Pilkingtonc37a3d82018-08-01 01:33:38 +0000456#include <__node_handle>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000457#include <iterator>
458#include <memory>
459#include <utility>
460#include <functional>
461#include <initializer_list>
Eric Fiselierf7394302015-06-13 07:08:02 +0000462#include <type_traits>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000463
Howard Hinnantaaaa52b2011-10-17 20:05:10 +0000464#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000465#pragma GCC system_header
Howard Hinnantaaaa52b2011-10-17 20:05:10 +0000466#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000467
468_LIBCPP_BEGIN_NAMESPACE_STD
469
Eric Fiseliera7a14ed2017-01-13 22:02:08 +0000470template <class _Key, class _CP, class _Compare, bool _IsSmall>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000471class __map_value_compare
472 : private _Compare
473{
Howard Hinnantc51e1022010-05-11 19:42:16 +0000474public:
Howard Hinnant756c69b2010-09-22 16:48:34 +0000475 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000476 __map_value_compare()
477 _NOEXCEPT_(is_nothrow_default_constructible<_Compare>::value)
478 : _Compare() {}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000479 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000480 __map_value_compare(_Compare c)
481 _NOEXCEPT_(is_nothrow_copy_constructible<_Compare>::value)
482 : _Compare(c) {}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000483 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000484 const _Compare& key_comp() const _NOEXCEPT {return *this;}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000485 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000486 bool operator()(const _CP& __x, const _CP& __y) const
Erik Pilkingtond3fe2992018-06-04 20:38:23 +0000487 {return static_cast<const _Compare&>(*this)(__x.__get_value().first, __y.__get_value().first);}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000488 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000489 bool operator()(const _CP& __x, const _Key& __y) const
Erik Pilkingtond3fe2992018-06-04 20:38:23 +0000490 {return static_cast<const _Compare&>(*this)(__x.__get_value().first, __y);}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000491 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000492 bool operator()(const _Key& __x, const _CP& __y) const
Erik Pilkingtond3fe2992018-06-04 20:38:23 +0000493 {return static_cast<const _Compare&>(*this)(__x, __y.__get_value().first);}
Marshall Clow8982dcd2015-07-13 20:04:56 +0000494 void swap(__map_value_compare&__y)
495 _NOEXCEPT_(__is_nothrow_swappable<_Compare>::value)
496 {
Eric Fiselier68b5f0b2017-04-13 00:34:24 +0000497 using _VSTD::swap;
498 swap(static_cast<_Compare&>(*this), static_cast<_Compare&>(__y));
Marshall Clow8982dcd2015-07-13 20:04:56 +0000499 }
Marshall Clowebb57322013-08-13 22:18:47 +0000500
501#if _LIBCPP_STD_VER > 11
502 template <typename _K2>
503 _LIBCPP_INLINE_VISIBILITY
504 typename enable_if<__is_transparent<_Compare, _K2>::value, bool>::type
505 operator () ( const _K2& __x, const _CP& __y ) const
Erik Pilkingtond3fe2992018-06-04 20:38:23 +0000506 {return static_cast<const _Compare&>(*this) (__x, __y.__get_value().first);}
Marshall Clowebb57322013-08-13 22:18:47 +0000507
508 template <typename _K2>
509 _LIBCPP_INLINE_VISIBILITY
510 typename enable_if<__is_transparent<_Compare, _K2>::value, bool>::type
511 operator () (const _CP& __x, const _K2& __y) const
Erik Pilkingtond3fe2992018-06-04 20:38:23 +0000512 {return static_cast<const _Compare&>(*this) (__x.__get_value().first, __y);}
Marshall Clowebb57322013-08-13 22:18:47 +0000513#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000514};
515
Howard Hinnant90b91592013-07-05 18:06:00 +0000516template <class _Key, class _CP, class _Compare>
517class __map_value_compare<_Key, _CP, _Compare, false>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000518{
519 _Compare comp;
520
Howard Hinnantc51e1022010-05-11 19:42:16 +0000521public:
Howard Hinnant756c69b2010-09-22 16:48:34 +0000522 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000523 __map_value_compare()
524 _NOEXCEPT_(is_nothrow_default_constructible<_Compare>::value)
525 : comp() {}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000526 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000527 __map_value_compare(_Compare c)
528 _NOEXCEPT_(is_nothrow_copy_constructible<_Compare>::value)
529 : comp(c) {}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000530 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000531 const _Compare& key_comp() const _NOEXCEPT {return comp;}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000532
Howard Hinnant756c69b2010-09-22 16:48:34 +0000533 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000534 bool operator()(const _CP& __x, const _CP& __y) const
Erik Pilkingtond3fe2992018-06-04 20:38:23 +0000535 {return comp(__x.__get_value().first, __y.__get_value().first);}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000536 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000537 bool operator()(const _CP& __x, const _Key& __y) const
Erik Pilkingtond3fe2992018-06-04 20:38:23 +0000538 {return comp(__x.__get_value().first, __y);}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000539 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000540 bool operator()(const _Key& __x, const _CP& __y) const
Erik Pilkingtond3fe2992018-06-04 20:38:23 +0000541 {return comp(__x, __y.__get_value().first);}
Marshall Clow8982dcd2015-07-13 20:04:56 +0000542 void swap(__map_value_compare&__y)
543 _NOEXCEPT_(__is_nothrow_swappable<_Compare>::value)
544 {
545 using _VSTD::swap;
546 swap(comp, __y.comp);
547 }
Eric Fiseliercf8c0212017-01-05 06:06:18 +0000548
Marshall Clowebb57322013-08-13 22:18:47 +0000549#if _LIBCPP_STD_VER > 11
550 template <typename _K2>
551 _LIBCPP_INLINE_VISIBILITY
552 typename enable_if<__is_transparent<_Compare, _K2>::value, bool>::type
553 operator () ( const _K2& __x, const _CP& __y ) const
Erik Pilkingtond3fe2992018-06-04 20:38:23 +0000554 {return comp (__x, __y.__get_value().first);}
Marshall Clowebb57322013-08-13 22:18:47 +0000555
556 template <typename _K2>
557 _LIBCPP_INLINE_VISIBILITY
558 typename enable_if<__is_transparent<_Compare, _K2>::value, bool>::type
559 operator () (const _CP& __x, const _K2& __y) const
Erik Pilkingtond3fe2992018-06-04 20:38:23 +0000560 {return comp (__x.__get_value().first, __y);}
Marshall Clowebb57322013-08-13 22:18:47 +0000561#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000562};
563
Marshall Clow8982dcd2015-07-13 20:04:56 +0000564template <class _Key, class _CP, class _Compare, bool __b>
565inline _LIBCPP_INLINE_VISIBILITY
566void
567swap(__map_value_compare<_Key, _CP, _Compare, __b>& __x,
568 __map_value_compare<_Key, _CP, _Compare, __b>& __y)
569 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
570{
571 __x.swap(__y);
572}
573
Howard Hinnantc51e1022010-05-11 19:42:16 +0000574template <class _Allocator>
575class __map_node_destructor
576{
577 typedef _Allocator allocator_type;
578 typedef allocator_traits<allocator_type> __alloc_traits;
Eric Fiseliera00b4842016-02-20 05:28:30 +0000579
Howard Hinnantc51e1022010-05-11 19:42:16 +0000580public:
581 typedef typename __alloc_traits::pointer pointer;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000582
Eric Fiseliera00b4842016-02-20 05:28:30 +0000583private:
Howard Hinnantc51e1022010-05-11 19:42:16 +0000584 allocator_type& __na_;
585
586 __map_node_destructor& operator=(const __map_node_destructor&);
587
588public:
589 bool __first_constructed;
590 bool __second_constructed;
591
Howard Hinnant756c69b2010-09-22 16:48:34 +0000592 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000593 explicit __map_node_destructor(allocator_type& __na) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +0000594 : __na_(__na),
595 __first_constructed(false),
596 __second_constructed(false)
597 {}
598
Eric Fiseliera85b1282017-04-18 21:08:06 +0000599#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant756c69b2010-09-22 16:48:34 +0000600 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000601 __map_node_destructor(__tree_node_destructor<allocator_type>&& __x) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +0000602 : __na_(__x.__na_),
603 __first_constructed(__x.__value_constructed),
604 __second_constructed(__x.__value_constructed)
605 {
606 __x.__value_constructed = false;
607 }
Eric Fiseliera85b1282017-04-18 21:08:06 +0000608#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000609
Howard Hinnant756c69b2010-09-22 16:48:34 +0000610 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000611 void operator()(pointer __p) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +0000612 {
613 if (__second_constructed)
Erik Pilkingtond3fe2992018-06-04 20:38:23 +0000614 __alloc_traits::destroy(__na_, _VSTD::addressof(__p->__value_.__get_value().second));
Howard Hinnantc51e1022010-05-11 19:42:16 +0000615 if (__first_constructed)
Erik Pilkingtond3fe2992018-06-04 20:38:23 +0000616 __alloc_traits::destroy(__na_, _VSTD::addressof(__p->__value_.__get_value().first));
Howard Hinnantc51e1022010-05-11 19:42:16 +0000617 if (__p)
618 __alloc_traits::deallocate(__na_, __p, 1);
619 }
620};
621
Howard Hinnant944510a2011-06-14 19:58:17 +0000622template <class _Key, class _Tp, class _Compare, class _Allocator>
623 class map;
624template <class _Key, class _Tp, class _Compare, class _Allocator>
625 class multimap;
626template <class _TreeIterator> class __map_const_iterator;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000627
Eric Fiseliera00b4842016-02-20 05:28:30 +0000628#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant89f8b792013-09-30 19:08:22 +0000629
630template <class _Key, class _Tp>
Erik Pilkingtond3fe2992018-06-04 20:38:23 +0000631struct __value_type
Howard Hinnant89f8b792013-09-30 19:08:22 +0000632{
633 typedef _Key key_type;
634 typedef _Tp mapped_type;
635 typedef pair<const key_type, mapped_type> value_type;
Erik Pilkingtond3fe2992018-06-04 20:38:23 +0000636 typedef pair<key_type&, mapped_type&> __nc_ref_pair_type;
637 typedef pair<key_type&&, mapped_type&&> __nc_rref_pair_type;
Howard Hinnant89f8b792013-09-30 19:08:22 +0000638
Erik Pilkingtond3fe2992018-06-04 20:38:23 +0000639private:
Howard Hinnant89f8b792013-09-30 19:08:22 +0000640 value_type __cc;
Erik Pilkingtond3fe2992018-06-04 20:38:23 +0000641
642public:
643 _LIBCPP_INLINE_VISIBILITY
644 value_type& __get_value()
645 {
646#if _LIBCPP_STD_VER > 14
647 return *_VSTD::launder(_VSTD::addressof(__cc));
648#else
649 return __cc;
650#endif
651 }
652
653 _LIBCPP_INLINE_VISIBILITY
654 const value_type& __get_value() const
655 {
656#if _LIBCPP_STD_VER > 14
657 return *_VSTD::launder(_VSTD::addressof(__cc));
658#else
659 return __cc;
660#endif
661 }
662
663 _LIBCPP_INLINE_VISIBILITY
664 __nc_ref_pair_type __ref()
665 {
666 value_type& __v = __get_value();
667 return __nc_ref_pair_type(const_cast<key_type&>(__v.first), __v.second);
668 }
669
670 _LIBCPP_INLINE_VISIBILITY
671 __nc_rref_pair_type __move()
672 {
673 value_type& __v = __get_value();
674 return __nc_rref_pair_type(
675 _VSTD::move(const_cast<key_type&>(__v.first)),
676 _VSTD::move(__v.second));
677 }
Howard Hinnant89f8b792013-09-30 19:08:22 +0000678
Howard Hinnant89f8b792013-09-30 19:08:22 +0000679 _LIBCPP_INLINE_VISIBILITY
680 __value_type& operator=(const __value_type& __v)
Erik Pilkingtond3fe2992018-06-04 20:38:23 +0000681 {
682 __ref() = __v.__get_value();
683 return *this;
684 }
Howard Hinnant89f8b792013-09-30 19:08:22 +0000685
686 _LIBCPP_INLINE_VISIBILITY
687 __value_type& operator=(__value_type&& __v)
Erik Pilkingtond3fe2992018-06-04 20:38:23 +0000688 {
689 __ref() = __v.__move();
690 return *this;
691 }
Howard Hinnant89f8b792013-09-30 19:08:22 +0000692
Eric Fiselierd06276b2016-03-31 02:15:15 +0000693 template <class _ValueTp,
694 class = typename enable_if<
695 __is_same_uncvref<_ValueTp, value_type>::value
696 >::type
697 >
Howard Hinnant89f8b792013-09-30 19:08:22 +0000698 _LIBCPP_INLINE_VISIBILITY
Erik Pilkingtond3fe2992018-06-04 20:38:23 +0000699 __value_type& operator=(_ValueTp&& __v)
700 {
701 __ref() = _VSTD::forward<_ValueTp>(__v);
702 return *this;
Eric Fiselierd06276b2016-03-31 02:15:15 +0000703 }
704
705private:
706 __value_type() _LIBCPP_EQUAL_DELETE;
707 ~__value_type() _LIBCPP_EQUAL_DELETE;
708 __value_type(const __value_type& __v) _LIBCPP_EQUAL_DELETE;
709 __value_type(__value_type&& __v) _LIBCPP_EQUAL_DELETE;
Howard Hinnant89f8b792013-09-30 19:08:22 +0000710};
711
712#else
713
714template <class _Key, class _Tp>
715struct __value_type
716{
717 typedef _Key key_type;
718 typedef _Tp mapped_type;
719 typedef pair<const key_type, mapped_type> value_type;
720
Erik Pilkingtond3fe2992018-06-04 20:38:23 +0000721private:
Howard Hinnant89f8b792013-09-30 19:08:22 +0000722 value_type __cc;
723
Erik Pilkingtond3fe2992018-06-04 20:38:23 +0000724public:
725 _LIBCPP_INLINE_VISIBILITY
726 value_type& __get_value() { return __cc; }
727 _LIBCPP_INLINE_VISIBILITY
728 const value_type& __get_value() const { return __cc; }
729
Eric Fiselierd06276b2016-03-31 02:15:15 +0000730private:
731 __value_type();
732 __value_type(__value_type const&);
733 __value_type& operator=(__value_type const&);
734 ~__value_type();
Howard Hinnant89f8b792013-09-30 19:08:22 +0000735};
736
Eric Fiseliera85b1282017-04-18 21:08:06 +0000737#endif // _LIBCPP_CXX03_LANG
Howard Hinnant89f8b792013-09-30 19:08:22 +0000738
Eric Fiselier44f9fd02015-03-03 20:10:01 +0000739template <class _Tp>
740struct __extract_key_value_types;
741
742template <class _Key, class _Tp>
743struct __extract_key_value_types<__value_type<_Key, _Tp> >
744{
745 typedef _Key const __key_type;
746 typedef _Tp __mapped_type;
747};
748
Howard Hinnantc51e1022010-05-11 19:42:16 +0000749template <class _TreeIterator>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000750class _LIBCPP_TEMPLATE_VIS __map_iterator
Howard Hinnantc51e1022010-05-11 19:42:16 +0000751{
Eric Fiseliera00b4842016-02-20 05:28:30 +0000752 typedef typename _TreeIterator::_NodeTypes _NodeTypes;
753 typedef typename _TreeIterator::__pointer_traits __pointer_traits;
754
Howard Hinnantc51e1022010-05-11 19:42:16 +0000755 _TreeIterator __i_;
756
Howard Hinnantc51e1022010-05-11 19:42:16 +0000757public:
758 typedef bidirectional_iterator_tag iterator_category;
Eric Fiseliera00b4842016-02-20 05:28:30 +0000759 typedef typename _NodeTypes::__map_value_type value_type;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000760 typedef typename _TreeIterator::difference_type difference_type;
761 typedef value_type& reference;
Eric Fiseliera00b4842016-02-20 05:28:30 +0000762 typedef typename _NodeTypes::__map_value_type_pointer pointer;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000763
Howard Hinnant756c69b2010-09-22 16:48:34 +0000764 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000765 __map_iterator() _NOEXCEPT {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000766
Howard Hinnant756c69b2010-09-22 16:48:34 +0000767 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000768 __map_iterator(_TreeIterator __i) _NOEXCEPT : __i_(__i) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000769
Howard Hinnant756c69b2010-09-22 16:48:34 +0000770 _LIBCPP_INLINE_VISIBILITY
Erik Pilkingtond3fe2992018-06-04 20:38:23 +0000771 reference operator*() const {return __i_->__get_value();}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000772 _LIBCPP_INLINE_VISIBILITY
Erik Pilkingtond3fe2992018-06-04 20:38:23 +0000773 pointer operator->() const {return pointer_traits<pointer>::pointer_to(__i_->__get_value());}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000774
Howard Hinnant756c69b2010-09-22 16:48:34 +0000775 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000776 __map_iterator& operator++() {++__i_; return *this;}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000777 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000778 __map_iterator operator++(int)
779 {
780 __map_iterator __t(*this);
781 ++(*this);
782 return __t;
783 }
784
Howard Hinnant756c69b2010-09-22 16:48:34 +0000785 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000786 __map_iterator& operator--() {--__i_; return *this;}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000787 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000788 __map_iterator operator--(int)
789 {
790 __map_iterator __t(*this);
791 --(*this);
792 return __t;
793 }
794
Howard Hinnant756c69b2010-09-22 16:48:34 +0000795 friend _LIBCPP_INLINE_VISIBILITY
796 bool operator==(const __map_iterator& __x, const __map_iterator& __y)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000797 {return __x.__i_ == __y.__i_;}
Eric Fiseliercf8c0212017-01-05 06:06:18 +0000798 friend
Howard Hinnant756c69b2010-09-22 16:48:34 +0000799 _LIBCPP_INLINE_VISIBILITY
800 bool operator!=(const __map_iterator& __x, const __map_iterator& __y)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000801 {return __x.__i_ != __y.__i_;}
802
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000803 template <class, class, class, class> friend class _LIBCPP_TEMPLATE_VIS map;
804 template <class, class, class, class> friend class _LIBCPP_TEMPLATE_VIS multimap;
805 template <class> friend class _LIBCPP_TEMPLATE_VIS __map_const_iterator;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000806};
807
808template <class _TreeIterator>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000809class _LIBCPP_TEMPLATE_VIS __map_const_iterator
Howard Hinnantc51e1022010-05-11 19:42:16 +0000810{
Eric Fiseliera00b4842016-02-20 05:28:30 +0000811 typedef typename _TreeIterator::_NodeTypes _NodeTypes;
812 typedef typename _TreeIterator::__pointer_traits __pointer_traits;
813
Howard Hinnantc51e1022010-05-11 19:42:16 +0000814 _TreeIterator __i_;
815
Howard Hinnantc51e1022010-05-11 19:42:16 +0000816public:
817 typedef bidirectional_iterator_tag iterator_category;
Eric Fiseliera00b4842016-02-20 05:28:30 +0000818 typedef typename _NodeTypes::__map_value_type value_type;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000819 typedef typename _TreeIterator::difference_type difference_type;
820 typedef const value_type& reference;
Eric Fiseliera00b4842016-02-20 05:28:30 +0000821 typedef typename _NodeTypes::__const_map_value_type_pointer pointer;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000822
Howard Hinnant756c69b2010-09-22 16:48:34 +0000823 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000824 __map_const_iterator() _NOEXCEPT {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000825
Howard Hinnant756c69b2010-09-22 16:48:34 +0000826 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000827 __map_const_iterator(_TreeIterator __i) _NOEXCEPT : __i_(__i) {}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000828 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier44f9fd02015-03-03 20:10:01 +0000829 __map_const_iterator(__map_iterator<
830 typename _TreeIterator::__non_const_iterator> __i) _NOEXCEPT
831 : __i_(__i.__i_) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000832
Howard Hinnant756c69b2010-09-22 16:48:34 +0000833 _LIBCPP_INLINE_VISIBILITY
Erik Pilkingtond3fe2992018-06-04 20:38:23 +0000834 reference operator*() const {return __i_->__get_value();}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000835 _LIBCPP_INLINE_VISIBILITY
Erik Pilkingtond3fe2992018-06-04 20:38:23 +0000836 pointer operator->() const {return pointer_traits<pointer>::pointer_to(__i_->__get_value());}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000837
Howard Hinnant756c69b2010-09-22 16:48:34 +0000838 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000839 __map_const_iterator& operator++() {++__i_; return *this;}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000840 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000841 __map_const_iterator operator++(int)
842 {
843 __map_const_iterator __t(*this);
844 ++(*this);
845 return __t;
846 }
847
Howard Hinnant756c69b2010-09-22 16:48:34 +0000848 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000849 __map_const_iterator& operator--() {--__i_; return *this;}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000850 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000851 __map_const_iterator operator--(int)
852 {
853 __map_const_iterator __t(*this);
854 --(*this);
855 return __t;
856 }
857
Howard Hinnant756c69b2010-09-22 16:48:34 +0000858 friend _LIBCPP_INLINE_VISIBILITY
859 bool operator==(const __map_const_iterator& __x, const __map_const_iterator& __y)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000860 {return __x.__i_ == __y.__i_;}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000861 friend _LIBCPP_INLINE_VISIBILITY
862 bool operator!=(const __map_const_iterator& __x, const __map_const_iterator& __y)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000863 {return __x.__i_ != __y.__i_;}
864
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000865 template <class, class, class, class> friend class _LIBCPP_TEMPLATE_VIS map;
866 template <class, class, class, class> friend class _LIBCPP_TEMPLATE_VIS multimap;
867 template <class, class, class> friend class _LIBCPP_TEMPLATE_VIS __tree_const_iterator;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000868};
869
870template <class _Key, class _Tp, class _Compare = less<_Key>,
871 class _Allocator = allocator<pair<const _Key, _Tp> > >
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000872class _LIBCPP_TEMPLATE_VIS map
Howard Hinnantc51e1022010-05-11 19:42:16 +0000873{
874public:
875 // types:
876 typedef _Key key_type;
877 typedef _Tp mapped_type;
878 typedef pair<const key_type, mapped_type> value_type;
879 typedef _Compare key_compare;
880 typedef _Allocator allocator_type;
881 typedef value_type& reference;
882 typedef const value_type& const_reference;
883
Marshall Clow5128cf32015-11-26 01:24:04 +0000884 static_assert((is_same<typename allocator_type::value_type, value_type>::value),
885 "Allocator::value_type must be same type as value_type");
886
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000887 class _LIBCPP_TEMPLATE_VIS value_compare
Howard Hinnantc51e1022010-05-11 19:42:16 +0000888 : public binary_function<value_type, value_type, bool>
889 {
890 friend class map;
891 protected:
892 key_compare comp;
893
Howard Hinnant756c69b2010-09-22 16:48:34 +0000894 _LIBCPP_INLINE_VISIBILITY value_compare(key_compare c) : comp(c) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000895 public:
Howard Hinnant756c69b2010-09-22 16:48:34 +0000896 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000897 bool operator()(const value_type& __x, const value_type& __y) const
898 {return comp(__x.first, __y.first);}
899 };
900
901private:
Howard Hinnant2d0046b2013-06-19 21:29:40 +0000902
Howard Hinnant89f8b792013-09-30 19:08:22 +0000903 typedef _VSTD::__value_type<key_type, mapped_type> __value_type;
Howard Hinnant90b91592013-07-05 18:06:00 +0000904 typedef __map_value_compare<key_type, __value_type, key_compare> __vc;
Marshall Clow940e01c2015-04-07 05:21:38 +0000905 typedef typename __rebind_alloc_helper<allocator_traits<allocator_type>,
906 __value_type>::type __allocator_type;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000907 typedef __tree<__value_type, __vc, __allocator_type> __base;
908 typedef typename __base::__node_traits __node_traits;
909 typedef allocator_traits<allocator_type> __alloc_traits;
910
911 __base __tree_;
912
913public:
914 typedef typename __alloc_traits::pointer pointer;
915 typedef typename __alloc_traits::const_pointer const_pointer;
916 typedef typename __alloc_traits::size_type size_type;
917 typedef typename __alloc_traits::difference_type difference_type;
Eric Fiselier44f9fd02015-03-03 20:10:01 +0000918 typedef __map_iterator<typename __base::iterator> iterator;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000919 typedef __map_const_iterator<typename __base::const_iterator> const_iterator;
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000920 typedef _VSTD::reverse_iterator<iterator> reverse_iterator;
921 typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000922
Erik Pilkingtonc37a3d82018-08-01 01:33:38 +0000923#if _LIBCPP_STD_VER > 14
924 typedef __map_node_handle<typename __base::__node, allocator_type> node_type;
925 typedef __insert_return_type<iterator, node_type> insert_return_type;
926#endif
927
Howard Hinnant756c69b2010-09-22 16:48:34 +0000928 _LIBCPP_INLINE_VISIBILITY
Marshall Clow7086a5a2014-03-10 04:50:10 +0000929 map()
930 _NOEXCEPT_(
931 is_nothrow_default_constructible<allocator_type>::value &&
932 is_nothrow_default_constructible<key_compare>::value &&
933 is_nothrow_copy_constructible<key_compare>::value)
934 : __tree_(__vc(key_compare())) {}
935
936 _LIBCPP_INLINE_VISIBILITY
937 explicit map(const key_compare& __comp)
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000938 _NOEXCEPT_(
939 is_nothrow_default_constructible<allocator_type>::value &&
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000940 is_nothrow_copy_constructible<key_compare>::value)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000941 : __tree_(__vc(__comp)) {}
942
Howard Hinnant756c69b2010-09-22 16:48:34 +0000943 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000944 explicit map(const key_compare& __comp, const allocator_type& __a)
Marshall Clow657cbc42016-08-17 05:58:40 +0000945 : __tree_(__vc(__comp), typename __base::allocator_type(__a)) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000946
947 template <class _InputIterator>
Howard Hinnant756c69b2010-09-22 16:48:34 +0000948 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000949 map(_InputIterator __f, _InputIterator __l,
950 const key_compare& __comp = key_compare())
951 : __tree_(__vc(__comp))
952 {
953 insert(__f, __l);
954 }
955
956 template <class _InputIterator>
Howard Hinnant756c69b2010-09-22 16:48:34 +0000957 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000958 map(_InputIterator __f, _InputIterator __l,
959 const key_compare& __comp, const allocator_type& __a)
Marshall Clow657cbc42016-08-17 05:58:40 +0000960 : __tree_(__vc(__comp), typename __base::allocator_type(__a))
Howard Hinnantc51e1022010-05-11 19:42:16 +0000961 {
962 insert(__f, __l);
963 }
964
Marshall Clow300abfb2013-09-11 01:15:47 +0000965#if _LIBCPP_STD_VER > 11
966 template <class _InputIterator>
Eric Fiseliercf8c0212017-01-05 06:06:18 +0000967 _LIBCPP_INLINE_VISIBILITY
Marshall Clow300abfb2013-09-11 01:15:47 +0000968 map(_InputIterator __f, _InputIterator __l, const allocator_type& __a)
969 : map(__f, __l, key_compare(), __a) {}
970#endif
971
Howard Hinnant756c69b2010-09-22 16:48:34 +0000972 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000973 map(const map& __m)
974 : __tree_(__m.__tree_)
975 {
976 insert(__m.begin(), __m.end());
977 }
978
Howard Hinnantd3a657f2011-07-01 19:24:36 +0000979 _LIBCPP_INLINE_VISIBILITY
980 map& operator=(const map& __m)
981 {
Marshall Clow476d3f42016-07-18 13:19:00 +0000982#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantd3a657f2011-07-01 19:24:36 +0000983 __tree_ = __m.__tree_;
Howard Hinnant2d0046b2013-06-19 21:29:40 +0000984#else
Marshall Clowdb3cfcb2014-02-08 04:03:14 +0000985 if (this != &__m) {
986 __tree_.clear();
987 __tree_.value_comp() = __m.__tree_.value_comp();
988 __tree_.__copy_assign_alloc(__m.__tree_);
989 insert(__m.begin(), __m.end());
990 }
Howard Hinnant2d0046b2013-06-19 21:29:40 +0000991#endif
Howard Hinnantd3a657f2011-07-01 19:24:36 +0000992 return *this;
993 }
994
Eric Fiseliera85b1282017-04-18 21:08:06 +0000995#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000996
Howard Hinnant756c69b2010-09-22 16:48:34 +0000997 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000998 map(map&& __m)
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000999 _NOEXCEPT_(is_nothrow_move_constructible<__base>::value)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001000 : __tree_(_VSTD::move(__m.__tree_))
Howard Hinnantc51e1022010-05-11 19:42:16 +00001001 {
1002 }
1003
1004 map(map&& __m, const allocator_type& __a);
1005
Howard Hinnant756c69b2010-09-22 16:48:34 +00001006 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant33711792011-08-12 21:56:02 +00001007 map& operator=(map&& __m)
1008 _NOEXCEPT_(is_nothrow_move_assignable<__base>::value)
1009 {
1010 __tree_ = _VSTD::move(__m.__tree_);
1011 return *this;
1012 }
1013
Howard Hinnant33711792011-08-12 21:56:02 +00001014 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001015 map(initializer_list<value_type> __il, const key_compare& __comp = key_compare())
1016 : __tree_(__vc(__comp))
1017 {
1018 insert(__il.begin(), __il.end());
1019 }
1020
Howard Hinnant756c69b2010-09-22 16:48:34 +00001021 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001022 map(initializer_list<value_type> __il, const key_compare& __comp, const allocator_type& __a)
Marshall Clow657cbc42016-08-17 05:58:40 +00001023 : __tree_(__vc(__comp), typename __base::allocator_type(__a))
Howard Hinnantc51e1022010-05-11 19:42:16 +00001024 {
1025 insert(__il.begin(), __il.end());
1026 }
1027
Marshall Clow300abfb2013-09-11 01:15:47 +00001028#if _LIBCPP_STD_VER > 11
Eric Fiseliercf8c0212017-01-05 06:06:18 +00001029 _LIBCPP_INLINE_VISIBILITY
Marshall Clow300abfb2013-09-11 01:15:47 +00001030 map(initializer_list<value_type> __il, const allocator_type& __a)
1031 : map(__il, key_compare(), __a) {}
1032#endif
1033
Howard Hinnant756c69b2010-09-22 16:48:34 +00001034 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001035 map& operator=(initializer_list<value_type> __il)
1036 {
1037 __tree_.__assign_unique(__il.begin(), __il.end());
1038 return *this;
1039 }
1040
Eric Fiseliera85b1282017-04-18 21:08:06 +00001041#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001042
Howard Hinnant756c69b2010-09-22 16:48:34 +00001043 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001044 explicit map(const allocator_type& __a)
Marshall Clow657cbc42016-08-17 05:58:40 +00001045 : __tree_(typename __base::allocator_type(__a))
Howard Hinnantc51e1022010-05-11 19:42:16 +00001046 {
1047 }
1048
Howard Hinnant756c69b2010-09-22 16:48:34 +00001049 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001050 map(const map& __m, const allocator_type& __a)
Marshall Clow657cbc42016-08-17 05:58:40 +00001051 : __tree_(__m.__tree_.value_comp(), typename __base::allocator_type(__a))
Howard Hinnantc51e1022010-05-11 19:42:16 +00001052 {
1053 insert(__m.begin(), __m.end());
1054 }
1055
Howard Hinnant756c69b2010-09-22 16:48:34 +00001056 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001057 iterator begin() _NOEXCEPT {return __tree_.begin();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001058 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001059 const_iterator begin() const _NOEXCEPT {return __tree_.begin();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001060 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001061 iterator end() _NOEXCEPT {return __tree_.end();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001062 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001063 const_iterator end() const _NOEXCEPT {return __tree_.end();}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001064
Howard Hinnant756c69b2010-09-22 16:48:34 +00001065 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001066 reverse_iterator rbegin() _NOEXCEPT {return reverse_iterator(end());}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001067 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001068 const_reverse_iterator rbegin() const _NOEXCEPT
1069 {return const_reverse_iterator(end());}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001070 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001071 reverse_iterator rend() _NOEXCEPT
1072 {return reverse_iterator(begin());}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001073 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001074 const_reverse_iterator rend() const _NOEXCEPT
1075 {return const_reverse_iterator(begin());}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001076
Howard Hinnant756c69b2010-09-22 16:48:34 +00001077 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001078 const_iterator cbegin() const _NOEXCEPT {return begin();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001079 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001080 const_iterator cend() const _NOEXCEPT {return end();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001081 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001082 const_reverse_iterator crbegin() const _NOEXCEPT {return rbegin();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001083 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001084 const_reverse_iterator crend() const _NOEXCEPT {return rend();}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001085
Marshall Clow425f5752017-11-15 05:51:26 +00001086 _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001087 bool empty() const _NOEXCEPT {return __tree_.size() == 0;}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001088 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001089 size_type size() const _NOEXCEPT {return __tree_.size();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001090 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001091 size_type max_size() const _NOEXCEPT {return __tree_.max_size();}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001092
1093 mapped_type& operator[](const key_type& __k);
Eric Fiselierd63f38e2016-03-31 03:13:37 +00001094#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001095 mapped_type& operator[](key_type&& __k);
1096#endif
1097
1098 mapped_type& at(const key_type& __k);
1099 const mapped_type& at(const key_type& __k) const;
1100
Howard Hinnant756c69b2010-09-22 16:48:34 +00001101 _LIBCPP_INLINE_VISIBILITY
Marshall Clow657cbc42016-08-17 05:58:40 +00001102 allocator_type get_allocator() const _NOEXCEPT {return allocator_type(__tree_.__alloc());}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001103 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001104 key_compare key_comp() const {return __tree_.value_comp().key_comp();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001105 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001106 value_compare value_comp() const {return value_compare(__tree_.value_comp().key_comp());}
1107
Eric Fiselierd06276b2016-03-31 02:15:15 +00001108#ifndef _LIBCPP_CXX03_LANG
1109 template <class ..._Args>
1110 _LIBCPP_INLINE_VISIBILITY
1111 pair<iterator, bool> emplace(_Args&& ...__args) {
1112 return __tree_.__emplace_unique(_VSTD::forward<_Args>(__args)...);
1113 }
Howard Hinnant74279a52010-09-04 23:28:19 +00001114
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001115 template <class ..._Args>
Eric Fiselierd06276b2016-03-31 02:15:15 +00001116 _LIBCPP_INLINE_VISIBILITY
1117 iterator emplace_hint(const_iterator __p, _Args&& ...__args) {
1118 return __tree_.__emplace_hint_unique(__p.__i_, _VSTD::forward<_Args>(__args)...);
1119 }
Howard Hinnant74279a52010-09-04 23:28:19 +00001120
Howard Hinnantc834c512011-11-29 18:15:50 +00001121 template <class _Pp,
1122 class = typename enable_if<is_constructible<value_type, _Pp>::value>::type>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001123 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc834c512011-11-29 18:15:50 +00001124 pair<iterator, bool> insert(_Pp&& __p)
1125 {return __tree_.__insert_unique(_VSTD::forward<_Pp>(__p));}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001126
Howard Hinnantc834c512011-11-29 18:15:50 +00001127 template <class _Pp,
1128 class = typename enable_if<is_constructible<value_type, _Pp>::value>::type>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001129 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc834c512011-11-29 18:15:50 +00001130 iterator insert(const_iterator __pos, _Pp&& __p)
1131 {return __tree_.__insert_unique(__pos.__i_, _VSTD::forward<_Pp>(__p));}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001132
Eric Fiselierd06276b2016-03-31 02:15:15 +00001133#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001134
Howard Hinnant756c69b2010-09-22 16:48:34 +00001135 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001136 pair<iterator, bool>
1137 insert(const value_type& __v) {return __tree_.__insert_unique(__v);}
1138
Howard Hinnant756c69b2010-09-22 16:48:34 +00001139 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001140 iterator
1141 insert(const_iterator __p, const value_type& __v)
1142 {return __tree_.__insert_unique(__p.__i_, __v);}
1143
Eric Fiselierd6143132016-04-18 01:40:45 +00001144#ifndef _LIBCPP_CXX03_LANG
Marshall Clowd430d022016-01-05 19:32:41 +00001145 _LIBCPP_INLINE_VISIBILITY
1146 pair<iterator, bool>
Eric Fiselierd06276b2016-03-31 02:15:15 +00001147 insert(value_type&& __v) {return __tree_.__insert_unique(_VSTD::move(__v));}
Marshall Clowd430d022016-01-05 19:32:41 +00001148
1149 _LIBCPP_INLINE_VISIBILITY
Eric Fiselierd06276b2016-03-31 02:15:15 +00001150 iterator insert(const_iterator __p, value_type&& __v)
1151 {return __tree_.__insert_unique(__p.__i_, _VSTD::move(__v));}
Eric Fiseliera85b1282017-04-18 21:08:06 +00001152
1153 _LIBCPP_INLINE_VISIBILITY
1154 void insert(initializer_list<value_type> __il)
1155 {insert(__il.begin(), __il.end());}
Marshall Clowd430d022016-01-05 19:32:41 +00001156#endif
1157
Howard Hinnantc51e1022010-05-11 19:42:16 +00001158 template <class _InputIterator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001159 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001160 void insert(_InputIterator __f, _InputIterator __l)
1161 {
1162 for (const_iterator __e = cend(); __f != __l; ++__f)
1163 insert(__e.__i_, *__f);
1164 }
1165
Marshall Clow3223db82015-07-07 03:37:33 +00001166#if _LIBCPP_STD_VER > 14
Eric Fiselierd63f38e2016-03-31 03:13:37 +00001167
Marshall Clow3223db82015-07-07 03:37:33 +00001168 template <class... _Args>
1169 _LIBCPP_INLINE_VISIBILITY
1170 pair<iterator, bool> try_emplace(const key_type& __k, _Args&&... __args)
1171 {
Eric Fiselierd63f38e2016-03-31 03:13:37 +00001172 return __tree_.__emplace_unique_key_args(__k,
1173 _VSTD::piecewise_construct,
1174 _VSTD::forward_as_tuple(__k),
1175 _VSTD::forward_as_tuple(_VSTD::forward<_Args>(__args)...));
Marshall Clow3223db82015-07-07 03:37:33 +00001176 }
1177
1178 template <class... _Args>
1179 _LIBCPP_INLINE_VISIBILITY
1180 pair<iterator, bool> try_emplace(key_type&& __k, _Args&&... __args)
1181 {
Eric Fiselierd63f38e2016-03-31 03:13:37 +00001182 return __tree_.__emplace_unique_key_args(__k,
1183 _VSTD::piecewise_construct,
1184 _VSTD::forward_as_tuple(_VSTD::move(__k)),
1185 _VSTD::forward_as_tuple(_VSTD::forward<_Args>(__args)...));
Marshall Clow3223db82015-07-07 03:37:33 +00001186 }
1187
1188 template <class... _Args>
1189 _LIBCPP_INLINE_VISIBILITY
1190 iterator try_emplace(const_iterator __h, const key_type& __k, _Args&&... __args)
1191 {
Eric Fiselierd63f38e2016-03-31 03:13:37 +00001192 return __tree_.__emplace_hint_unique_key_args(__h.__i_, __k,
1193 _VSTD::piecewise_construct,
1194 _VSTD::forward_as_tuple(__k),
1195 _VSTD::forward_as_tuple(_VSTD::forward<_Args>(__args)...));
Marshall Clow3223db82015-07-07 03:37:33 +00001196 }
1197
1198 template <class... _Args>
1199 _LIBCPP_INLINE_VISIBILITY
1200 iterator try_emplace(const_iterator __h, key_type&& __k, _Args&&... __args)
1201 {
Eric Fiselierd63f38e2016-03-31 03:13:37 +00001202 return __tree_.__emplace_hint_unique_key_args(__h.__i_, __k,
1203 _VSTD::piecewise_construct,
1204 _VSTD::forward_as_tuple(_VSTD::move(__k)),
1205 _VSTD::forward_as_tuple(_VSTD::forward<_Args>(__args)...));
Marshall Clow3223db82015-07-07 03:37:33 +00001206 }
1207
1208 template <class _Vp>
1209 _LIBCPP_INLINE_VISIBILITY
1210 pair<iterator, bool> insert_or_assign(const key_type& __k, _Vp&& __v)
1211 {
1212 iterator __p = lower_bound(__k);
1213 if ( __p != end() && !key_comp()(__k, __p->first))
1214 {
1215 __p->second = _VSTD::forward<_Vp>(__v);
1216 return _VSTD::make_pair(__p, false);
1217 }
1218 return _VSTD::make_pair(emplace_hint(__p, __k, _VSTD::forward<_Vp>(__v)), true);
1219 }
Eric Fiselierd63f38e2016-03-31 03:13:37 +00001220
Marshall Clow3223db82015-07-07 03:37:33 +00001221 template <class _Vp>
1222 _LIBCPP_INLINE_VISIBILITY
1223 pair<iterator, bool> insert_or_assign(key_type&& __k, _Vp&& __v)
1224 {
1225 iterator __p = lower_bound(__k);
1226 if ( __p != end() && !key_comp()(__k, __p->first))
1227 {
1228 __p->second = _VSTD::forward<_Vp>(__v);
1229 return _VSTD::make_pair(__p, false);
1230 }
1231 return _VSTD::make_pair(emplace_hint(__p, _VSTD::move(__k), _VSTD::forward<_Vp>(__v)), true);
1232 }
1233
1234 template <class _Vp>
1235 _LIBCPP_INLINE_VISIBILITY
1236 iterator insert_or_assign(const_iterator __h, 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 __p;
1243 }
1244 return emplace_hint(__h, __k, _VSTD::forward<_Vp>(__v));
1245 }
1246
1247 template <class _Vp>
1248 _LIBCPP_INLINE_VISIBILITY
1249 iterator insert_or_assign(const_iterator __h, 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 __p;
1256 }
1257 return emplace_hint(__h, _VSTD::move(__k), _VSTD::forward<_Vp>(__v));
1258 }
Eric Fiselierd63f38e2016-03-31 03:13:37 +00001259
Eric Fiseliera85b1282017-04-18 21:08:06 +00001260#endif // _LIBCPP_STD_VER > 14
Marshall Clow3223db82015-07-07 03:37:33 +00001261
Howard Hinnant756c69b2010-09-22 16:48:34 +00001262 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001263 iterator erase(const_iterator __p) {return __tree_.erase(__p.__i_);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001264 _LIBCPP_INLINE_VISIBILITY
Marshall Clow22ea5b82015-05-10 13:35:00 +00001265 iterator erase(iterator __p) {return __tree_.erase(__p.__i_);}
1266 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001267 size_type erase(const key_type& __k)
1268 {return __tree_.__erase_unique(__k);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001269 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001270 iterator erase(const_iterator __f, const_iterator __l)
1271 {return __tree_.erase(__f.__i_, __l.__i_);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001272 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001273 void clear() _NOEXCEPT {__tree_.clear();}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001274
Erik Pilkingtonc37a3d82018-08-01 01:33:38 +00001275#if _LIBCPP_STD_VER > 14
1276 _LIBCPP_INLINE_VISIBILITY
1277 insert_return_type insert(node_type&& __nh)
1278 {
1279 _LIBCPP_ASSERT(__nh.empty() || __nh.get_allocator() == get_allocator(),
1280 "node_type with incompatible allocator passed to map::insert()");
1281 return __tree_.template __node_handle_insert_unique<
1282 node_type, insert_return_type>(_VSTD::move(__nh));
1283 }
1284 _LIBCPP_INLINE_VISIBILITY
1285 iterator insert(const_iterator __hint, node_type&& __nh)
1286 {
1287 _LIBCPP_ASSERT(__nh.empty() || __nh.get_allocator() == get_allocator(),
1288 "node_type with incompatible allocator passed to map::insert()");
1289 return __tree_.template __node_handle_insert_unique<node_type>(
1290 __hint.__i_, _VSTD::move(__nh));
1291 }
1292 _LIBCPP_INLINE_VISIBILITY
1293 node_type extract(key_type const& __key)
1294 {
1295 return __tree_.template __node_handle_extract<node_type>(__key);
1296 }
1297 _LIBCPP_INLINE_VISIBILITY
1298 node_type extract(const_iterator __it)
1299 {
1300 return __tree_.template __node_handle_extract<node_type>(__it.__i_);
1301 }
1302#endif
1303
Howard Hinnant756c69b2010-09-22 16:48:34 +00001304 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001305 void swap(map& __m)
1306 _NOEXCEPT_(__is_nothrow_swappable<__base>::value)
1307 {__tree_.swap(__m.__tree_);}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001308
Howard Hinnant756c69b2010-09-22 16:48:34 +00001309 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001310 iterator find(const key_type& __k) {return __tree_.find(__k);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001311 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001312 const_iterator find(const key_type& __k) const {return __tree_.find(__k);}
Marshall Clowebb57322013-08-13 22:18:47 +00001313#if _LIBCPP_STD_VER > 11
1314 template <typename _K2>
1315 _LIBCPP_INLINE_VISIBILITY
1316 typename enable_if<__is_transparent<_Compare, _K2>::value,iterator>::type
1317 find(const _K2& __k) {return __tree_.find(__k);}
1318 template <typename _K2>
1319 _LIBCPP_INLINE_VISIBILITY
1320 typename enable_if<__is_transparent<_Compare, _K2>::value,const_iterator>::type
1321 find(const _K2& __k) const {return __tree_.find(__k);}
1322#endif
1323
Howard Hinnant756c69b2010-09-22 16:48:34 +00001324 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001325 size_type count(const key_type& __k) const
1326 {return __tree_.__count_unique(__k);}
Marshall Clowe6a5f522014-08-24 23:54:16 +00001327#if _LIBCPP_STD_VER > 11
1328 template <typename _K2>
1329 _LIBCPP_INLINE_VISIBILITY
1330 typename enable_if<__is_transparent<_Compare, _K2>::value,size_type>::type
Eric Fiseliera85c9e92018-02-10 02:53:47 +00001331 count(const _K2& __k) const {return __tree_.__count_multi(__k);}
Marshall Clowe6a5f522014-08-24 23:54:16 +00001332#endif
Howard Hinnant756c69b2010-09-22 16:48:34 +00001333 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001334 iterator lower_bound(const key_type& __k)
1335 {return __tree_.lower_bound(__k);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001336 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001337 const_iterator lower_bound(const key_type& __k) const
1338 {return __tree_.lower_bound(__k);}
Marshall Clowebb57322013-08-13 22:18:47 +00001339#if _LIBCPP_STD_VER > 11
1340 template <typename _K2>
1341 _LIBCPP_INLINE_VISIBILITY
1342 typename enable_if<__is_transparent<_Compare, _K2>::value,iterator>::type
1343 lower_bound(const _K2& __k) {return __tree_.lower_bound(__k);}
1344
1345 template <typename _K2>
1346 _LIBCPP_INLINE_VISIBILITY
1347 typename enable_if<__is_transparent<_Compare, _K2>::value,const_iterator>::type
1348 lower_bound(const _K2& __k) const {return __tree_.lower_bound(__k);}
1349#endif
1350
Howard Hinnant756c69b2010-09-22 16:48:34 +00001351 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001352 iterator upper_bound(const key_type& __k)
1353 {return __tree_.upper_bound(__k);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001354 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001355 const_iterator upper_bound(const key_type& __k) const
1356 {return __tree_.upper_bound(__k);}
Marshall Clowebb57322013-08-13 22:18:47 +00001357#if _LIBCPP_STD_VER > 11
1358 template <typename _K2>
1359 _LIBCPP_INLINE_VISIBILITY
1360 typename enable_if<__is_transparent<_Compare, _K2>::value,iterator>::type
1361 upper_bound(const _K2& __k) {return __tree_.upper_bound(__k);}
1362 template <typename _K2>
1363 _LIBCPP_INLINE_VISIBILITY
1364 typename enable_if<__is_transparent<_Compare, _K2>::value,const_iterator>::type
1365 upper_bound(const _K2& __k) const {return __tree_.upper_bound(__k);}
1366#endif
1367
Howard Hinnant756c69b2010-09-22 16:48:34 +00001368 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001369 pair<iterator,iterator> equal_range(const key_type& __k)
1370 {return __tree_.__equal_range_unique(__k);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001371 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001372 pair<const_iterator,const_iterator> equal_range(const key_type& __k) const
1373 {return __tree_.__equal_range_unique(__k);}
Marshall Clowebb57322013-08-13 22:18:47 +00001374#if _LIBCPP_STD_VER > 11
1375 template <typename _K2>
1376 _LIBCPP_INLINE_VISIBILITY
1377 typename enable_if<__is_transparent<_Compare, _K2>::value,pair<iterator,iterator>>::type
Eric Fiseliera85c9e92018-02-10 02:53:47 +00001378 equal_range(const _K2& __k) {return __tree_.__equal_range_multi(__k);}
Marshall Clowebb57322013-08-13 22:18:47 +00001379 template <typename _K2>
1380 _LIBCPP_INLINE_VISIBILITY
1381 typename enable_if<__is_transparent<_Compare, _K2>::value,pair<const_iterator,const_iterator>>::type
Eric Fiseliera85c9e92018-02-10 02:53:47 +00001382 equal_range(const _K2& __k) const {return __tree_.__equal_range_multi(__k);}
Marshall Clowebb57322013-08-13 22:18:47 +00001383#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001384
1385private:
1386 typedef typename __base::__node __node;
1387 typedef typename __base::__node_allocator __node_allocator;
1388 typedef typename __base::__node_pointer __node_pointer;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001389 typedef typename __base::__node_base_pointer __node_base_pointer;
Eric Fiseliercf8c0212017-01-05 06:06:18 +00001390 typedef typename __base::__parent_pointer __parent_pointer;
Eric Fiseliera92b0732016-02-20 07:12:17 +00001391
Howard Hinnantc834c512011-11-29 18:15:50 +00001392 typedef __map_node_destructor<__node_allocator> _Dp;
1393 typedef unique_ptr<__node, _Dp> __node_holder;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001394
Eric Fiselierd63f38e2016-03-31 03:13:37 +00001395#ifdef _LIBCPP_CXX03_LANG
Howard Hinnantac7e7482013-07-04 20:59:16 +00001396 __node_holder __construct_node_with_key(const key_type& __k);
Eric Fiselierd63f38e2016-03-31 03:13:37 +00001397#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001398};
1399
Eric Fiseliera92b0732016-02-20 07:12:17 +00001400
Eric Fiselierd06276b2016-03-31 02:15:15 +00001401#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001402template <class _Key, class _Tp, class _Compare, class _Allocator>
1403map<_Key, _Tp, _Compare, _Allocator>::map(map&& __m, const allocator_type& __a)
Marshall Clow657cbc42016-08-17 05:58:40 +00001404 : __tree_(_VSTD::move(__m.__tree_), typename __base::allocator_type(__a))
Howard Hinnantc51e1022010-05-11 19:42:16 +00001405{
1406 if (__a != __m.get_allocator())
1407 {
1408 const_iterator __e = cend();
1409 while (!__m.empty())
1410 __tree_.__insert_unique(__e.__i_,
Erik Pilkingtond3fe2992018-06-04 20:38:23 +00001411 __m.__tree_.remove(__m.begin().__i_)->__value_.__move());
Howard Hinnantc51e1022010-05-11 19:42:16 +00001412 }
1413}
1414
Eric Fiseliera85b1282017-04-18 21:08:06 +00001415template <class _Key, class _Tp, class _Compare, class _Allocator>
1416_Tp&
1417map<_Key, _Tp, _Compare, _Allocator>::operator[](const key_type& __k)
1418{
1419 return __tree_.__emplace_unique_key_args(__k,
1420 _VSTD::piecewise_construct,
1421 _VSTD::forward_as_tuple(__k),
Erik Pilkingtond3fe2992018-06-04 20:38:23 +00001422 _VSTD::forward_as_tuple()).first->__get_value().second;
Eric Fiseliera85b1282017-04-18 21:08:06 +00001423}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001424
Eric Fiseliera85b1282017-04-18 21:08:06 +00001425template <class _Key, class _Tp, class _Compare, class _Allocator>
1426_Tp&
1427map<_Key, _Tp, _Compare, _Allocator>::operator[](key_type&& __k)
1428{
1429 return __tree_.__emplace_unique_key_args(__k,
1430 _VSTD::piecewise_construct,
1431 _VSTD::forward_as_tuple(_VSTD::move(__k)),
Erik Pilkingtond3fe2992018-06-04 20:38:23 +00001432 _VSTD::forward_as_tuple()).first->__get_value().second;
Eric Fiseliera85b1282017-04-18 21:08:06 +00001433}
Eric Fiselierd63f38e2016-03-31 03:13:37 +00001434
Eric Fiseliera85b1282017-04-18 21:08:06 +00001435#else // _LIBCPP_CXX03_LANG
Eric Fiselierd63f38e2016-03-31 03:13:37 +00001436
Howard Hinnantc51e1022010-05-11 19:42:16 +00001437template <class _Key, class _Tp, class _Compare, class _Allocator>
1438typename map<_Key, _Tp, _Compare, _Allocator>::__node_holder
Howard Hinnantac7e7482013-07-04 20:59:16 +00001439map<_Key, _Tp, _Compare, _Allocator>::__construct_node_with_key(const key_type& __k)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001440{
1441 __node_allocator& __na = __tree_.__node_alloc();
Howard Hinnantc834c512011-11-29 18:15:50 +00001442 __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
Erik Pilkingtond3fe2992018-06-04 20:38:23 +00001443 __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__get_value().first), __k);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001444 __h.get_deleter().__first_constructed = true;
Erik Pilkingtond3fe2992018-06-04 20:38:23 +00001445 __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__get_value().second));
Howard Hinnantc51e1022010-05-11 19:42:16 +00001446 __h.get_deleter().__second_constructed = true;
Dimitry Andric830fb602015-08-19 06:43:33 +00001447 return _LIBCPP_EXPLICIT_MOVE(__h); // explicitly moved for C++03
Howard Hinnantc51e1022010-05-11 19:42:16 +00001448}
1449
Howard Hinnantc51e1022010-05-11 19:42:16 +00001450template <class _Key, class _Tp, class _Compare, class _Allocator>
1451_Tp&
1452map<_Key, _Tp, _Compare, _Allocator>::operator[](const key_type& __k)
1453{
Eric Fiseliercf8c0212017-01-05 06:06:18 +00001454 __parent_pointer __parent;
1455 __node_base_pointer& __child = __tree_.__find_equal(__parent, __k);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001456 __node_pointer __r = static_cast<__node_pointer>(__child);
1457 if (__child == nullptr)
1458 {
Howard Hinnantac7e7482013-07-04 20:59:16 +00001459 __node_holder __h = __construct_node_with_key(__k);
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001460 __tree_.__insert_node_at(__parent, __child, static_cast<__node_base_pointer>(__h.get()));
Howard Hinnantc51e1022010-05-11 19:42:16 +00001461 __r = __h.release();
1462 }
Erik Pilkingtond3fe2992018-06-04 20:38:23 +00001463 return __r->__value_.__get_value().second;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001464}
1465
Eric Fiseliera85b1282017-04-18 21:08:06 +00001466#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001467
1468template <class _Key, class _Tp, class _Compare, class _Allocator>
1469_Tp&
1470map<_Key, _Tp, _Compare, _Allocator>::at(const key_type& __k)
1471{
Eric Fiseliercf8c0212017-01-05 06:06:18 +00001472 __parent_pointer __parent;
1473 __node_base_pointer& __child = __tree_.__find_equal(__parent, __k);
Howard Hinnant72f73582010-08-11 17:04:31 +00001474#ifndef _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +00001475 if (__child == nullptr)
1476 throw out_of_range("map::at: key not found");
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001477#endif // _LIBCPP_NO_EXCEPTIONS
Erik Pilkingtond3fe2992018-06-04 20:38:23 +00001478 return static_cast<__node_pointer>(__child)->__value_.__get_value().second;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001479}
1480
1481template <class _Key, class _Tp, class _Compare, class _Allocator>
1482const _Tp&
1483map<_Key, _Tp, _Compare, _Allocator>::at(const key_type& __k) const
1484{
Eric Fiseliercf8c0212017-01-05 06:06:18 +00001485 __parent_pointer __parent;
1486 __node_base_pointer __child = __tree_.__find_equal(__parent, __k);
Howard Hinnant72f73582010-08-11 17:04:31 +00001487#ifndef _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +00001488 if (__child == nullptr)
1489 throw out_of_range("map::at: key not found");
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001490#endif // _LIBCPP_NO_EXCEPTIONS
Erik Pilkingtond3fe2992018-06-04 20:38:23 +00001491 return static_cast<__node_pointer>(__child)->__value_.__get_value().second;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001492}
1493
Howard Hinnantc51e1022010-05-11 19:42:16 +00001494
1495template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001496inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001497bool
1498operator==(const map<_Key, _Tp, _Compare, _Allocator>& __x,
1499 const map<_Key, _Tp, _Compare, _Allocator>& __y)
1500{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001501 return __x.size() == __y.size() && _VSTD::equal(__x.begin(), __x.end(), __y.begin());
Howard Hinnantc51e1022010-05-11 19:42:16 +00001502}
1503
1504template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001505inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001506bool
1507operator< (const map<_Key, _Tp, _Compare, _Allocator>& __x,
1508 const map<_Key, _Tp, _Compare, _Allocator>& __y)
1509{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001510 return _VSTD::lexicographical_compare(__x.begin(), __x.end(), __y.begin(), __y.end());
Howard Hinnantc51e1022010-05-11 19:42:16 +00001511}
1512
1513template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001514inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001515bool
1516operator!=(const map<_Key, _Tp, _Compare, _Allocator>& __x,
1517 const map<_Key, _Tp, _Compare, _Allocator>& __y)
1518{
1519 return !(__x == __y);
1520}
1521
1522template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001523inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001524bool
1525operator> (const map<_Key, _Tp, _Compare, _Allocator>& __x,
1526 const map<_Key, _Tp, _Compare, _Allocator>& __y)
1527{
1528 return __y < __x;
1529}
1530
1531template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001532inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001533bool
1534operator>=(const map<_Key, _Tp, _Compare, _Allocator>& __x,
1535 const map<_Key, _Tp, _Compare, _Allocator>& __y)
1536{
1537 return !(__x < __y);
1538}
1539
1540template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001541inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001542bool
1543operator<=(const map<_Key, _Tp, _Compare, _Allocator>& __x,
1544 const map<_Key, _Tp, _Compare, _Allocator>& __y)
1545{
1546 return !(__y < __x);
1547}
1548
1549template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001550inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001551void
1552swap(map<_Key, _Tp, _Compare, _Allocator>& __x,
1553 map<_Key, _Tp, _Compare, _Allocator>& __y)
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001554 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
Howard Hinnantc51e1022010-05-11 19:42:16 +00001555{
1556 __x.swap(__y);
1557}
1558
1559template <class _Key, class _Tp, class _Compare = less<_Key>,
1560 class _Allocator = allocator<pair<const _Key, _Tp> > >
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00001561class _LIBCPP_TEMPLATE_VIS multimap
Howard Hinnantc51e1022010-05-11 19:42:16 +00001562{
1563public:
1564 // types:
1565 typedef _Key key_type;
1566 typedef _Tp mapped_type;
1567 typedef pair<const key_type, mapped_type> value_type;
1568 typedef _Compare key_compare;
1569 typedef _Allocator allocator_type;
1570 typedef value_type& reference;
1571 typedef const value_type& const_reference;
1572
Marshall Clow5128cf32015-11-26 01:24:04 +00001573 static_assert((is_same<typename allocator_type::value_type, value_type>::value),
1574 "Allocator::value_type must be same type as value_type");
1575
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00001576 class _LIBCPP_TEMPLATE_VIS value_compare
Howard Hinnantc51e1022010-05-11 19:42:16 +00001577 : public binary_function<value_type, value_type, bool>
1578 {
1579 friend class multimap;
1580 protected:
1581 key_compare comp;
1582
Howard Hinnant756c69b2010-09-22 16:48:34 +00001583 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001584 value_compare(key_compare c) : comp(c) {}
1585 public:
Howard Hinnant756c69b2010-09-22 16:48:34 +00001586 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001587 bool operator()(const value_type& __x, const value_type& __y) const
1588 {return comp(__x.first, __y.first);}
1589 };
1590
1591private:
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001592
Howard Hinnant89f8b792013-09-30 19:08:22 +00001593 typedef _VSTD::__value_type<key_type, mapped_type> __value_type;
Howard Hinnant90b91592013-07-05 18:06:00 +00001594 typedef __map_value_compare<key_type, __value_type, key_compare> __vc;
Marshall Clow940e01c2015-04-07 05:21:38 +00001595 typedef typename __rebind_alloc_helper<allocator_traits<allocator_type>,
1596 __value_type>::type __allocator_type;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001597 typedef __tree<__value_type, __vc, __allocator_type> __base;
1598 typedef typename __base::__node_traits __node_traits;
1599 typedef allocator_traits<allocator_type> __alloc_traits;
1600
1601 __base __tree_;
1602
1603public:
1604 typedef typename __alloc_traits::pointer pointer;
1605 typedef typename __alloc_traits::const_pointer const_pointer;
1606 typedef typename __alloc_traits::size_type size_type;
1607 typedef typename __alloc_traits::difference_type difference_type;
1608 typedef __map_iterator<typename __base::iterator> iterator;
1609 typedef __map_const_iterator<typename __base::const_iterator> const_iterator;
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001610 typedef _VSTD::reverse_iterator<iterator> reverse_iterator;
1611 typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001612
Erik Pilkingtonc37a3d82018-08-01 01:33:38 +00001613#if _LIBCPP_STD_VER > 14
1614 typedef __map_node_handle<typename __base::__node, allocator_type> node_type;
1615#endif
1616
Howard Hinnant756c69b2010-09-22 16:48:34 +00001617 _LIBCPP_INLINE_VISIBILITY
Marshall Clow7086a5a2014-03-10 04:50:10 +00001618 multimap()
1619 _NOEXCEPT_(
1620 is_nothrow_default_constructible<allocator_type>::value &&
1621 is_nothrow_default_constructible<key_compare>::value &&
1622 is_nothrow_copy_constructible<key_compare>::value)
1623 : __tree_(__vc(key_compare())) {}
1624
1625 _LIBCPP_INLINE_VISIBILITY
1626 explicit multimap(const key_compare& __comp)
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001627 _NOEXCEPT_(
1628 is_nothrow_default_constructible<allocator_type>::value &&
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001629 is_nothrow_copy_constructible<key_compare>::value)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001630 : __tree_(__vc(__comp)) {}
1631
Howard Hinnant756c69b2010-09-22 16:48:34 +00001632 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001633 explicit multimap(const key_compare& __comp, const allocator_type& __a)
Marshall Clow657cbc42016-08-17 05:58:40 +00001634 : __tree_(__vc(__comp), typename __base::allocator_type(__a)) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001635
1636 template <class _InputIterator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001637 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001638 multimap(_InputIterator __f, _InputIterator __l,
1639 const key_compare& __comp = key_compare())
1640 : __tree_(__vc(__comp))
1641 {
1642 insert(__f, __l);
1643 }
1644
1645 template <class _InputIterator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001646 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001647 multimap(_InputIterator __f, _InputIterator __l,
1648 const key_compare& __comp, const allocator_type& __a)
Marshall Clow657cbc42016-08-17 05:58:40 +00001649 : __tree_(__vc(__comp), typename __base::allocator_type(__a))
Howard Hinnantc51e1022010-05-11 19:42:16 +00001650 {
1651 insert(__f, __l);
1652 }
1653
Marshall Clow300abfb2013-09-11 01:15:47 +00001654#if _LIBCPP_STD_VER > 11
1655 template <class _InputIterator>
Eric Fiseliercf8c0212017-01-05 06:06:18 +00001656 _LIBCPP_INLINE_VISIBILITY
Marshall Clow300abfb2013-09-11 01:15:47 +00001657 multimap(_InputIterator __f, _InputIterator __l, const allocator_type& __a)
1658 : multimap(__f, __l, key_compare(), __a) {}
1659#endif
1660
Howard Hinnant756c69b2010-09-22 16:48:34 +00001661 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001662 multimap(const multimap& __m)
1663 : __tree_(__m.__tree_.value_comp(),
1664 __alloc_traits::select_on_container_copy_construction(__m.__tree_.__alloc()))
1665 {
1666 insert(__m.begin(), __m.end());
1667 }
1668
Howard Hinnantd3a657f2011-07-01 19:24:36 +00001669 _LIBCPP_INLINE_VISIBILITY
1670 multimap& operator=(const multimap& __m)
1671 {
Marshall Clow476d3f42016-07-18 13:19:00 +00001672#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantd3a657f2011-07-01 19:24:36 +00001673 __tree_ = __m.__tree_;
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001674#else
Marshall Clowdb3cfcb2014-02-08 04:03:14 +00001675 if (this != &__m) {
1676 __tree_.clear();
1677 __tree_.value_comp() = __m.__tree_.value_comp();
1678 __tree_.__copy_assign_alloc(__m.__tree_);
1679 insert(__m.begin(), __m.end());
1680 }
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001681#endif
Howard Hinnantd3a657f2011-07-01 19:24:36 +00001682 return *this;
1683 }
1684
Eric Fiseliera85b1282017-04-18 21:08:06 +00001685#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001686
Howard Hinnant756c69b2010-09-22 16:48:34 +00001687 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001688 multimap(multimap&& __m)
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001689 _NOEXCEPT_(is_nothrow_move_constructible<__base>::value)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001690 : __tree_(_VSTD::move(__m.__tree_))
Howard Hinnantc51e1022010-05-11 19:42:16 +00001691 {
1692 }
1693
1694 multimap(multimap&& __m, const allocator_type& __a);
1695
Howard Hinnant756c69b2010-09-22 16:48:34 +00001696 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant33711792011-08-12 21:56:02 +00001697 multimap& operator=(multimap&& __m)
1698 _NOEXCEPT_(is_nothrow_move_assignable<__base>::value)
1699 {
1700 __tree_ = _VSTD::move(__m.__tree_);
1701 return *this;
1702 }
1703
Howard Hinnant33711792011-08-12 21:56:02 +00001704 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001705 multimap(initializer_list<value_type> __il, const key_compare& __comp = key_compare())
1706 : __tree_(__vc(__comp))
1707 {
1708 insert(__il.begin(), __il.end());
1709 }
1710
Howard Hinnant756c69b2010-09-22 16:48:34 +00001711 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001712 multimap(initializer_list<value_type> __il, 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(__il.begin(), __il.end());
1716 }
1717
Marshall Clow300abfb2013-09-11 01:15:47 +00001718#if _LIBCPP_STD_VER > 11
Eric Fiseliercf8c0212017-01-05 06:06:18 +00001719 _LIBCPP_INLINE_VISIBILITY
Marshall Clow300abfb2013-09-11 01:15:47 +00001720 multimap(initializer_list<value_type> __il, const allocator_type& __a)
1721 : multimap(__il, key_compare(), __a) {}
1722#endif
1723
Howard Hinnant756c69b2010-09-22 16:48:34 +00001724 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001725 multimap& operator=(initializer_list<value_type> __il)
1726 {
1727 __tree_.__assign_multi(__il.begin(), __il.end());
1728 return *this;
1729 }
Howard Hinnant33711792011-08-12 21:56:02 +00001730
Eric Fiseliera85b1282017-04-18 21:08:06 +00001731#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001732
Howard Hinnant756c69b2010-09-22 16:48:34 +00001733 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001734 explicit multimap(const allocator_type& __a)
Marshall Clow657cbc42016-08-17 05:58:40 +00001735 : __tree_(typename __base::allocator_type(__a))
Howard Hinnantc51e1022010-05-11 19:42:16 +00001736 {
1737 }
1738
Howard Hinnant756c69b2010-09-22 16:48:34 +00001739 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001740 multimap(const multimap& __m, const allocator_type& __a)
Marshall Clow657cbc42016-08-17 05:58:40 +00001741 : __tree_(__m.__tree_.value_comp(), typename __base::allocator_type(__a))
Howard Hinnantc51e1022010-05-11 19:42:16 +00001742 {
1743 insert(__m.begin(), __m.end());
1744 }
1745
Howard Hinnant756c69b2010-09-22 16:48:34 +00001746 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001747 iterator begin() _NOEXCEPT {return __tree_.begin();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001748 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001749 const_iterator begin() const _NOEXCEPT {return __tree_.begin();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001750 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001751 iterator end() _NOEXCEPT {return __tree_.end();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001752 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001753 const_iterator end() const _NOEXCEPT {return __tree_.end();}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001754
Howard Hinnant756c69b2010-09-22 16:48:34 +00001755 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001756 reverse_iterator rbegin() _NOEXCEPT {return reverse_iterator(end());}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001757 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001758 const_reverse_iterator rbegin() const _NOEXCEPT
1759 {return const_reverse_iterator(end());}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001760 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001761 reverse_iterator rend() _NOEXCEPT {return reverse_iterator(begin());}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001762 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001763 const_reverse_iterator rend() const _NOEXCEPT
1764 {return const_reverse_iterator(begin());}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001765
Howard Hinnant756c69b2010-09-22 16:48:34 +00001766 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001767 const_iterator cbegin() const _NOEXCEPT {return begin();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001768 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001769 const_iterator cend() const _NOEXCEPT {return end();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001770 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001771 const_reverse_iterator crbegin() const _NOEXCEPT {return rbegin();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001772 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001773 const_reverse_iterator crend() const _NOEXCEPT {return rend();}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001774
Marshall Clow425f5752017-11-15 05:51:26 +00001775 _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001776 bool empty() const _NOEXCEPT {return __tree_.size() == 0;}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001777 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001778 size_type size() const _NOEXCEPT {return __tree_.size();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001779 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001780 size_type max_size() const _NOEXCEPT {return __tree_.max_size();}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001781
Howard Hinnant756c69b2010-09-22 16:48:34 +00001782 _LIBCPP_INLINE_VISIBILITY
Marshall Clow657cbc42016-08-17 05:58:40 +00001783 allocator_type get_allocator() const _NOEXCEPT {return allocator_type(__tree_.__alloc());}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001784 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001785 key_compare key_comp() const {return __tree_.value_comp().key_comp();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001786 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001787 value_compare value_comp() const
1788 {return value_compare(__tree_.value_comp().key_comp());}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001789
Eric Fiselierd06276b2016-03-31 02:15:15 +00001790#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant74279a52010-09-04 23:28:19 +00001791
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001792 template <class ..._Args>
Eric Fiselierd06276b2016-03-31 02:15:15 +00001793 _LIBCPP_INLINE_VISIBILITY
1794 iterator emplace(_Args&& ...__args) {
1795 return __tree_.__emplace_multi(_VSTD::forward<_Args>(__args)...);
1796 }
Howard Hinnantc51e1022010-05-11 19:42:16 +00001797
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001798 template <class ..._Args>
Eric Fiselierd06276b2016-03-31 02:15:15 +00001799 _LIBCPP_INLINE_VISIBILITY
1800 iterator emplace_hint(const_iterator __p, _Args&& ...__args) {
1801 return __tree_.__emplace_hint_multi(__p.__i_, _VSTD::forward<_Args>(__args)...);
1802 }
Howard Hinnant74279a52010-09-04 23:28:19 +00001803
Howard Hinnantc834c512011-11-29 18:15:50 +00001804 template <class _Pp,
1805 class = typename enable_if<is_constructible<value_type, _Pp>::value>::type>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001806 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc834c512011-11-29 18:15:50 +00001807 iterator insert(_Pp&& __p)
1808 {return __tree_.__insert_multi(_VSTD::forward<_Pp>(__p));}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001809
Howard Hinnantc834c512011-11-29 18:15:50 +00001810 template <class _Pp,
1811 class = typename enable_if<is_constructible<value_type, _Pp>::value>::type>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001812 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc834c512011-11-29 18:15:50 +00001813 iterator insert(const_iterator __pos, _Pp&& __p)
1814 {return __tree_.__insert_multi(__pos.__i_, _VSTD::forward<_Pp>(__p));}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001815
Eric Fiselierd6143132016-04-18 01:40:45 +00001816 _LIBCPP_INLINE_VISIBILITY
1817 iterator insert(value_type&& __v)
1818 {return __tree_.__insert_multi(_VSTD::move(__v));}
1819
1820 _LIBCPP_INLINE_VISIBILITY
1821 iterator insert(const_iterator __p, value_type&& __v)
1822 {return __tree_.__insert_multi(__p.__i_, _VSTD::move(__v));}
1823
Eric Fiseliera85b1282017-04-18 21:08:06 +00001824
1825 _LIBCPP_INLINE_VISIBILITY
1826 void insert(initializer_list<value_type> __il)
1827 {insert(__il.begin(), __il.end());}
1828
Eric Fiselierd06276b2016-03-31 02:15:15 +00001829#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001830
Howard Hinnant756c69b2010-09-22 16:48:34 +00001831 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001832 iterator insert(const value_type& __v) {return __tree_.__insert_multi(__v);}
1833
Howard Hinnant756c69b2010-09-22 16:48:34 +00001834 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001835 iterator insert(const_iterator __p, const value_type& __v)
1836 {return __tree_.__insert_multi(__p.__i_, __v);}
1837
1838 template <class _InputIterator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001839 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001840 void insert(_InputIterator __f, _InputIterator __l)
1841 {
1842 for (const_iterator __e = cend(); __f != __l; ++__f)
1843 __tree_.__insert_multi(__e.__i_, *__f);
1844 }
1845
Howard Hinnant756c69b2010-09-22 16:48:34 +00001846 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001847 iterator erase(const_iterator __p) {return __tree_.erase(__p.__i_);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001848 _LIBCPP_INLINE_VISIBILITY
Marshall Clow22ea5b82015-05-10 13:35:00 +00001849 iterator erase(iterator __p) {return __tree_.erase(__p.__i_);}
1850 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001851 size_type erase(const key_type& __k) {return __tree_.__erase_multi(__k);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001852 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001853 iterator erase(const_iterator __f, const_iterator __l)
1854 {return __tree_.erase(__f.__i_, __l.__i_);}
Erik Pilkingtonc37a3d82018-08-01 01:33:38 +00001855
1856#if _LIBCPP_STD_VER > 14
1857 _LIBCPP_INLINE_VISIBILITY
1858 iterator insert(node_type&& __nh)
1859 {
1860 _LIBCPP_ASSERT(__nh.empty() || __nh.get_allocator() == get_allocator(),
1861 "node_type with incompatible allocator passed to multimap::insert()");
1862 return __tree_.template __node_handle_insert_multi<node_type>(
1863 _VSTD::move(__nh));
1864 }
1865 _LIBCPP_INLINE_VISIBILITY
1866 iterator insert(const_iterator __hint, node_type&& __nh)
1867 {
1868 _LIBCPP_ASSERT(__nh.empty() || __nh.get_allocator() == get_allocator(),
1869 "node_type with incompatible allocator passed to multimap::insert()");
1870 return __tree_.template __node_handle_insert_multi<node_type>(
1871 __hint.__i_, _VSTD::move(__nh));
1872 }
1873 _LIBCPP_INLINE_VISIBILITY
1874 node_type extract(key_type const& __key)
1875 {
1876 return __tree_.template __node_handle_extract<node_type>(__key);
1877 }
1878 _LIBCPP_INLINE_VISIBILITY
1879 node_type extract(const_iterator __it)
1880 {
1881 return __tree_.template __node_handle_extract<node_type>(
1882 __it.__i_);
1883 }
1884#endif
1885
Howard Hinnant756c69b2010-09-22 16:48:34 +00001886 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001887 void clear() {__tree_.clear();}
1888
Howard Hinnant756c69b2010-09-22 16:48:34 +00001889 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001890 void swap(multimap& __m)
1891 _NOEXCEPT_(__is_nothrow_swappable<__base>::value)
1892 {__tree_.swap(__m.__tree_);}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001893
Howard Hinnant756c69b2010-09-22 16:48:34 +00001894 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001895 iterator find(const key_type& __k) {return __tree_.find(__k);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001896 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001897 const_iterator find(const key_type& __k) const {return __tree_.find(__k);}
Marshall Clowebb57322013-08-13 22:18:47 +00001898#if _LIBCPP_STD_VER > 11
1899 template <typename _K2>
1900 _LIBCPP_INLINE_VISIBILITY
1901 typename enable_if<__is_transparent<_Compare, _K2>::value,iterator>::type
1902 find(const _K2& __k) {return __tree_.find(__k);}
1903 template <typename _K2>
1904 _LIBCPP_INLINE_VISIBILITY
1905 typename enable_if<__is_transparent<_Compare, _K2>::value,const_iterator>::type
1906 find(const _K2& __k) const {return __tree_.find(__k);}
1907#endif
1908
Howard Hinnant756c69b2010-09-22 16:48:34 +00001909 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001910 size_type count(const key_type& __k) const
1911 {return __tree_.__count_multi(__k);}
Marshall Clowe6a5f522014-08-24 23:54:16 +00001912#if _LIBCPP_STD_VER > 11
1913 template <typename _K2>
1914 _LIBCPP_INLINE_VISIBILITY
1915 typename enable_if<__is_transparent<_Compare, _K2>::value,size_type>::type
Marshall Clow141e47b2015-06-30 18:15:41 +00001916 count(const _K2& __k) const {return __tree_.__count_multi(__k);}
Marshall Clowe6a5f522014-08-24 23:54:16 +00001917#endif
Howard Hinnant756c69b2010-09-22 16:48:34 +00001918 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001919 iterator lower_bound(const key_type& __k)
1920 {return __tree_.lower_bound(__k);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001921 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001922 const_iterator lower_bound(const key_type& __k) const
1923 {return __tree_.lower_bound(__k);}
Marshall Clowebb57322013-08-13 22:18:47 +00001924#if _LIBCPP_STD_VER > 11
1925 template <typename _K2>
1926 _LIBCPP_INLINE_VISIBILITY
1927 typename enable_if<__is_transparent<_Compare, _K2>::value,iterator>::type
1928 lower_bound(const _K2& __k) {return __tree_.lower_bound(__k);}
1929
1930 template <typename _K2>
1931 _LIBCPP_INLINE_VISIBILITY
1932 typename enable_if<__is_transparent<_Compare, _K2>::value,const_iterator>::type
1933 lower_bound(const _K2& __k) const {return __tree_.lower_bound(__k);}
1934#endif
1935
Howard Hinnant756c69b2010-09-22 16:48:34 +00001936 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001937 iterator upper_bound(const key_type& __k)
1938 {return __tree_.upper_bound(__k);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001939 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001940 const_iterator upper_bound(const key_type& __k) const
1941 {return __tree_.upper_bound(__k);}
Marshall Clowebb57322013-08-13 22:18:47 +00001942#if _LIBCPP_STD_VER > 11
1943 template <typename _K2>
1944 _LIBCPP_INLINE_VISIBILITY
1945 typename enable_if<__is_transparent<_Compare, _K2>::value,iterator>::type
1946 upper_bound(const _K2& __k) {return __tree_.upper_bound(__k);}
1947 template <typename _K2>
1948 _LIBCPP_INLINE_VISIBILITY
1949 typename enable_if<__is_transparent<_Compare, _K2>::value,const_iterator>::type
1950 upper_bound(const _K2& __k) const {return __tree_.upper_bound(__k);}
1951#endif
1952
Howard Hinnant756c69b2010-09-22 16:48:34 +00001953 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001954 pair<iterator,iterator> equal_range(const key_type& __k)
1955 {return __tree_.__equal_range_multi(__k);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001956 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001957 pair<const_iterator,const_iterator> equal_range(const key_type& __k) const
1958 {return __tree_.__equal_range_multi(__k);}
Marshall Clowebb57322013-08-13 22:18:47 +00001959#if _LIBCPP_STD_VER > 11
1960 template <typename _K2>
1961 _LIBCPP_INLINE_VISIBILITY
1962 typename enable_if<__is_transparent<_Compare, _K2>::value,pair<iterator,iterator>>::type
1963 equal_range(const _K2& __k) {return __tree_.__equal_range_multi(__k);}
1964 template <typename _K2>
1965 _LIBCPP_INLINE_VISIBILITY
1966 typename enable_if<__is_transparent<_Compare, _K2>::value,pair<const_iterator,const_iterator>>::type
1967 equal_range(const _K2& __k) const {return __tree_.__equal_range_multi(__k);}
1968#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001969
1970private:
1971 typedef typename __base::__node __node;
1972 typedef typename __base::__node_allocator __node_allocator;
1973 typedef typename __base::__node_pointer __node_pointer;
Eric Fiseliera92b0732016-02-20 07:12:17 +00001974
Howard Hinnantc834c512011-11-29 18:15:50 +00001975 typedef __map_node_destructor<__node_allocator> _Dp;
1976 typedef unique_ptr<__node, _Dp> __node_holder;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001977};
1978
Eric Fiselierd06276b2016-03-31 02:15:15 +00001979#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001980template <class _Key, class _Tp, class _Compare, class _Allocator>
1981multimap<_Key, _Tp, _Compare, _Allocator>::multimap(multimap&& __m, const allocator_type& __a)
Marshall Clow657cbc42016-08-17 05:58:40 +00001982 : __tree_(_VSTD::move(__m.__tree_), typename __base::allocator_type(__a))
Howard Hinnantc51e1022010-05-11 19:42:16 +00001983{
1984 if (__a != __m.get_allocator())
1985 {
1986 const_iterator __e = cend();
1987 while (!__m.empty())
1988 __tree_.__insert_multi(__e.__i_,
Erik Pilkingtond3fe2992018-06-04 20:38:23 +00001989 _VSTD::move(__m.__tree_.remove(__m.begin().__i_)->__value_.__move()));
Howard Hinnantc51e1022010-05-11 19:42:16 +00001990 }
1991}
Eric Fiselierd06276b2016-03-31 02:15:15 +00001992#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001993
1994template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001995inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001996bool
1997operator==(const multimap<_Key, _Tp, _Compare, _Allocator>& __x,
1998 const multimap<_Key, _Tp, _Compare, _Allocator>& __y)
1999{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00002000 return __x.size() == __y.size() && _VSTD::equal(__x.begin(), __x.end(), __y.begin());
Howard Hinnantc51e1022010-05-11 19:42:16 +00002001}
2002
2003template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00002004inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002005bool
2006operator< (const multimap<_Key, _Tp, _Compare, _Allocator>& __x,
2007 const multimap<_Key, _Tp, _Compare, _Allocator>& __y)
2008{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00002009 return _VSTD::lexicographical_compare(__x.begin(), __x.end(), __y.begin(), __y.end());
Howard Hinnantc51e1022010-05-11 19:42:16 +00002010}
2011
2012template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00002013inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002014bool
2015operator!=(const multimap<_Key, _Tp, _Compare, _Allocator>& __x,
2016 const multimap<_Key, _Tp, _Compare, _Allocator>& __y)
2017{
2018 return !(__x == __y);
2019}
2020
2021template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00002022inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002023bool
2024operator> (const multimap<_Key, _Tp, _Compare, _Allocator>& __x,
2025 const multimap<_Key, _Tp, _Compare, _Allocator>& __y)
2026{
2027 return __y < __x;
2028}
2029
2030template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00002031inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002032bool
2033operator>=(const multimap<_Key, _Tp, _Compare, _Allocator>& __x,
2034 const multimap<_Key, _Tp, _Compare, _Allocator>& __y)
2035{
2036 return !(__x < __y);
2037}
2038
2039template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00002040inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002041bool
2042operator<=(const multimap<_Key, _Tp, _Compare, _Allocator>& __x,
2043 const multimap<_Key, _Tp, _Compare, _Allocator>& __y)
2044{
2045 return !(__y < __x);
2046}
2047
2048template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00002049inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002050void
2051swap(multimap<_Key, _Tp, _Compare, _Allocator>& __x,
2052 multimap<_Key, _Tp, _Compare, _Allocator>& __y)
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00002053 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
Howard Hinnantc51e1022010-05-11 19:42:16 +00002054{
2055 __x.swap(__y);
2056}
2057
2058_LIBCPP_END_NAMESPACE_STD
2059
2060#endif // _LIBCPP_MAP