blob: 472ac314bc1bc99ff4f8ed396c49fc01901263f3 [file] [log] [blame]
Howard Hinnantc51e1022010-05-11 19:42:16 +00001// -*- C++ -*-
2//===----------------------------- map ------------------------------------===//
3//
Howard Hinnantc566dc32010-05-11 21:36:01 +00004// The LLVM Compiler Infrastructure
Howard Hinnantc51e1022010-05-11 19:42:16 +00005//
Howard Hinnantee11c312010-11-16 22:09:02 +00006// This file is dual licensed under the MIT and the University of Illinois Open
7// Source Licenses. See LICENSE.TXT for details.
Howard Hinnantc51e1022010-05-11 19:42:16 +00008//
9//===----------------------------------------------------------------------===//
10
11#ifndef _LIBCPP_MAP
12#define _LIBCPP_MAP
13
14/*
15
16 map synopsis
17
18namespace std
19{
20
21template <class Key, class T, class Compare = less<Key>,
22 class Allocator = allocator<pair<const Key, T>>>
23class map
24{
25public:
26 // types:
27 typedef Key key_type;
28 typedef T mapped_type;
29 typedef pair<const key_type, mapped_type> value_type;
30 typedef Compare key_compare;
31 typedef Allocator allocator_type;
32 typedef typename allocator_type::reference reference;
33 typedef typename allocator_type::const_reference const_reference;
34 typedef typename allocator_type::pointer pointer;
35 typedef typename allocator_type::const_pointer const_pointer;
36 typedef typename allocator_type::size_type size_type;
37 typedef typename allocator_type::difference_type difference_type;
38
39 typedef implementation-defined iterator;
40 typedef implementation-defined const_iterator;
41 typedef std::reverse_iterator<iterator> reverse_iterator;
42 typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
Erik Pilkingtonc37a3d82018-08-01 01:33:38 +000043 typedef unspecified node_type; // C++17
44 typedef INSERT_RETURN_TYPE<iterator, node_type> insert_return_type; // C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +000045
46 class value_compare
47 : public binary_function<value_type, value_type, bool>
48 {
49 friend class map;
50 protected:
51 key_compare comp;
52
53 value_compare(key_compare c);
54 public:
55 bool operator()(const value_type& x, const value_type& y) const;
56 };
57
58 // construct/copy/destroy:
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +000059 map()
60 noexcept(
61 is_nothrow_default_constructible<allocator_type>::value &&
62 is_nothrow_default_constructible<key_compare>::value &&
63 is_nothrow_copy_constructible<key_compare>::value);
Howard Hinnantc51e1022010-05-11 19:42:16 +000064 explicit map(const key_compare& comp);
65 map(const key_compare& comp, const allocator_type& a);
66 template <class InputIterator>
67 map(InputIterator first, InputIterator last,
68 const key_compare& comp = key_compare());
69 template <class InputIterator>
70 map(InputIterator first, InputIterator last,
71 const key_compare& comp, const allocator_type& a);
72 map(const map& m);
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +000073 map(map&& m)
74 noexcept(
75 is_nothrow_move_constructible<allocator_type>::value &&
76 is_nothrow_move_constructible<key_compare>::value);
Howard Hinnantc51e1022010-05-11 19:42:16 +000077 explicit map(const allocator_type& a);
78 map(const map& m, const allocator_type& a);
79 map(map&& m, const allocator_type& a);
80 map(initializer_list<value_type> il, const key_compare& comp = key_compare());
81 map(initializer_list<value_type> il, const key_compare& comp, const allocator_type& a);
Marshall Clow300abfb2013-09-11 01:15:47 +000082 template <class InputIterator>
83 map(InputIterator first, InputIterator last, const allocator_type& a)
84 : map(first, last, Compare(), a) {} // C++14
85 map(initializer_list<value_type> il, const allocator_type& a)
86 : map(il, Compare(), a) {} // C++14
87 ~map();
Howard Hinnantc51e1022010-05-11 19:42:16 +000088
89 map& operator=(const map& m);
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +000090 map& operator=(map&& m)
91 noexcept(
92 allocator_type::propagate_on_container_move_assignment::value &&
93 is_nothrow_move_assignable<allocator_type>::value &&
Howard Hinnantf95f4f52011-06-04 15:22:34 +000094 is_nothrow_move_assignable<key_compare>::value);
Howard Hinnantc51e1022010-05-11 19:42:16 +000095 map& operator=(initializer_list<value_type> il);
96
97 // iterators:
Howard Hinnantf95f4f52011-06-04 15:22:34 +000098 iterator begin() noexcept;
99 const_iterator begin() const noexcept;
100 iterator end() noexcept;
101 const_iterator end() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000102
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000103 reverse_iterator rbegin() noexcept;
104 const_reverse_iterator rbegin() const noexcept;
105 reverse_iterator rend() noexcept;
106 const_reverse_iterator rend() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000107
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000108 const_iterator cbegin() const noexcept;
109 const_iterator cend() const noexcept;
110 const_reverse_iterator crbegin() const noexcept;
111 const_reverse_iterator crend() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000112
113 // capacity:
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000114 bool empty() const noexcept;
115 size_type size() const noexcept;
116 size_type max_size() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000117
118 // element access:
119 mapped_type& operator[](const key_type& k);
120 mapped_type& operator[](key_type&& k);
121
122 mapped_type& at(const key_type& k);
123 const mapped_type& at(const key_type& k) const;
124
125 // modifiers:
126 template <class... Args>
127 pair<iterator, bool> emplace(Args&&... args);
128 template <class... Args>
129 iterator emplace_hint(const_iterator position, Args&&... args);
130 pair<iterator, bool> insert(const value_type& v);
Marshall Clowd430d022016-01-05 19:32:41 +0000131 pair<iterator, bool> insert( value_type&& v); // C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000132 template <class P>
133 pair<iterator, bool> insert(P&& p);
134 iterator insert(const_iterator position, const value_type& v);
Marshall Clowd430d022016-01-05 19:32:41 +0000135 iterator insert(const_iterator position, value_type&& v); // C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000136 template <class P>
137 iterator insert(const_iterator position, P&& p);
138 template <class InputIterator>
139 void insert(InputIterator first, InputIterator last);
140 void insert(initializer_list<value_type> il);
141
Erik Pilkingtonc37a3d82018-08-01 01:33:38 +0000142 node_type extract(const_iterator position); // C++17
143 node_type extract(const key_type& x); // C++17
144 insert_return_type insert(node_type&& nh); // C++17
145 iterator insert(const_iterator hint, node_type&& nh); // C++17
146
Marshall Clow3223db82015-07-07 03:37:33 +0000147 template <class... Args>
148 pair<iterator, bool> try_emplace(const key_type& k, Args&&... args); // C++17
149 template <class... Args>
150 pair<iterator, bool> try_emplace(key_type&& k, Args&&... args); // C++17
151 template <class... Args>
152 iterator try_emplace(const_iterator hint, const key_type& k, Args&&... args); // C++17
153 template <class... Args>
154 iterator try_emplace(const_iterator hint, key_type&& k, Args&&... args); // C++17
155 template <class M>
156 pair<iterator, bool> insert_or_assign(const key_type& k, M&& obj); // C++17
157 template <class M>
158 pair<iterator, bool> insert_or_assign(key_type&& k, M&& obj); // C++17
159 template <class M>
160 iterator insert_or_assign(const_iterator hint, const key_type& k, M&& obj); // C++17
161 template <class M>
162 iterator insert_or_assign(const_iterator hint, key_type&& k, M&& obj); // C++17
163
Howard Hinnantc51e1022010-05-11 19:42:16 +0000164 iterator erase(const_iterator position);
Marshall Clow22ea5b82015-05-10 13:35:00 +0000165 iterator erase(iterator position); // C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000166 size_type erase(const key_type& k);
167 iterator erase(const_iterator first, const_iterator last);
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000168 void clear() noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000169
Erik Pilkington82a65ad2018-10-31 17:31:35 +0000170 template<class C2>
171 void merge(map<Key, T, C2, Allocator>& source); // C++17
172 template<class C2>
173 void merge(map<Key, T, C2, Allocator>&& source); // C++17
174 template<class C2>
175 void merge(multimap<Key, T, C2, Allocator>& source); // C++17
176 template<class C2>
177 void merge(multimap<Key, T, C2, Allocator>&& source); // C++17
178
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000179 void swap(map& m)
Marshall Clow8982dcd2015-07-13 20:04:56 +0000180 noexcept(allocator_traits<allocator_type>::is_always_equal::value &&
Eric Fiselier6bfed252016-04-21 23:38:59 +0000181 is_nothrow_swappable<key_compare>::value); // C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000182
183 // observers:
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000184 allocator_type get_allocator() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000185 key_compare key_comp() const;
186 value_compare value_comp() const;
187
188 // map operations:
189 iterator find(const key_type& k);
190 const_iterator find(const key_type& k) const;
Marshall Clowebb57322013-08-13 22:18:47 +0000191 template<typename K>
192 iterator find(const K& x); // C++14
193 template<typename K>
194 const_iterator find(const K& x) const; // C++14
195 template<typename K>
Marshall Clowe6a5f522014-08-24 23:54:16 +0000196 size_type count(const K& x) const; // C++14
Marshall Clowebb57322013-08-13 22:18:47 +0000197
Howard Hinnantc51e1022010-05-11 19:42:16 +0000198 size_type count(const key_type& k) const;
199 iterator lower_bound(const key_type& k);
200 const_iterator lower_bound(const key_type& k) const;
Marshall Clowebb57322013-08-13 22:18:47 +0000201 template<typename K>
202 iterator lower_bound(const K& x); // C++14
203 template<typename K>
204 const_iterator lower_bound(const K& x) const; // C++14
205
Howard Hinnantc51e1022010-05-11 19:42:16 +0000206 iterator upper_bound(const key_type& k);
207 const_iterator upper_bound(const key_type& k) const;
Marshall Clowebb57322013-08-13 22:18:47 +0000208 template<typename K>
209 iterator upper_bound(const K& x); // C++14
210 template<typename K>
211 const_iterator upper_bound(const K& x) const; // C++14
212
Howard Hinnantc51e1022010-05-11 19:42:16 +0000213 pair<iterator,iterator> equal_range(const key_type& k);
214 pair<const_iterator,const_iterator> equal_range(const key_type& k) const;
Marshall Clowebb57322013-08-13 22:18:47 +0000215 template<typename K>
216 pair<iterator,iterator> equal_range(const K& x); // C++14
217 template<typename K>
218 pair<const_iterator,const_iterator> equal_range(const K& x) const; // C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000219};
220
221template <class Key, class T, class Compare, class Allocator>
222bool
223operator==(const map<Key, T, Compare, Allocator>& x,
224 const map<Key, T, Compare, Allocator>& y);
225
226template <class Key, class T, class Compare, class Allocator>
227bool
228operator< (const map<Key, T, Compare, Allocator>& x,
229 const map<Key, T, Compare, Allocator>& y);
230
231template <class Key, class T, class Compare, class Allocator>
232bool
233operator!=(const map<Key, T, Compare, Allocator>& x,
234 const map<Key, T, Compare, Allocator>& y);
235
236template <class Key, class T, class Compare, class Allocator>
237bool
238operator> (const map<Key, T, Compare, Allocator>& x,
239 const map<Key, T, Compare, Allocator>& y);
240
241template <class Key, class T, class Compare, class Allocator>
242bool
243operator>=(const map<Key, T, Compare, Allocator>& x,
244 const map<Key, T, Compare, Allocator>& y);
245
246template <class Key, class T, class Compare, class Allocator>
247bool
248operator<=(const map<Key, T, Compare, Allocator>& x,
249 const map<Key, T, Compare, Allocator>& y);
250
251// specialized algorithms:
252template <class Key, class T, class Compare, class Allocator>
253void
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000254swap(map<Key, T, Compare, Allocator>& x, map<Key, T, Compare, Allocator>& y)
255 noexcept(noexcept(x.swap(y)));
Howard Hinnantc51e1022010-05-11 19:42:16 +0000256
257template <class Key, class T, class Compare = less<Key>,
258 class Allocator = allocator<pair<const Key, T>>>
259class multimap
260{
261public:
262 // types:
263 typedef Key key_type;
264 typedef T mapped_type;
265 typedef pair<const key_type,mapped_type> value_type;
266 typedef Compare key_compare;
267 typedef Allocator allocator_type;
268 typedef typename allocator_type::reference reference;
269 typedef typename allocator_type::const_reference const_reference;
270 typedef typename allocator_type::size_type size_type;
271 typedef typename allocator_type::difference_type difference_type;
272 typedef typename allocator_type::pointer pointer;
273 typedef typename allocator_type::const_pointer const_pointer;
274
275 typedef implementation-defined iterator;
276 typedef implementation-defined const_iterator;
277 typedef std::reverse_iterator<iterator> reverse_iterator;
278 typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
Erik Pilkingtonc37a3d82018-08-01 01:33:38 +0000279 typedef unspecified node_type; // C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000280
281 class value_compare
282 : public binary_function<value_type,value_type,bool>
283 {
284 friend class multimap;
285 protected:
286 key_compare comp;
287 value_compare(key_compare c);
288 public:
289 bool operator()(const value_type& x, const value_type& y) const;
290 };
291
292 // construct/copy/destroy:
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000293 multimap()
294 noexcept(
295 is_nothrow_default_constructible<allocator_type>::value &&
296 is_nothrow_default_constructible<key_compare>::value &&
297 is_nothrow_copy_constructible<key_compare>::value);
298 explicit multimap(const key_compare& comp);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000299 multimap(const key_compare& comp, const allocator_type& a);
300 template <class InputIterator>
301 multimap(InputIterator first, InputIterator last, const key_compare& comp);
302 template <class InputIterator>
303 multimap(InputIterator first, InputIterator last, const key_compare& comp,
304 const allocator_type& a);
305 multimap(const multimap& m);
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000306 multimap(multimap&& m)
307 noexcept(
308 is_nothrow_move_constructible<allocator_type>::value &&
309 is_nothrow_move_constructible<key_compare>::value);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000310 explicit multimap(const allocator_type& a);
311 multimap(const multimap& m, const allocator_type& a);
312 multimap(multimap&& m, const allocator_type& a);
313 multimap(initializer_list<value_type> il, const key_compare& comp = key_compare());
314 multimap(initializer_list<value_type> il, const key_compare& comp,
315 const allocator_type& a);
Marshall Clow300abfb2013-09-11 01:15:47 +0000316 template <class InputIterator>
317 multimap(InputIterator first, InputIterator last, const allocator_type& a)
318 : multimap(first, last, Compare(), a) {} // C++14
319 multimap(initializer_list<value_type> il, const allocator_type& a)
320 : multimap(il, Compare(), a) {} // C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000321 ~multimap();
322
323 multimap& operator=(const multimap& m);
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000324 multimap& operator=(multimap&& m)
325 noexcept(
326 allocator_type::propagate_on_container_move_assignment::value &&
327 is_nothrow_move_assignable<allocator_type>::value &&
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000328 is_nothrow_move_assignable<key_compare>::value);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000329 multimap& operator=(initializer_list<value_type> il);
330
331 // iterators:
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000332 iterator begin() noexcept;
333 const_iterator begin() const noexcept;
334 iterator end() noexcept;
335 const_iterator end() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000336
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000337 reverse_iterator rbegin() noexcept;
338 const_reverse_iterator rbegin() const noexcept;
339 reverse_iterator rend() noexcept;
340 const_reverse_iterator rend() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000341
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000342 const_iterator cbegin() const noexcept;
343 const_iterator cend() const noexcept;
344 const_reverse_iterator crbegin() const noexcept;
345 const_reverse_iterator crend() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000346
347 // capacity:
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000348 bool empty() const noexcept;
349 size_type size() const noexcept;
350 size_type max_size() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000351
352 // modifiers:
353 template <class... Args>
354 iterator emplace(Args&&... args);
355 template <class... Args>
356 iterator emplace_hint(const_iterator position, Args&&... args);
357 iterator insert(const value_type& v);
Marshall Clowd430d022016-01-05 19:32:41 +0000358 iterator insert( value_type&& v); // C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000359 template <class P>
360 iterator insert(P&& p);
361 iterator insert(const_iterator position, const value_type& v);
Marshall Clowd430d022016-01-05 19:32:41 +0000362 iterator insert(const_iterator position, value_type&& v); // C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000363 template <class P>
364 iterator insert(const_iterator position, P&& p);
365 template <class InputIterator>
366 void insert(InputIterator first, InputIterator last);
367 void insert(initializer_list<value_type> il);
368
Erik Pilkingtonc37a3d82018-08-01 01:33:38 +0000369 node_type extract(const_iterator position); // C++17
370 node_type extract(const key_type& x); // C++17
371 iterator insert(node_type&& nh); // C++17
372 iterator insert(const_iterator hint, node_type&& nh); // C++17
373
Howard Hinnantc51e1022010-05-11 19:42:16 +0000374 iterator erase(const_iterator position);
Marshall Clow22ea5b82015-05-10 13:35:00 +0000375 iterator erase(iterator position); // C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000376 size_type erase(const key_type& k);
377 iterator erase(const_iterator first, const_iterator last);
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000378 void clear() noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000379
Erik Pilkington82a65ad2018-10-31 17:31:35 +0000380 template<class C2>
381 void merge(multimap<Key, T, C2, Allocator>& source); // C++17
382 template<class C2>
383 void merge(multimap<Key, T, C2, Allocator>&& source); // C++17
384 template<class C2>
385 void merge(map<Key, T, C2, Allocator>& source); // C++17
386 template<class C2>
387 void merge(map<Key, T, C2, Allocator>&& source); // C++17
388
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000389 void swap(multimap& m)
Marshall Clow8982dcd2015-07-13 20:04:56 +0000390 noexcept(allocator_traits<allocator_type>::is_always_equal::value &&
Eric Fiselier6bfed252016-04-21 23:38:59 +0000391 is_nothrow_swappable<key_compare>::value); // C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000392
393 // observers:
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000394 allocator_type get_allocator() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000395 key_compare key_comp() const;
396 value_compare value_comp() const;
397
398 // map operations:
399 iterator find(const key_type& k);
400 const_iterator find(const key_type& k) const;
Marshall Clowebb57322013-08-13 22:18:47 +0000401 template<typename K>
402 iterator find(const K& x); // C++14
403 template<typename K>
404 const_iterator find(const K& x) const; // C++14
405 template<typename K>
Marshall Clowe6a5f522014-08-24 23:54:16 +0000406 size_type count(const K& x) const; // C++14
Marshall Clowebb57322013-08-13 22:18:47 +0000407
Howard Hinnantc51e1022010-05-11 19:42:16 +0000408 size_type count(const key_type& k) const;
409 iterator lower_bound(const key_type& k);
410 const_iterator lower_bound(const key_type& k) const;
Marshall Clowebb57322013-08-13 22:18:47 +0000411 template<typename K>
412 iterator lower_bound(const K& x); // C++14
413 template<typename K>
414 const_iterator lower_bound(const K& x) const; // C++14
415
Howard Hinnantc51e1022010-05-11 19:42:16 +0000416 iterator upper_bound(const key_type& k);
417 const_iterator upper_bound(const key_type& k) const;
Marshall Clowebb57322013-08-13 22:18:47 +0000418 template<typename K>
419 iterator upper_bound(const K& x); // C++14
420 template<typename K>
421 const_iterator upper_bound(const K& x) const; // C++14
422
Howard Hinnantc51e1022010-05-11 19:42:16 +0000423 pair<iterator,iterator> equal_range(const key_type& k);
424 pair<const_iterator,const_iterator> equal_range(const key_type& k) const;
Marshall Clowebb57322013-08-13 22:18:47 +0000425 template<typename K>
426 pair<iterator,iterator> equal_range(const K& x); // C++14
427 template<typename K>
428 pair<const_iterator,const_iterator> equal_range(const K& x) const; // C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000429};
430
431template <class Key, class T, class Compare, class Allocator>
432bool
433operator==(const multimap<Key, T, Compare, Allocator>& x,
434 const multimap<Key, T, Compare, Allocator>& y);
435
436template <class Key, class T, class Compare, class Allocator>
437bool
438operator< (const multimap<Key, T, Compare, Allocator>& x,
439 const multimap<Key, T, Compare, Allocator>& y);
440
441template <class Key, class T, class Compare, class Allocator>
442bool
443operator!=(const multimap<Key, T, Compare, Allocator>& x,
444 const multimap<Key, T, Compare, Allocator>& y);
445
446template <class Key, class T, class Compare, class Allocator>
447bool
448operator> (const multimap<Key, T, Compare, Allocator>& x,
449 const multimap<Key, T, Compare, Allocator>& y);
450
451template <class Key, class T, class Compare, class Allocator>
452bool
453operator>=(const multimap<Key, T, Compare, Allocator>& x,
454 const multimap<Key, T, Compare, Allocator>& y);
455
456template <class Key, class T, class Compare, class Allocator>
457bool
458operator<=(const multimap<Key, T, Compare, Allocator>& x,
459 const multimap<Key, T, Compare, Allocator>& y);
460
461// specialized algorithms:
462template <class Key, class T, class Compare, class Allocator>
463void
464swap(multimap<Key, T, Compare, Allocator>& x,
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000465 multimap<Key, T, Compare, Allocator>& y)
466 noexcept(noexcept(x.swap(y)));
Howard Hinnantc51e1022010-05-11 19:42:16 +0000467
468} // std
469
470*/
471
472#include <__config>
473#include <__tree>
Erik Pilkingtonc37a3d82018-08-01 01:33:38 +0000474#include <__node_handle>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000475#include <iterator>
476#include <memory>
477#include <utility>
478#include <functional>
479#include <initializer_list>
Eric Fiselierf7394302015-06-13 07:08:02 +0000480#include <type_traits>
Marshall Clow0a1e7502018-09-12 19:41:40 +0000481#include <version>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000482
Howard Hinnantaaaa52b2011-10-17 20:05:10 +0000483#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000484#pragma GCC system_header
Howard Hinnantaaaa52b2011-10-17 20:05:10 +0000485#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000486
487_LIBCPP_BEGIN_NAMESPACE_STD
488
Eric Fiseliera7a14ed2017-01-13 22:02:08 +0000489template <class _Key, class _CP, class _Compare, bool _IsSmall>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000490class __map_value_compare
491 : private _Compare
492{
Howard Hinnantc51e1022010-05-11 19:42:16 +0000493public:
Howard Hinnant756c69b2010-09-22 16:48:34 +0000494 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000495 __map_value_compare()
496 _NOEXCEPT_(is_nothrow_default_constructible<_Compare>::value)
497 : _Compare() {}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000498 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000499 __map_value_compare(_Compare c)
500 _NOEXCEPT_(is_nothrow_copy_constructible<_Compare>::value)
501 : _Compare(c) {}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000502 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000503 const _Compare& key_comp() const _NOEXCEPT {return *this;}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000504 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000505 bool operator()(const _CP& __x, const _CP& __y) const
Erik Pilkingtond3fe2992018-06-04 20:38:23 +0000506 {return static_cast<const _Compare&>(*this)(__x.__get_value().first, __y.__get_value().first);}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000507 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000508 bool operator()(const _CP& __x, const _Key& __y) const
Erik Pilkingtond3fe2992018-06-04 20:38:23 +0000509 {return static_cast<const _Compare&>(*this)(__x.__get_value().first, __y);}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000510 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000511 bool operator()(const _Key& __x, const _CP& __y) const
Erik Pilkingtond3fe2992018-06-04 20:38:23 +0000512 {return static_cast<const _Compare&>(*this)(__x, __y.__get_value().first);}
Marshall Clow8982dcd2015-07-13 20:04:56 +0000513 void swap(__map_value_compare&__y)
514 _NOEXCEPT_(__is_nothrow_swappable<_Compare>::value)
515 {
Eric Fiselier68b5f0b2017-04-13 00:34:24 +0000516 using _VSTD::swap;
517 swap(static_cast<_Compare&>(*this), static_cast<_Compare&>(__y));
Marshall Clow8982dcd2015-07-13 20:04:56 +0000518 }
Marshall Clowebb57322013-08-13 22:18:47 +0000519
520#if _LIBCPP_STD_VER > 11
521 template <typename _K2>
522 _LIBCPP_INLINE_VISIBILITY
523 typename enable_if<__is_transparent<_Compare, _K2>::value, bool>::type
524 operator () ( const _K2& __x, const _CP& __y ) const
Erik Pilkingtond3fe2992018-06-04 20:38:23 +0000525 {return static_cast<const _Compare&>(*this) (__x, __y.__get_value().first);}
Marshall Clowebb57322013-08-13 22:18:47 +0000526
527 template <typename _K2>
528 _LIBCPP_INLINE_VISIBILITY
529 typename enable_if<__is_transparent<_Compare, _K2>::value, bool>::type
530 operator () (const _CP& __x, const _K2& __y) const
Erik Pilkingtond3fe2992018-06-04 20:38:23 +0000531 {return static_cast<const _Compare&>(*this) (__x.__get_value().first, __y);}
Marshall Clowebb57322013-08-13 22:18:47 +0000532#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000533};
534
Howard Hinnant90b91592013-07-05 18:06:00 +0000535template <class _Key, class _CP, class _Compare>
536class __map_value_compare<_Key, _CP, _Compare, false>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000537{
538 _Compare comp;
539
Howard Hinnantc51e1022010-05-11 19:42:16 +0000540public:
Howard Hinnant756c69b2010-09-22 16:48:34 +0000541 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000542 __map_value_compare()
543 _NOEXCEPT_(is_nothrow_default_constructible<_Compare>::value)
544 : comp() {}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000545 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000546 __map_value_compare(_Compare c)
547 _NOEXCEPT_(is_nothrow_copy_constructible<_Compare>::value)
548 : comp(c) {}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000549 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000550 const _Compare& key_comp() const _NOEXCEPT {return comp;}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000551
Howard Hinnant756c69b2010-09-22 16:48:34 +0000552 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000553 bool operator()(const _CP& __x, const _CP& __y) const
Erik Pilkingtond3fe2992018-06-04 20:38:23 +0000554 {return comp(__x.__get_value().first, __y.__get_value().first);}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000555 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000556 bool operator()(const _CP& __x, const _Key& __y) const
Erik Pilkingtond3fe2992018-06-04 20:38:23 +0000557 {return comp(__x.__get_value().first, __y);}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000558 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000559 bool operator()(const _Key& __x, const _CP& __y) const
Erik Pilkingtond3fe2992018-06-04 20:38:23 +0000560 {return comp(__x, __y.__get_value().first);}
Marshall Clow8982dcd2015-07-13 20:04:56 +0000561 void swap(__map_value_compare&__y)
562 _NOEXCEPT_(__is_nothrow_swappable<_Compare>::value)
563 {
564 using _VSTD::swap;
565 swap(comp, __y.comp);
566 }
Eric Fiseliercf8c0212017-01-05 06:06:18 +0000567
Marshall Clowebb57322013-08-13 22:18:47 +0000568#if _LIBCPP_STD_VER > 11
569 template <typename _K2>
570 _LIBCPP_INLINE_VISIBILITY
571 typename enable_if<__is_transparent<_Compare, _K2>::value, bool>::type
572 operator () ( const _K2& __x, const _CP& __y ) const
Erik Pilkingtond3fe2992018-06-04 20:38:23 +0000573 {return comp (__x, __y.__get_value().first);}
Marshall Clowebb57322013-08-13 22:18:47 +0000574
575 template <typename _K2>
576 _LIBCPP_INLINE_VISIBILITY
577 typename enable_if<__is_transparent<_Compare, _K2>::value, bool>::type
578 operator () (const _CP& __x, const _K2& __y) const
Erik Pilkingtond3fe2992018-06-04 20:38:23 +0000579 {return comp (__x.__get_value().first, __y);}
Marshall Clowebb57322013-08-13 22:18:47 +0000580#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000581};
582
Marshall Clow8982dcd2015-07-13 20:04:56 +0000583template <class _Key, class _CP, class _Compare, bool __b>
584inline _LIBCPP_INLINE_VISIBILITY
585void
586swap(__map_value_compare<_Key, _CP, _Compare, __b>& __x,
587 __map_value_compare<_Key, _CP, _Compare, __b>& __y)
588 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
589{
590 __x.swap(__y);
591}
592
Howard Hinnantc51e1022010-05-11 19:42:16 +0000593template <class _Allocator>
594class __map_node_destructor
595{
596 typedef _Allocator allocator_type;
597 typedef allocator_traits<allocator_type> __alloc_traits;
Eric Fiseliera00b4842016-02-20 05:28:30 +0000598
Howard Hinnantc51e1022010-05-11 19:42:16 +0000599public:
600 typedef typename __alloc_traits::pointer pointer;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000601
Eric Fiseliera00b4842016-02-20 05:28:30 +0000602private:
Howard Hinnantc51e1022010-05-11 19:42:16 +0000603 allocator_type& __na_;
604
605 __map_node_destructor& operator=(const __map_node_destructor&);
606
607public:
608 bool __first_constructed;
609 bool __second_constructed;
610
Howard Hinnant756c69b2010-09-22 16:48:34 +0000611 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000612 explicit __map_node_destructor(allocator_type& __na) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +0000613 : __na_(__na),
614 __first_constructed(false),
615 __second_constructed(false)
616 {}
617
Eric Fiseliera85b1282017-04-18 21:08:06 +0000618#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant756c69b2010-09-22 16:48:34 +0000619 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000620 __map_node_destructor(__tree_node_destructor<allocator_type>&& __x) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +0000621 : __na_(__x.__na_),
622 __first_constructed(__x.__value_constructed),
623 __second_constructed(__x.__value_constructed)
624 {
625 __x.__value_constructed = false;
626 }
Eric Fiseliera85b1282017-04-18 21:08:06 +0000627#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000628
Howard Hinnant756c69b2010-09-22 16:48:34 +0000629 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000630 void operator()(pointer __p) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +0000631 {
632 if (__second_constructed)
Erik Pilkingtond3fe2992018-06-04 20:38:23 +0000633 __alloc_traits::destroy(__na_, _VSTD::addressof(__p->__value_.__get_value().second));
Howard Hinnantc51e1022010-05-11 19:42:16 +0000634 if (__first_constructed)
Erik Pilkingtond3fe2992018-06-04 20:38:23 +0000635 __alloc_traits::destroy(__na_, _VSTD::addressof(__p->__value_.__get_value().first));
Howard Hinnantc51e1022010-05-11 19:42:16 +0000636 if (__p)
637 __alloc_traits::deallocate(__na_, __p, 1);
638 }
639};
640
Howard Hinnant944510a2011-06-14 19:58:17 +0000641template <class _Key, class _Tp, class _Compare, class _Allocator>
642 class map;
643template <class _Key, class _Tp, class _Compare, class _Allocator>
644 class multimap;
645template <class _TreeIterator> class __map_const_iterator;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000646
Eric Fiseliera00b4842016-02-20 05:28:30 +0000647#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant89f8b792013-09-30 19:08:22 +0000648
649template <class _Key, class _Tp>
Erik Pilkingtond3fe2992018-06-04 20:38:23 +0000650struct __value_type
Howard Hinnant89f8b792013-09-30 19:08:22 +0000651{
652 typedef _Key key_type;
653 typedef _Tp mapped_type;
654 typedef pair<const key_type, mapped_type> value_type;
Erik Pilkingtond3fe2992018-06-04 20:38:23 +0000655 typedef pair<key_type&, mapped_type&> __nc_ref_pair_type;
656 typedef pair<key_type&&, mapped_type&&> __nc_rref_pair_type;
Howard Hinnant89f8b792013-09-30 19:08:22 +0000657
Erik Pilkingtond3fe2992018-06-04 20:38:23 +0000658private:
Howard Hinnant89f8b792013-09-30 19:08:22 +0000659 value_type __cc;
Erik Pilkingtond3fe2992018-06-04 20:38:23 +0000660
661public:
662 _LIBCPP_INLINE_VISIBILITY
663 value_type& __get_value()
664 {
665#if _LIBCPP_STD_VER > 14
666 return *_VSTD::launder(_VSTD::addressof(__cc));
667#else
668 return __cc;
669#endif
670 }
671
672 _LIBCPP_INLINE_VISIBILITY
673 const value_type& __get_value() const
674 {
675#if _LIBCPP_STD_VER > 14
676 return *_VSTD::launder(_VSTD::addressof(__cc));
677#else
678 return __cc;
679#endif
680 }
681
682 _LIBCPP_INLINE_VISIBILITY
683 __nc_ref_pair_type __ref()
684 {
685 value_type& __v = __get_value();
686 return __nc_ref_pair_type(const_cast<key_type&>(__v.first), __v.second);
687 }
688
689 _LIBCPP_INLINE_VISIBILITY
690 __nc_rref_pair_type __move()
691 {
692 value_type& __v = __get_value();
693 return __nc_rref_pair_type(
694 _VSTD::move(const_cast<key_type&>(__v.first)),
695 _VSTD::move(__v.second));
696 }
Howard Hinnant89f8b792013-09-30 19:08:22 +0000697
Howard Hinnant89f8b792013-09-30 19:08:22 +0000698 _LIBCPP_INLINE_VISIBILITY
699 __value_type& operator=(const __value_type& __v)
Erik Pilkingtond3fe2992018-06-04 20:38:23 +0000700 {
701 __ref() = __v.__get_value();
702 return *this;
703 }
Howard Hinnant89f8b792013-09-30 19:08:22 +0000704
705 _LIBCPP_INLINE_VISIBILITY
706 __value_type& operator=(__value_type&& __v)
Erik Pilkingtond3fe2992018-06-04 20:38:23 +0000707 {
708 __ref() = __v.__move();
709 return *this;
710 }
Howard Hinnant89f8b792013-09-30 19:08:22 +0000711
Eric Fiselierd06276b2016-03-31 02:15:15 +0000712 template <class _ValueTp,
713 class = typename enable_if<
714 __is_same_uncvref<_ValueTp, value_type>::value
715 >::type
716 >
Howard Hinnant89f8b792013-09-30 19:08:22 +0000717 _LIBCPP_INLINE_VISIBILITY
Erik Pilkingtond3fe2992018-06-04 20:38:23 +0000718 __value_type& operator=(_ValueTp&& __v)
719 {
720 __ref() = _VSTD::forward<_ValueTp>(__v);
721 return *this;
Eric Fiselierd06276b2016-03-31 02:15:15 +0000722 }
723
724private:
725 __value_type() _LIBCPP_EQUAL_DELETE;
726 ~__value_type() _LIBCPP_EQUAL_DELETE;
727 __value_type(const __value_type& __v) _LIBCPP_EQUAL_DELETE;
728 __value_type(__value_type&& __v) _LIBCPP_EQUAL_DELETE;
Howard Hinnant89f8b792013-09-30 19:08:22 +0000729};
730
731#else
732
733template <class _Key, class _Tp>
734struct __value_type
735{
736 typedef _Key key_type;
737 typedef _Tp mapped_type;
738 typedef pair<const key_type, mapped_type> value_type;
739
Erik Pilkingtond3fe2992018-06-04 20:38:23 +0000740private:
Howard Hinnant89f8b792013-09-30 19:08:22 +0000741 value_type __cc;
742
Erik Pilkingtond3fe2992018-06-04 20:38:23 +0000743public:
744 _LIBCPP_INLINE_VISIBILITY
745 value_type& __get_value() { return __cc; }
746 _LIBCPP_INLINE_VISIBILITY
747 const value_type& __get_value() const { return __cc; }
748
Eric Fiselierd06276b2016-03-31 02:15:15 +0000749private:
750 __value_type();
751 __value_type(__value_type const&);
752 __value_type& operator=(__value_type const&);
753 ~__value_type();
Howard Hinnant89f8b792013-09-30 19:08:22 +0000754};
755
Eric Fiseliera85b1282017-04-18 21:08:06 +0000756#endif // _LIBCPP_CXX03_LANG
Howard Hinnant89f8b792013-09-30 19:08:22 +0000757
Eric Fiselier44f9fd02015-03-03 20:10:01 +0000758template <class _Tp>
759struct __extract_key_value_types;
760
761template <class _Key, class _Tp>
762struct __extract_key_value_types<__value_type<_Key, _Tp> >
763{
764 typedef _Key const __key_type;
765 typedef _Tp __mapped_type;
766};
767
Howard Hinnantc51e1022010-05-11 19:42:16 +0000768template <class _TreeIterator>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000769class _LIBCPP_TEMPLATE_VIS __map_iterator
Howard Hinnantc51e1022010-05-11 19:42:16 +0000770{
Eric Fiseliera00b4842016-02-20 05:28:30 +0000771 typedef typename _TreeIterator::_NodeTypes _NodeTypes;
772 typedef typename _TreeIterator::__pointer_traits __pointer_traits;
773
Howard Hinnantc51e1022010-05-11 19:42:16 +0000774 _TreeIterator __i_;
775
Howard Hinnantc51e1022010-05-11 19:42:16 +0000776public:
777 typedef bidirectional_iterator_tag iterator_category;
Eric Fiseliera00b4842016-02-20 05:28:30 +0000778 typedef typename _NodeTypes::__map_value_type value_type;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000779 typedef typename _TreeIterator::difference_type difference_type;
780 typedef value_type& reference;
Eric Fiseliera00b4842016-02-20 05:28:30 +0000781 typedef typename _NodeTypes::__map_value_type_pointer pointer;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000782
Howard Hinnant756c69b2010-09-22 16:48:34 +0000783 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000784 __map_iterator() _NOEXCEPT {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000785
Howard Hinnant756c69b2010-09-22 16:48:34 +0000786 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000787 __map_iterator(_TreeIterator __i) _NOEXCEPT : __i_(__i) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000788
Howard Hinnant756c69b2010-09-22 16:48:34 +0000789 _LIBCPP_INLINE_VISIBILITY
Erik Pilkingtond3fe2992018-06-04 20:38:23 +0000790 reference operator*() const {return __i_->__get_value();}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000791 _LIBCPP_INLINE_VISIBILITY
Erik Pilkingtond3fe2992018-06-04 20:38:23 +0000792 pointer operator->() const {return pointer_traits<pointer>::pointer_to(__i_->__get_value());}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000793
Howard Hinnant756c69b2010-09-22 16:48:34 +0000794 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000795 __map_iterator& operator++() {++__i_; return *this;}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000796 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000797 __map_iterator operator++(int)
798 {
799 __map_iterator __t(*this);
800 ++(*this);
801 return __t;
802 }
803
Howard Hinnant756c69b2010-09-22 16:48:34 +0000804 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000805 __map_iterator& operator--() {--__i_; return *this;}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000806 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000807 __map_iterator operator--(int)
808 {
809 __map_iterator __t(*this);
810 --(*this);
811 return __t;
812 }
813
Howard Hinnant756c69b2010-09-22 16:48:34 +0000814 friend _LIBCPP_INLINE_VISIBILITY
815 bool operator==(const __map_iterator& __x, const __map_iterator& __y)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000816 {return __x.__i_ == __y.__i_;}
Eric Fiseliercf8c0212017-01-05 06:06:18 +0000817 friend
Howard Hinnant756c69b2010-09-22 16:48:34 +0000818 _LIBCPP_INLINE_VISIBILITY
819 bool operator!=(const __map_iterator& __x, const __map_iterator& __y)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000820 {return __x.__i_ != __y.__i_;}
821
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000822 template <class, class, class, class> friend class _LIBCPP_TEMPLATE_VIS map;
823 template <class, class, class, class> friend class _LIBCPP_TEMPLATE_VIS multimap;
824 template <class> friend class _LIBCPP_TEMPLATE_VIS __map_const_iterator;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000825};
826
827template <class _TreeIterator>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000828class _LIBCPP_TEMPLATE_VIS __map_const_iterator
Howard Hinnantc51e1022010-05-11 19:42:16 +0000829{
Eric Fiseliera00b4842016-02-20 05:28:30 +0000830 typedef typename _TreeIterator::_NodeTypes _NodeTypes;
831 typedef typename _TreeIterator::__pointer_traits __pointer_traits;
832
Howard Hinnantc51e1022010-05-11 19:42:16 +0000833 _TreeIterator __i_;
834
Howard Hinnantc51e1022010-05-11 19:42:16 +0000835public:
836 typedef bidirectional_iterator_tag iterator_category;
Eric Fiseliera00b4842016-02-20 05:28:30 +0000837 typedef typename _NodeTypes::__map_value_type value_type;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000838 typedef typename _TreeIterator::difference_type difference_type;
839 typedef const value_type& reference;
Eric Fiseliera00b4842016-02-20 05:28:30 +0000840 typedef typename _NodeTypes::__const_map_value_type_pointer pointer;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000841
Howard Hinnant756c69b2010-09-22 16:48:34 +0000842 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000843 __map_const_iterator() _NOEXCEPT {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000844
Howard Hinnant756c69b2010-09-22 16:48:34 +0000845 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000846 __map_const_iterator(_TreeIterator __i) _NOEXCEPT : __i_(__i) {}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000847 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier44f9fd02015-03-03 20:10:01 +0000848 __map_const_iterator(__map_iterator<
849 typename _TreeIterator::__non_const_iterator> __i) _NOEXCEPT
850 : __i_(__i.__i_) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000851
Howard Hinnant756c69b2010-09-22 16:48:34 +0000852 _LIBCPP_INLINE_VISIBILITY
Erik Pilkingtond3fe2992018-06-04 20:38:23 +0000853 reference operator*() const {return __i_->__get_value();}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000854 _LIBCPP_INLINE_VISIBILITY
Erik Pilkingtond3fe2992018-06-04 20:38:23 +0000855 pointer operator->() const {return pointer_traits<pointer>::pointer_to(__i_->__get_value());}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000856
Howard Hinnant756c69b2010-09-22 16:48:34 +0000857 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000858 __map_const_iterator& operator++() {++__i_; return *this;}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000859 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000860 __map_const_iterator operator++(int)
861 {
862 __map_const_iterator __t(*this);
863 ++(*this);
864 return __t;
865 }
866
Howard Hinnant756c69b2010-09-22 16:48:34 +0000867 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000868 __map_const_iterator& operator--() {--__i_; return *this;}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000869 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000870 __map_const_iterator operator--(int)
871 {
872 __map_const_iterator __t(*this);
873 --(*this);
874 return __t;
875 }
876
Howard Hinnant756c69b2010-09-22 16:48:34 +0000877 friend _LIBCPP_INLINE_VISIBILITY
878 bool operator==(const __map_const_iterator& __x, const __map_const_iterator& __y)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000879 {return __x.__i_ == __y.__i_;}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000880 friend _LIBCPP_INLINE_VISIBILITY
881 bool operator!=(const __map_const_iterator& __x, const __map_const_iterator& __y)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000882 {return __x.__i_ != __y.__i_;}
883
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000884 template <class, class, class, class> friend class _LIBCPP_TEMPLATE_VIS map;
885 template <class, class, class, class> friend class _LIBCPP_TEMPLATE_VIS multimap;
886 template <class, class, class> friend class _LIBCPP_TEMPLATE_VIS __tree_const_iterator;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000887};
888
889template <class _Key, class _Tp, class _Compare = less<_Key>,
890 class _Allocator = allocator<pair<const _Key, _Tp> > >
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000891class _LIBCPP_TEMPLATE_VIS map
Howard Hinnantc51e1022010-05-11 19:42:16 +0000892{
893public:
894 // types:
895 typedef _Key key_type;
896 typedef _Tp mapped_type;
897 typedef pair<const key_type, mapped_type> value_type;
898 typedef _Compare key_compare;
899 typedef _Allocator allocator_type;
900 typedef value_type& reference;
901 typedef const value_type& const_reference;
902
Marshall Clow5128cf32015-11-26 01:24:04 +0000903 static_assert((is_same<typename allocator_type::value_type, value_type>::value),
904 "Allocator::value_type must be same type as value_type");
905
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000906 class _LIBCPP_TEMPLATE_VIS value_compare
Howard Hinnantc51e1022010-05-11 19:42:16 +0000907 : public binary_function<value_type, value_type, bool>
908 {
909 friend class map;
910 protected:
911 key_compare comp;
912
Howard Hinnant756c69b2010-09-22 16:48:34 +0000913 _LIBCPP_INLINE_VISIBILITY value_compare(key_compare c) : comp(c) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000914 public:
Howard Hinnant756c69b2010-09-22 16:48:34 +0000915 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000916 bool operator()(const value_type& __x, const value_type& __y) const
917 {return comp(__x.first, __y.first);}
918 };
919
920private:
Howard Hinnant2d0046b2013-06-19 21:29:40 +0000921
Howard Hinnant89f8b792013-09-30 19:08:22 +0000922 typedef _VSTD::__value_type<key_type, mapped_type> __value_type;
Howard Hinnant90b91592013-07-05 18:06:00 +0000923 typedef __map_value_compare<key_type, __value_type, key_compare> __vc;
Marshall Clow940e01c2015-04-07 05:21:38 +0000924 typedef typename __rebind_alloc_helper<allocator_traits<allocator_type>,
925 __value_type>::type __allocator_type;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000926 typedef __tree<__value_type, __vc, __allocator_type> __base;
927 typedef typename __base::__node_traits __node_traits;
928 typedef allocator_traits<allocator_type> __alloc_traits;
929
930 __base __tree_;
931
932public:
933 typedef typename __alloc_traits::pointer pointer;
934 typedef typename __alloc_traits::const_pointer const_pointer;
935 typedef typename __alloc_traits::size_type size_type;
936 typedef typename __alloc_traits::difference_type difference_type;
Eric Fiselier44f9fd02015-03-03 20:10:01 +0000937 typedef __map_iterator<typename __base::iterator> iterator;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000938 typedef __map_const_iterator<typename __base::const_iterator> const_iterator;
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000939 typedef _VSTD::reverse_iterator<iterator> reverse_iterator;
940 typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000941
Erik Pilkingtonc37a3d82018-08-01 01:33:38 +0000942#if _LIBCPP_STD_VER > 14
943 typedef __map_node_handle<typename __base::__node, allocator_type> node_type;
944 typedef __insert_return_type<iterator, node_type> insert_return_type;
945#endif
946
Erik Pilkington82a65ad2018-10-31 17:31:35 +0000947 template <class _Key2, class _Value2, class _Comp2, class _Alloc2>
948 friend class _LIBCPP_TEMPLATE_VIS map;
949 template <class _Key2, class _Value2, class _Comp2, class _Alloc2>
950 friend class _LIBCPP_TEMPLATE_VIS multimap;
951
Howard Hinnant756c69b2010-09-22 16:48:34 +0000952 _LIBCPP_INLINE_VISIBILITY
Marshall Clow7086a5a2014-03-10 04:50:10 +0000953 map()
954 _NOEXCEPT_(
955 is_nothrow_default_constructible<allocator_type>::value &&
956 is_nothrow_default_constructible<key_compare>::value &&
957 is_nothrow_copy_constructible<key_compare>::value)
958 : __tree_(__vc(key_compare())) {}
959
960 _LIBCPP_INLINE_VISIBILITY
961 explicit map(const key_compare& __comp)
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000962 _NOEXCEPT_(
963 is_nothrow_default_constructible<allocator_type>::value &&
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000964 is_nothrow_copy_constructible<key_compare>::value)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000965 : __tree_(__vc(__comp)) {}
966
Howard Hinnant756c69b2010-09-22 16:48:34 +0000967 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000968 explicit map(const key_compare& __comp, const allocator_type& __a)
Marshall Clow657cbc42016-08-17 05:58:40 +0000969 : __tree_(__vc(__comp), typename __base::allocator_type(__a)) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000970
971 template <class _InputIterator>
Howard Hinnant756c69b2010-09-22 16:48:34 +0000972 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000973 map(_InputIterator __f, _InputIterator __l,
974 const key_compare& __comp = key_compare())
975 : __tree_(__vc(__comp))
976 {
977 insert(__f, __l);
978 }
979
980 template <class _InputIterator>
Howard Hinnant756c69b2010-09-22 16:48:34 +0000981 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000982 map(_InputIterator __f, _InputIterator __l,
983 const key_compare& __comp, const allocator_type& __a)
Marshall Clow657cbc42016-08-17 05:58:40 +0000984 : __tree_(__vc(__comp), typename __base::allocator_type(__a))
Howard Hinnantc51e1022010-05-11 19:42:16 +0000985 {
986 insert(__f, __l);
987 }
988
Marshall Clow300abfb2013-09-11 01:15:47 +0000989#if _LIBCPP_STD_VER > 11
990 template <class _InputIterator>
Eric Fiseliercf8c0212017-01-05 06:06:18 +0000991 _LIBCPP_INLINE_VISIBILITY
Marshall Clow300abfb2013-09-11 01:15:47 +0000992 map(_InputIterator __f, _InputIterator __l, const allocator_type& __a)
993 : map(__f, __l, key_compare(), __a) {}
994#endif
995
Howard Hinnant756c69b2010-09-22 16:48:34 +0000996 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000997 map(const map& __m)
998 : __tree_(__m.__tree_)
999 {
1000 insert(__m.begin(), __m.end());
1001 }
1002
Howard Hinnantd3a657f2011-07-01 19:24:36 +00001003 _LIBCPP_INLINE_VISIBILITY
1004 map& operator=(const map& __m)
1005 {
Marshall Clow476d3f42016-07-18 13:19:00 +00001006#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantd3a657f2011-07-01 19:24:36 +00001007 __tree_ = __m.__tree_;
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001008#else
Marshall Clowdb3cfcb2014-02-08 04:03:14 +00001009 if (this != &__m) {
1010 __tree_.clear();
1011 __tree_.value_comp() = __m.__tree_.value_comp();
1012 __tree_.__copy_assign_alloc(__m.__tree_);
1013 insert(__m.begin(), __m.end());
1014 }
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001015#endif
Howard Hinnantd3a657f2011-07-01 19:24:36 +00001016 return *this;
1017 }
1018
Eric Fiseliera85b1282017-04-18 21:08:06 +00001019#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001020
Howard Hinnant756c69b2010-09-22 16:48:34 +00001021 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001022 map(map&& __m)
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001023 _NOEXCEPT_(is_nothrow_move_constructible<__base>::value)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001024 : __tree_(_VSTD::move(__m.__tree_))
Howard Hinnantc51e1022010-05-11 19:42:16 +00001025 {
1026 }
1027
1028 map(map&& __m, const allocator_type& __a);
1029
Howard Hinnant756c69b2010-09-22 16:48:34 +00001030 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant33711792011-08-12 21:56:02 +00001031 map& operator=(map&& __m)
1032 _NOEXCEPT_(is_nothrow_move_assignable<__base>::value)
1033 {
1034 __tree_ = _VSTD::move(__m.__tree_);
1035 return *this;
1036 }
1037
Howard Hinnant33711792011-08-12 21:56:02 +00001038 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001039 map(initializer_list<value_type> __il, const key_compare& __comp = key_compare())
1040 : __tree_(__vc(__comp))
1041 {
1042 insert(__il.begin(), __il.end());
1043 }
1044
Howard Hinnant756c69b2010-09-22 16:48:34 +00001045 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001046 map(initializer_list<value_type> __il, const key_compare& __comp, const allocator_type& __a)
Marshall Clow657cbc42016-08-17 05:58:40 +00001047 : __tree_(__vc(__comp), typename __base::allocator_type(__a))
Howard Hinnantc51e1022010-05-11 19:42:16 +00001048 {
1049 insert(__il.begin(), __il.end());
1050 }
1051
Marshall Clow300abfb2013-09-11 01:15:47 +00001052#if _LIBCPP_STD_VER > 11
Eric Fiseliercf8c0212017-01-05 06:06:18 +00001053 _LIBCPP_INLINE_VISIBILITY
Marshall Clow300abfb2013-09-11 01:15:47 +00001054 map(initializer_list<value_type> __il, const allocator_type& __a)
1055 : map(__il, key_compare(), __a) {}
1056#endif
1057
Howard Hinnant756c69b2010-09-22 16:48:34 +00001058 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001059 map& operator=(initializer_list<value_type> __il)
1060 {
1061 __tree_.__assign_unique(__il.begin(), __il.end());
1062 return *this;
1063 }
1064
Eric Fiseliera85b1282017-04-18 21:08:06 +00001065#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001066
Howard Hinnant756c69b2010-09-22 16:48:34 +00001067 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001068 explicit map(const allocator_type& __a)
Marshall Clow657cbc42016-08-17 05:58:40 +00001069 : __tree_(typename __base::allocator_type(__a))
Howard Hinnantc51e1022010-05-11 19:42:16 +00001070 {
1071 }
1072
Howard Hinnant756c69b2010-09-22 16:48:34 +00001073 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001074 map(const map& __m, const allocator_type& __a)
Marshall Clow657cbc42016-08-17 05:58:40 +00001075 : __tree_(__m.__tree_.value_comp(), typename __base::allocator_type(__a))
Howard Hinnantc51e1022010-05-11 19:42:16 +00001076 {
1077 insert(__m.begin(), __m.end());
1078 }
1079
Howard Hinnant756c69b2010-09-22 16:48:34 +00001080 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001081 iterator begin() _NOEXCEPT {return __tree_.begin();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001082 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001083 const_iterator begin() const _NOEXCEPT {return __tree_.begin();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001084 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001085 iterator end() _NOEXCEPT {return __tree_.end();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001086 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001087 const_iterator end() const _NOEXCEPT {return __tree_.end();}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001088
Howard Hinnant756c69b2010-09-22 16:48:34 +00001089 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001090 reverse_iterator rbegin() _NOEXCEPT {return reverse_iterator(end());}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001091 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001092 const_reverse_iterator rbegin() const _NOEXCEPT
1093 {return const_reverse_iterator(end());}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001094 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001095 reverse_iterator rend() _NOEXCEPT
1096 {return reverse_iterator(begin());}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001097 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001098 const_reverse_iterator rend() const _NOEXCEPT
1099 {return const_reverse_iterator(begin());}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001100
Howard Hinnant756c69b2010-09-22 16:48:34 +00001101 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001102 const_iterator cbegin() const _NOEXCEPT {return begin();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001103 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001104 const_iterator cend() const _NOEXCEPT {return end();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001105 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001106 const_reverse_iterator crbegin() const _NOEXCEPT {return rbegin();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001107 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001108 const_reverse_iterator crend() const _NOEXCEPT {return rend();}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001109
Marshall Clow425f5752017-11-15 05:51:26 +00001110 _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001111 bool empty() const _NOEXCEPT {return __tree_.size() == 0;}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001112 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001113 size_type size() const _NOEXCEPT {return __tree_.size();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001114 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001115 size_type max_size() const _NOEXCEPT {return __tree_.max_size();}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001116
1117 mapped_type& operator[](const key_type& __k);
Eric Fiselierd63f38e2016-03-31 03:13:37 +00001118#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001119 mapped_type& operator[](key_type&& __k);
1120#endif
1121
1122 mapped_type& at(const key_type& __k);
1123 const mapped_type& at(const key_type& __k) const;
1124
Howard Hinnant756c69b2010-09-22 16:48:34 +00001125 _LIBCPP_INLINE_VISIBILITY
Marshall Clow657cbc42016-08-17 05:58:40 +00001126 allocator_type get_allocator() const _NOEXCEPT {return allocator_type(__tree_.__alloc());}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001127 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001128 key_compare key_comp() const {return __tree_.value_comp().key_comp();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001129 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001130 value_compare value_comp() const {return value_compare(__tree_.value_comp().key_comp());}
1131
Eric Fiselierd06276b2016-03-31 02:15:15 +00001132#ifndef _LIBCPP_CXX03_LANG
1133 template <class ..._Args>
1134 _LIBCPP_INLINE_VISIBILITY
1135 pair<iterator, bool> emplace(_Args&& ...__args) {
1136 return __tree_.__emplace_unique(_VSTD::forward<_Args>(__args)...);
1137 }
Howard Hinnant74279a52010-09-04 23:28:19 +00001138
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001139 template <class ..._Args>
Eric Fiselierd06276b2016-03-31 02:15:15 +00001140 _LIBCPP_INLINE_VISIBILITY
1141 iterator emplace_hint(const_iterator __p, _Args&& ...__args) {
1142 return __tree_.__emplace_hint_unique(__p.__i_, _VSTD::forward<_Args>(__args)...);
1143 }
Howard Hinnant74279a52010-09-04 23:28:19 +00001144
Howard Hinnantc834c512011-11-29 18:15:50 +00001145 template <class _Pp,
1146 class = typename enable_if<is_constructible<value_type, _Pp>::value>::type>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001147 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc834c512011-11-29 18:15:50 +00001148 pair<iterator, bool> insert(_Pp&& __p)
1149 {return __tree_.__insert_unique(_VSTD::forward<_Pp>(__p));}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001150
Howard Hinnantc834c512011-11-29 18:15:50 +00001151 template <class _Pp,
1152 class = typename enable_if<is_constructible<value_type, _Pp>::value>::type>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001153 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc834c512011-11-29 18:15:50 +00001154 iterator insert(const_iterator __pos, _Pp&& __p)
1155 {return __tree_.__insert_unique(__pos.__i_, _VSTD::forward<_Pp>(__p));}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001156
Eric Fiselierd06276b2016-03-31 02:15:15 +00001157#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001158
Howard Hinnant756c69b2010-09-22 16:48:34 +00001159 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001160 pair<iterator, bool>
1161 insert(const value_type& __v) {return __tree_.__insert_unique(__v);}
1162
Howard Hinnant756c69b2010-09-22 16:48:34 +00001163 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001164 iterator
1165 insert(const_iterator __p, const value_type& __v)
1166 {return __tree_.__insert_unique(__p.__i_, __v);}
1167
Eric Fiselierd6143132016-04-18 01:40:45 +00001168#ifndef _LIBCPP_CXX03_LANG
Marshall Clowd430d022016-01-05 19:32:41 +00001169 _LIBCPP_INLINE_VISIBILITY
1170 pair<iterator, bool>
Eric Fiselierd06276b2016-03-31 02:15:15 +00001171 insert(value_type&& __v) {return __tree_.__insert_unique(_VSTD::move(__v));}
Marshall Clowd430d022016-01-05 19:32:41 +00001172
1173 _LIBCPP_INLINE_VISIBILITY
Eric Fiselierd06276b2016-03-31 02:15:15 +00001174 iterator insert(const_iterator __p, value_type&& __v)
1175 {return __tree_.__insert_unique(__p.__i_, _VSTD::move(__v));}
Eric Fiseliera85b1282017-04-18 21:08:06 +00001176
1177 _LIBCPP_INLINE_VISIBILITY
1178 void insert(initializer_list<value_type> __il)
1179 {insert(__il.begin(), __il.end());}
Marshall Clowd430d022016-01-05 19:32:41 +00001180#endif
1181
Howard Hinnantc51e1022010-05-11 19:42:16 +00001182 template <class _InputIterator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001183 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001184 void insert(_InputIterator __f, _InputIterator __l)
1185 {
1186 for (const_iterator __e = cend(); __f != __l; ++__f)
1187 insert(__e.__i_, *__f);
1188 }
1189
Marshall Clow3223db82015-07-07 03:37:33 +00001190#if _LIBCPP_STD_VER > 14
Eric Fiselierd63f38e2016-03-31 03:13:37 +00001191
Marshall Clow3223db82015-07-07 03:37:33 +00001192 template <class... _Args>
1193 _LIBCPP_INLINE_VISIBILITY
1194 pair<iterator, bool> try_emplace(const key_type& __k, _Args&&... __args)
1195 {
Eric Fiselierd63f38e2016-03-31 03:13:37 +00001196 return __tree_.__emplace_unique_key_args(__k,
1197 _VSTD::piecewise_construct,
1198 _VSTD::forward_as_tuple(__k),
1199 _VSTD::forward_as_tuple(_VSTD::forward<_Args>(__args)...));
Marshall Clow3223db82015-07-07 03:37:33 +00001200 }
1201
1202 template <class... _Args>
1203 _LIBCPP_INLINE_VISIBILITY
1204 pair<iterator, bool> try_emplace(key_type&& __k, _Args&&... __args)
1205 {
Eric Fiselierd63f38e2016-03-31 03:13:37 +00001206 return __tree_.__emplace_unique_key_args(__k,
1207 _VSTD::piecewise_construct,
1208 _VSTD::forward_as_tuple(_VSTD::move(__k)),
1209 _VSTD::forward_as_tuple(_VSTD::forward<_Args>(__args)...));
Marshall Clow3223db82015-07-07 03:37:33 +00001210 }
1211
1212 template <class... _Args>
1213 _LIBCPP_INLINE_VISIBILITY
1214 iterator try_emplace(const_iterator __h, const key_type& __k, _Args&&... __args)
1215 {
Eric Fiselierd63f38e2016-03-31 03:13:37 +00001216 return __tree_.__emplace_hint_unique_key_args(__h.__i_, __k,
1217 _VSTD::piecewise_construct,
1218 _VSTD::forward_as_tuple(__k),
1219 _VSTD::forward_as_tuple(_VSTD::forward<_Args>(__args)...));
Marshall Clow3223db82015-07-07 03:37:33 +00001220 }
1221
1222 template <class... _Args>
1223 _LIBCPP_INLINE_VISIBILITY
1224 iterator try_emplace(const_iterator __h, key_type&& __k, _Args&&... __args)
1225 {
Eric Fiselierd63f38e2016-03-31 03:13:37 +00001226 return __tree_.__emplace_hint_unique_key_args(__h.__i_, __k,
1227 _VSTD::piecewise_construct,
1228 _VSTD::forward_as_tuple(_VSTD::move(__k)),
1229 _VSTD::forward_as_tuple(_VSTD::forward<_Args>(__args)...));
Marshall Clow3223db82015-07-07 03:37:33 +00001230 }
1231
1232 template <class _Vp>
1233 _LIBCPP_INLINE_VISIBILITY
1234 pair<iterator, bool> insert_or_assign(const key_type& __k, _Vp&& __v)
1235 {
1236 iterator __p = lower_bound(__k);
1237 if ( __p != end() && !key_comp()(__k, __p->first))
1238 {
1239 __p->second = _VSTD::forward<_Vp>(__v);
1240 return _VSTD::make_pair(__p, false);
1241 }
1242 return _VSTD::make_pair(emplace_hint(__p, __k, _VSTD::forward<_Vp>(__v)), true);
1243 }
Eric Fiselierd63f38e2016-03-31 03:13:37 +00001244
Marshall Clow3223db82015-07-07 03:37:33 +00001245 template <class _Vp>
1246 _LIBCPP_INLINE_VISIBILITY
1247 pair<iterator, bool> insert_or_assign(key_type&& __k, _Vp&& __v)
1248 {
1249 iterator __p = lower_bound(__k);
1250 if ( __p != end() && !key_comp()(__k, __p->first))
1251 {
1252 __p->second = _VSTD::forward<_Vp>(__v);
1253 return _VSTD::make_pair(__p, false);
1254 }
1255 return _VSTD::make_pair(emplace_hint(__p, _VSTD::move(__k), _VSTD::forward<_Vp>(__v)), true);
1256 }
1257
1258 template <class _Vp>
1259 _LIBCPP_INLINE_VISIBILITY
1260 iterator insert_or_assign(const_iterator __h, const key_type& __k, _Vp&& __v)
1261 {
1262 iterator __p = lower_bound(__k);
1263 if ( __p != end() && !key_comp()(__k, __p->first))
1264 {
1265 __p->second = _VSTD::forward<_Vp>(__v);
1266 return __p;
1267 }
1268 return emplace_hint(__h, __k, _VSTD::forward<_Vp>(__v));
1269 }
1270
1271 template <class _Vp>
1272 _LIBCPP_INLINE_VISIBILITY
1273 iterator insert_or_assign(const_iterator __h, key_type&& __k, _Vp&& __v)
1274 {
1275 iterator __p = lower_bound(__k);
1276 if ( __p != end() && !key_comp()(__k, __p->first))
1277 {
1278 __p->second = _VSTD::forward<_Vp>(__v);
1279 return __p;
1280 }
1281 return emplace_hint(__h, _VSTD::move(__k), _VSTD::forward<_Vp>(__v));
1282 }
Eric Fiselierd63f38e2016-03-31 03:13:37 +00001283
Eric Fiseliera85b1282017-04-18 21:08:06 +00001284#endif // _LIBCPP_STD_VER > 14
Marshall Clow3223db82015-07-07 03:37:33 +00001285
Howard Hinnant756c69b2010-09-22 16:48:34 +00001286 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001287 iterator erase(const_iterator __p) {return __tree_.erase(__p.__i_);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001288 _LIBCPP_INLINE_VISIBILITY
Marshall Clow22ea5b82015-05-10 13:35:00 +00001289 iterator erase(iterator __p) {return __tree_.erase(__p.__i_);}
1290 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001291 size_type erase(const key_type& __k)
1292 {return __tree_.__erase_unique(__k);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001293 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001294 iterator erase(const_iterator __f, const_iterator __l)
1295 {return __tree_.erase(__f.__i_, __l.__i_);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001296 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001297 void clear() _NOEXCEPT {__tree_.clear();}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001298
Erik Pilkingtonc37a3d82018-08-01 01:33:38 +00001299#if _LIBCPP_STD_VER > 14
1300 _LIBCPP_INLINE_VISIBILITY
1301 insert_return_type insert(node_type&& __nh)
1302 {
1303 _LIBCPP_ASSERT(__nh.empty() || __nh.get_allocator() == get_allocator(),
1304 "node_type with incompatible allocator passed to map::insert()");
1305 return __tree_.template __node_handle_insert_unique<
1306 node_type, insert_return_type>(_VSTD::move(__nh));
1307 }
1308 _LIBCPP_INLINE_VISIBILITY
1309 iterator insert(const_iterator __hint, node_type&& __nh)
1310 {
1311 _LIBCPP_ASSERT(__nh.empty() || __nh.get_allocator() == get_allocator(),
1312 "node_type with incompatible allocator passed to map::insert()");
1313 return __tree_.template __node_handle_insert_unique<node_type>(
1314 __hint.__i_, _VSTD::move(__nh));
1315 }
1316 _LIBCPP_INLINE_VISIBILITY
1317 node_type extract(key_type const& __key)
1318 {
1319 return __tree_.template __node_handle_extract<node_type>(__key);
1320 }
1321 _LIBCPP_INLINE_VISIBILITY
1322 node_type extract(const_iterator __it)
1323 {
1324 return __tree_.template __node_handle_extract<node_type>(__it.__i_);
1325 }
Erik Pilkington82a65ad2018-10-31 17:31:35 +00001326 template <class _C2>
1327 _LIBCPP_INLINE_VISIBILITY
1328 void merge(map<key_type, mapped_type, _C2, allocator_type>& __source)
1329 {
1330 _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
1331 "merging container with incompatible allocator");
1332 __tree_.__node_handle_merge_unique(__source.__tree_);
1333 }
1334 template <class _C2>
1335 _LIBCPP_INLINE_VISIBILITY
1336 void merge(map<key_type, mapped_type, _C2, allocator_type>&& __source)
1337 {
1338 _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
1339 "merging container with incompatible allocator");
1340 __tree_.__node_handle_merge_unique(__source.__tree_);
1341 }
1342 template <class _C2>
1343 _LIBCPP_INLINE_VISIBILITY
1344 void merge(multimap<key_type, mapped_type, _C2, allocator_type>& __source)
1345 {
1346 _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
1347 "merging container with incompatible allocator");
1348 __tree_.__node_handle_merge_unique(__source.__tree_);
1349 }
1350 template <class _C2>
1351 _LIBCPP_INLINE_VISIBILITY
1352 void merge(multimap<key_type, mapped_type, _C2, allocator_type>&& __source)
1353 {
1354 _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
1355 "merging container with incompatible allocator");
1356 __tree_.__node_handle_merge_unique(__source.__tree_);
1357 }
Erik Pilkingtonc37a3d82018-08-01 01:33:38 +00001358#endif
1359
Howard Hinnant756c69b2010-09-22 16:48:34 +00001360 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001361 void swap(map& __m)
1362 _NOEXCEPT_(__is_nothrow_swappable<__base>::value)
1363 {__tree_.swap(__m.__tree_);}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001364
Howard Hinnant756c69b2010-09-22 16:48:34 +00001365 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001366 iterator find(const key_type& __k) {return __tree_.find(__k);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001367 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001368 const_iterator find(const key_type& __k) const {return __tree_.find(__k);}
Marshall Clowebb57322013-08-13 22:18:47 +00001369#if _LIBCPP_STD_VER > 11
1370 template <typename _K2>
1371 _LIBCPP_INLINE_VISIBILITY
1372 typename enable_if<__is_transparent<_Compare, _K2>::value,iterator>::type
1373 find(const _K2& __k) {return __tree_.find(__k);}
1374 template <typename _K2>
1375 _LIBCPP_INLINE_VISIBILITY
1376 typename enable_if<__is_transparent<_Compare, _K2>::value,const_iterator>::type
1377 find(const _K2& __k) const {return __tree_.find(__k);}
1378#endif
1379
Howard Hinnant756c69b2010-09-22 16:48:34 +00001380 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001381 size_type count(const key_type& __k) const
1382 {return __tree_.__count_unique(__k);}
Marshall Clowe6a5f522014-08-24 23:54:16 +00001383#if _LIBCPP_STD_VER > 11
1384 template <typename _K2>
1385 _LIBCPP_INLINE_VISIBILITY
1386 typename enable_if<__is_transparent<_Compare, _K2>::value,size_type>::type
Eric Fiseliera85c9e92018-02-10 02:53:47 +00001387 count(const _K2& __k) const {return __tree_.__count_multi(__k);}
Marshall Clowe6a5f522014-08-24 23:54:16 +00001388#endif
Howard Hinnant756c69b2010-09-22 16:48:34 +00001389 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001390 iterator lower_bound(const key_type& __k)
1391 {return __tree_.lower_bound(__k);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001392 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001393 const_iterator lower_bound(const key_type& __k) const
1394 {return __tree_.lower_bound(__k);}
Marshall Clowebb57322013-08-13 22:18:47 +00001395#if _LIBCPP_STD_VER > 11
1396 template <typename _K2>
1397 _LIBCPP_INLINE_VISIBILITY
1398 typename enable_if<__is_transparent<_Compare, _K2>::value,iterator>::type
1399 lower_bound(const _K2& __k) {return __tree_.lower_bound(__k);}
1400
1401 template <typename _K2>
1402 _LIBCPP_INLINE_VISIBILITY
1403 typename enable_if<__is_transparent<_Compare, _K2>::value,const_iterator>::type
1404 lower_bound(const _K2& __k) const {return __tree_.lower_bound(__k);}
1405#endif
1406
Howard Hinnant756c69b2010-09-22 16:48:34 +00001407 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001408 iterator upper_bound(const key_type& __k)
1409 {return __tree_.upper_bound(__k);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001410 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001411 const_iterator upper_bound(const key_type& __k) const
1412 {return __tree_.upper_bound(__k);}
Marshall Clowebb57322013-08-13 22:18:47 +00001413#if _LIBCPP_STD_VER > 11
1414 template <typename _K2>
1415 _LIBCPP_INLINE_VISIBILITY
1416 typename enable_if<__is_transparent<_Compare, _K2>::value,iterator>::type
1417 upper_bound(const _K2& __k) {return __tree_.upper_bound(__k);}
1418 template <typename _K2>
1419 _LIBCPP_INLINE_VISIBILITY
1420 typename enable_if<__is_transparent<_Compare, _K2>::value,const_iterator>::type
1421 upper_bound(const _K2& __k) const {return __tree_.upper_bound(__k);}
1422#endif
1423
Howard Hinnant756c69b2010-09-22 16:48:34 +00001424 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001425 pair<iterator,iterator> equal_range(const key_type& __k)
1426 {return __tree_.__equal_range_unique(__k);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001427 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001428 pair<const_iterator,const_iterator> equal_range(const key_type& __k) const
1429 {return __tree_.__equal_range_unique(__k);}
Marshall Clowebb57322013-08-13 22:18:47 +00001430#if _LIBCPP_STD_VER > 11
1431 template <typename _K2>
1432 _LIBCPP_INLINE_VISIBILITY
1433 typename enable_if<__is_transparent<_Compare, _K2>::value,pair<iterator,iterator>>::type
Eric Fiseliera85c9e92018-02-10 02:53:47 +00001434 equal_range(const _K2& __k) {return __tree_.__equal_range_multi(__k);}
Marshall Clowebb57322013-08-13 22:18:47 +00001435 template <typename _K2>
1436 _LIBCPP_INLINE_VISIBILITY
1437 typename enable_if<__is_transparent<_Compare, _K2>::value,pair<const_iterator,const_iterator>>::type
Eric Fiseliera85c9e92018-02-10 02:53:47 +00001438 equal_range(const _K2& __k) const {return __tree_.__equal_range_multi(__k);}
Marshall Clowebb57322013-08-13 22:18:47 +00001439#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001440
1441private:
1442 typedef typename __base::__node __node;
1443 typedef typename __base::__node_allocator __node_allocator;
1444 typedef typename __base::__node_pointer __node_pointer;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001445 typedef typename __base::__node_base_pointer __node_base_pointer;
Eric Fiseliercf8c0212017-01-05 06:06:18 +00001446 typedef typename __base::__parent_pointer __parent_pointer;
Eric Fiseliera92b0732016-02-20 07:12:17 +00001447
Howard Hinnantc834c512011-11-29 18:15:50 +00001448 typedef __map_node_destructor<__node_allocator> _Dp;
1449 typedef unique_ptr<__node, _Dp> __node_holder;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001450
Eric Fiselierd63f38e2016-03-31 03:13:37 +00001451#ifdef _LIBCPP_CXX03_LANG
Howard Hinnantac7e7482013-07-04 20:59:16 +00001452 __node_holder __construct_node_with_key(const key_type& __k);
Eric Fiselierd63f38e2016-03-31 03:13:37 +00001453#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001454};
1455
Eric Fiseliera92b0732016-02-20 07:12:17 +00001456
Eric Fiselierd06276b2016-03-31 02:15:15 +00001457#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001458template <class _Key, class _Tp, class _Compare, class _Allocator>
1459map<_Key, _Tp, _Compare, _Allocator>::map(map&& __m, const allocator_type& __a)
Marshall Clow657cbc42016-08-17 05:58:40 +00001460 : __tree_(_VSTD::move(__m.__tree_), typename __base::allocator_type(__a))
Howard Hinnantc51e1022010-05-11 19:42:16 +00001461{
1462 if (__a != __m.get_allocator())
1463 {
1464 const_iterator __e = cend();
1465 while (!__m.empty())
1466 __tree_.__insert_unique(__e.__i_,
Erik Pilkingtond3fe2992018-06-04 20:38:23 +00001467 __m.__tree_.remove(__m.begin().__i_)->__value_.__move());
Howard Hinnantc51e1022010-05-11 19:42:16 +00001468 }
1469}
1470
Eric Fiseliera85b1282017-04-18 21:08:06 +00001471template <class _Key, class _Tp, class _Compare, class _Allocator>
1472_Tp&
1473map<_Key, _Tp, _Compare, _Allocator>::operator[](const key_type& __k)
1474{
1475 return __tree_.__emplace_unique_key_args(__k,
1476 _VSTD::piecewise_construct,
1477 _VSTD::forward_as_tuple(__k),
Erik Pilkingtond3fe2992018-06-04 20:38:23 +00001478 _VSTD::forward_as_tuple()).first->__get_value().second;
Eric Fiseliera85b1282017-04-18 21:08:06 +00001479}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001480
Eric Fiseliera85b1282017-04-18 21:08:06 +00001481template <class _Key, class _Tp, class _Compare, class _Allocator>
1482_Tp&
1483map<_Key, _Tp, _Compare, _Allocator>::operator[](key_type&& __k)
1484{
1485 return __tree_.__emplace_unique_key_args(__k,
1486 _VSTD::piecewise_construct,
1487 _VSTD::forward_as_tuple(_VSTD::move(__k)),
Erik Pilkingtond3fe2992018-06-04 20:38:23 +00001488 _VSTD::forward_as_tuple()).first->__get_value().second;
Eric Fiseliera85b1282017-04-18 21:08:06 +00001489}
Eric Fiselierd63f38e2016-03-31 03:13:37 +00001490
Eric Fiseliera85b1282017-04-18 21:08:06 +00001491#else // _LIBCPP_CXX03_LANG
Eric Fiselierd63f38e2016-03-31 03:13:37 +00001492
Howard Hinnantc51e1022010-05-11 19:42:16 +00001493template <class _Key, class _Tp, class _Compare, class _Allocator>
1494typename map<_Key, _Tp, _Compare, _Allocator>::__node_holder
Howard Hinnantac7e7482013-07-04 20:59:16 +00001495map<_Key, _Tp, _Compare, _Allocator>::__construct_node_with_key(const key_type& __k)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001496{
1497 __node_allocator& __na = __tree_.__node_alloc();
Howard Hinnantc834c512011-11-29 18:15:50 +00001498 __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
Erik Pilkingtond3fe2992018-06-04 20:38:23 +00001499 __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__get_value().first), __k);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001500 __h.get_deleter().__first_constructed = true;
Erik Pilkingtond3fe2992018-06-04 20:38:23 +00001501 __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__get_value().second));
Howard Hinnantc51e1022010-05-11 19:42:16 +00001502 __h.get_deleter().__second_constructed = true;
Dimitry Andric830fb602015-08-19 06:43:33 +00001503 return _LIBCPP_EXPLICIT_MOVE(__h); // explicitly moved for C++03
Howard Hinnantc51e1022010-05-11 19:42:16 +00001504}
1505
Howard Hinnantc51e1022010-05-11 19:42:16 +00001506template <class _Key, class _Tp, class _Compare, class _Allocator>
1507_Tp&
1508map<_Key, _Tp, _Compare, _Allocator>::operator[](const key_type& __k)
1509{
Eric Fiseliercf8c0212017-01-05 06:06:18 +00001510 __parent_pointer __parent;
1511 __node_base_pointer& __child = __tree_.__find_equal(__parent, __k);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001512 __node_pointer __r = static_cast<__node_pointer>(__child);
1513 if (__child == nullptr)
1514 {
Howard Hinnantac7e7482013-07-04 20:59:16 +00001515 __node_holder __h = __construct_node_with_key(__k);
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001516 __tree_.__insert_node_at(__parent, __child, static_cast<__node_base_pointer>(__h.get()));
Howard Hinnantc51e1022010-05-11 19:42:16 +00001517 __r = __h.release();
1518 }
Erik Pilkingtond3fe2992018-06-04 20:38:23 +00001519 return __r->__value_.__get_value().second;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001520}
1521
Eric Fiseliera85b1282017-04-18 21:08:06 +00001522#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001523
1524template <class _Key, class _Tp, class _Compare, class _Allocator>
1525_Tp&
1526map<_Key, _Tp, _Compare, _Allocator>::at(const key_type& __k)
1527{
Eric Fiseliercf8c0212017-01-05 06:06:18 +00001528 __parent_pointer __parent;
1529 __node_base_pointer& __child = __tree_.__find_equal(__parent, __k);
Howard Hinnant72f73582010-08-11 17:04:31 +00001530#ifndef _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +00001531 if (__child == nullptr)
1532 throw out_of_range("map::at: key not found");
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001533#endif // _LIBCPP_NO_EXCEPTIONS
Erik Pilkingtond3fe2992018-06-04 20:38:23 +00001534 return static_cast<__node_pointer>(__child)->__value_.__get_value().second;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001535}
1536
1537template <class _Key, class _Tp, class _Compare, class _Allocator>
1538const _Tp&
1539map<_Key, _Tp, _Compare, _Allocator>::at(const key_type& __k) const
1540{
Eric Fiseliercf8c0212017-01-05 06:06:18 +00001541 __parent_pointer __parent;
1542 __node_base_pointer __child = __tree_.__find_equal(__parent, __k);
Howard Hinnant72f73582010-08-11 17:04:31 +00001543#ifndef _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +00001544 if (__child == nullptr)
1545 throw out_of_range("map::at: key not found");
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001546#endif // _LIBCPP_NO_EXCEPTIONS
Erik Pilkingtond3fe2992018-06-04 20:38:23 +00001547 return static_cast<__node_pointer>(__child)->__value_.__get_value().second;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001548}
1549
Howard Hinnantc51e1022010-05-11 19:42:16 +00001550
1551template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001552inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001553bool
1554operator==(const map<_Key, _Tp, _Compare, _Allocator>& __x,
1555 const map<_Key, _Tp, _Compare, _Allocator>& __y)
1556{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001557 return __x.size() == __y.size() && _VSTD::equal(__x.begin(), __x.end(), __y.begin());
Howard Hinnantc51e1022010-05-11 19:42:16 +00001558}
1559
1560template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001561inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001562bool
1563operator< (const map<_Key, _Tp, _Compare, _Allocator>& __x,
1564 const map<_Key, _Tp, _Compare, _Allocator>& __y)
1565{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001566 return _VSTD::lexicographical_compare(__x.begin(), __x.end(), __y.begin(), __y.end());
Howard Hinnantc51e1022010-05-11 19:42:16 +00001567}
1568
1569template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001570inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001571bool
1572operator!=(const map<_Key, _Tp, _Compare, _Allocator>& __x,
1573 const map<_Key, _Tp, _Compare, _Allocator>& __y)
1574{
1575 return !(__x == __y);
1576}
1577
1578template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001579inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001580bool
1581operator> (const map<_Key, _Tp, _Compare, _Allocator>& __x,
1582 const map<_Key, _Tp, _Compare, _Allocator>& __y)
1583{
1584 return __y < __x;
1585}
1586
1587template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001588inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001589bool
1590operator>=(const map<_Key, _Tp, _Compare, _Allocator>& __x,
1591 const map<_Key, _Tp, _Compare, _Allocator>& __y)
1592{
1593 return !(__x < __y);
1594}
1595
1596template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001597inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001598bool
1599operator<=(const map<_Key, _Tp, _Compare, _Allocator>& __x,
1600 const map<_Key, _Tp, _Compare, _Allocator>& __y)
1601{
1602 return !(__y < __x);
1603}
1604
1605template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001606inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001607void
1608swap(map<_Key, _Tp, _Compare, _Allocator>& __x,
1609 map<_Key, _Tp, _Compare, _Allocator>& __y)
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001610 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
Howard Hinnantc51e1022010-05-11 19:42:16 +00001611{
1612 __x.swap(__y);
1613}
1614
1615template <class _Key, class _Tp, class _Compare = less<_Key>,
1616 class _Allocator = allocator<pair<const _Key, _Tp> > >
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00001617class _LIBCPP_TEMPLATE_VIS multimap
Howard Hinnantc51e1022010-05-11 19:42:16 +00001618{
1619public:
1620 // types:
1621 typedef _Key key_type;
1622 typedef _Tp mapped_type;
1623 typedef pair<const key_type, mapped_type> value_type;
1624 typedef _Compare key_compare;
1625 typedef _Allocator allocator_type;
1626 typedef value_type& reference;
1627 typedef const value_type& const_reference;
1628
Marshall Clow5128cf32015-11-26 01:24:04 +00001629 static_assert((is_same<typename allocator_type::value_type, value_type>::value),
1630 "Allocator::value_type must be same type as value_type");
1631
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00001632 class _LIBCPP_TEMPLATE_VIS value_compare
Howard Hinnantc51e1022010-05-11 19:42:16 +00001633 : public binary_function<value_type, value_type, bool>
1634 {
1635 friend class multimap;
1636 protected:
1637 key_compare comp;
1638
Howard Hinnant756c69b2010-09-22 16:48:34 +00001639 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001640 value_compare(key_compare c) : comp(c) {}
1641 public:
Howard Hinnant756c69b2010-09-22 16:48:34 +00001642 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001643 bool operator()(const value_type& __x, const value_type& __y) const
1644 {return comp(__x.first, __y.first);}
1645 };
1646
1647private:
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001648
Howard Hinnant89f8b792013-09-30 19:08:22 +00001649 typedef _VSTD::__value_type<key_type, mapped_type> __value_type;
Howard Hinnant90b91592013-07-05 18:06:00 +00001650 typedef __map_value_compare<key_type, __value_type, key_compare> __vc;
Marshall Clow940e01c2015-04-07 05:21:38 +00001651 typedef typename __rebind_alloc_helper<allocator_traits<allocator_type>,
1652 __value_type>::type __allocator_type;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001653 typedef __tree<__value_type, __vc, __allocator_type> __base;
1654 typedef typename __base::__node_traits __node_traits;
1655 typedef allocator_traits<allocator_type> __alloc_traits;
1656
1657 __base __tree_;
1658
1659public:
1660 typedef typename __alloc_traits::pointer pointer;
1661 typedef typename __alloc_traits::const_pointer const_pointer;
1662 typedef typename __alloc_traits::size_type size_type;
1663 typedef typename __alloc_traits::difference_type difference_type;
1664 typedef __map_iterator<typename __base::iterator> iterator;
1665 typedef __map_const_iterator<typename __base::const_iterator> const_iterator;
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001666 typedef _VSTD::reverse_iterator<iterator> reverse_iterator;
1667 typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001668
Erik Pilkingtonc37a3d82018-08-01 01:33:38 +00001669#if _LIBCPP_STD_VER > 14
1670 typedef __map_node_handle<typename __base::__node, allocator_type> node_type;
1671#endif
1672
Erik Pilkington82a65ad2018-10-31 17:31:35 +00001673 template <class _Key2, class _Value2, class _Comp2, class _Alloc2>
1674 friend class _LIBCPP_TEMPLATE_VIS map;
1675 template <class _Key2, class _Value2, class _Comp2, class _Alloc2>
1676 friend class _LIBCPP_TEMPLATE_VIS multimap;
1677
Howard Hinnant756c69b2010-09-22 16:48:34 +00001678 _LIBCPP_INLINE_VISIBILITY
Marshall Clow7086a5a2014-03-10 04:50:10 +00001679 multimap()
1680 _NOEXCEPT_(
1681 is_nothrow_default_constructible<allocator_type>::value &&
1682 is_nothrow_default_constructible<key_compare>::value &&
1683 is_nothrow_copy_constructible<key_compare>::value)
1684 : __tree_(__vc(key_compare())) {}
1685
1686 _LIBCPP_INLINE_VISIBILITY
1687 explicit multimap(const key_compare& __comp)
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001688 _NOEXCEPT_(
1689 is_nothrow_default_constructible<allocator_type>::value &&
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001690 is_nothrow_copy_constructible<key_compare>::value)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001691 : __tree_(__vc(__comp)) {}
1692
Howard Hinnant756c69b2010-09-22 16:48:34 +00001693 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001694 explicit multimap(const key_compare& __comp, const allocator_type& __a)
Marshall Clow657cbc42016-08-17 05:58:40 +00001695 : __tree_(__vc(__comp), typename __base::allocator_type(__a)) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001696
1697 template <class _InputIterator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001698 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001699 multimap(_InputIterator __f, _InputIterator __l,
1700 const key_compare& __comp = key_compare())
1701 : __tree_(__vc(__comp))
1702 {
1703 insert(__f, __l);
1704 }
1705
1706 template <class _InputIterator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001707 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001708 multimap(_InputIterator __f, _InputIterator __l,
1709 const key_compare& __comp, const allocator_type& __a)
Marshall Clow657cbc42016-08-17 05:58:40 +00001710 : __tree_(__vc(__comp), typename __base::allocator_type(__a))
Howard Hinnantc51e1022010-05-11 19:42:16 +00001711 {
1712 insert(__f, __l);
1713 }
1714
Marshall Clow300abfb2013-09-11 01:15:47 +00001715#if _LIBCPP_STD_VER > 11
1716 template <class _InputIterator>
Eric Fiseliercf8c0212017-01-05 06:06:18 +00001717 _LIBCPP_INLINE_VISIBILITY
Marshall Clow300abfb2013-09-11 01:15:47 +00001718 multimap(_InputIterator __f, _InputIterator __l, const allocator_type& __a)
1719 : multimap(__f, __l, key_compare(), __a) {}
1720#endif
1721
Howard Hinnant756c69b2010-09-22 16:48:34 +00001722 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001723 multimap(const multimap& __m)
1724 : __tree_(__m.__tree_.value_comp(),
1725 __alloc_traits::select_on_container_copy_construction(__m.__tree_.__alloc()))
1726 {
1727 insert(__m.begin(), __m.end());
1728 }
1729
Howard Hinnantd3a657f2011-07-01 19:24:36 +00001730 _LIBCPP_INLINE_VISIBILITY
1731 multimap& operator=(const multimap& __m)
1732 {
Marshall Clow476d3f42016-07-18 13:19:00 +00001733#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantd3a657f2011-07-01 19:24:36 +00001734 __tree_ = __m.__tree_;
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001735#else
Marshall Clowdb3cfcb2014-02-08 04:03:14 +00001736 if (this != &__m) {
1737 __tree_.clear();
1738 __tree_.value_comp() = __m.__tree_.value_comp();
1739 __tree_.__copy_assign_alloc(__m.__tree_);
1740 insert(__m.begin(), __m.end());
1741 }
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001742#endif
Howard Hinnantd3a657f2011-07-01 19:24:36 +00001743 return *this;
1744 }
1745
Eric Fiseliera85b1282017-04-18 21:08:06 +00001746#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001747
Howard Hinnant756c69b2010-09-22 16:48:34 +00001748 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001749 multimap(multimap&& __m)
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001750 _NOEXCEPT_(is_nothrow_move_constructible<__base>::value)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001751 : __tree_(_VSTD::move(__m.__tree_))
Howard Hinnantc51e1022010-05-11 19:42:16 +00001752 {
1753 }
1754
1755 multimap(multimap&& __m, const allocator_type& __a);
1756
Howard Hinnant756c69b2010-09-22 16:48:34 +00001757 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant33711792011-08-12 21:56:02 +00001758 multimap& operator=(multimap&& __m)
1759 _NOEXCEPT_(is_nothrow_move_assignable<__base>::value)
1760 {
1761 __tree_ = _VSTD::move(__m.__tree_);
1762 return *this;
1763 }
1764
Howard Hinnant33711792011-08-12 21:56:02 +00001765 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001766 multimap(initializer_list<value_type> __il, const key_compare& __comp = key_compare())
1767 : __tree_(__vc(__comp))
1768 {
1769 insert(__il.begin(), __il.end());
1770 }
1771
Howard Hinnant756c69b2010-09-22 16:48:34 +00001772 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001773 multimap(initializer_list<value_type> __il, const key_compare& __comp, const allocator_type& __a)
Marshall Clow657cbc42016-08-17 05:58:40 +00001774 : __tree_(__vc(__comp), typename __base::allocator_type(__a))
Howard Hinnantc51e1022010-05-11 19:42:16 +00001775 {
1776 insert(__il.begin(), __il.end());
1777 }
1778
Marshall Clow300abfb2013-09-11 01:15:47 +00001779#if _LIBCPP_STD_VER > 11
Eric Fiseliercf8c0212017-01-05 06:06:18 +00001780 _LIBCPP_INLINE_VISIBILITY
Marshall Clow300abfb2013-09-11 01:15:47 +00001781 multimap(initializer_list<value_type> __il, const allocator_type& __a)
1782 : multimap(__il, key_compare(), __a) {}
1783#endif
1784
Howard Hinnant756c69b2010-09-22 16:48:34 +00001785 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001786 multimap& operator=(initializer_list<value_type> __il)
1787 {
1788 __tree_.__assign_multi(__il.begin(), __il.end());
1789 return *this;
1790 }
Howard Hinnant33711792011-08-12 21:56:02 +00001791
Eric Fiseliera85b1282017-04-18 21:08:06 +00001792#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001793
Howard Hinnant756c69b2010-09-22 16:48:34 +00001794 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001795 explicit multimap(const allocator_type& __a)
Marshall Clow657cbc42016-08-17 05:58:40 +00001796 : __tree_(typename __base::allocator_type(__a))
Howard Hinnantc51e1022010-05-11 19:42:16 +00001797 {
1798 }
1799
Howard Hinnant756c69b2010-09-22 16:48:34 +00001800 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001801 multimap(const multimap& __m, const allocator_type& __a)
Marshall Clow657cbc42016-08-17 05:58:40 +00001802 : __tree_(__m.__tree_.value_comp(), typename __base::allocator_type(__a))
Howard Hinnantc51e1022010-05-11 19:42:16 +00001803 {
1804 insert(__m.begin(), __m.end());
1805 }
1806
Howard Hinnant756c69b2010-09-22 16:48:34 +00001807 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001808 iterator begin() _NOEXCEPT {return __tree_.begin();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001809 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001810 const_iterator begin() const _NOEXCEPT {return __tree_.begin();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001811 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001812 iterator end() _NOEXCEPT {return __tree_.end();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001813 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001814 const_iterator end() const _NOEXCEPT {return __tree_.end();}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001815
Howard Hinnant756c69b2010-09-22 16:48:34 +00001816 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001817 reverse_iterator rbegin() _NOEXCEPT {return reverse_iterator(end());}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001818 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001819 const_reverse_iterator rbegin() const _NOEXCEPT
1820 {return const_reverse_iterator(end());}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001821 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001822 reverse_iterator rend() _NOEXCEPT {return reverse_iterator(begin());}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001823 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001824 const_reverse_iterator rend() const _NOEXCEPT
1825 {return const_reverse_iterator(begin());}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001826
Howard Hinnant756c69b2010-09-22 16:48:34 +00001827 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001828 const_iterator cbegin() const _NOEXCEPT {return begin();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001829 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001830 const_iterator cend() const _NOEXCEPT {return end();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001831 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001832 const_reverse_iterator crbegin() const _NOEXCEPT {return rbegin();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001833 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001834 const_reverse_iterator crend() const _NOEXCEPT {return rend();}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001835
Marshall Clow425f5752017-11-15 05:51:26 +00001836 _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001837 bool empty() const _NOEXCEPT {return __tree_.size() == 0;}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001838 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001839 size_type size() const _NOEXCEPT {return __tree_.size();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001840 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001841 size_type max_size() const _NOEXCEPT {return __tree_.max_size();}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001842
Howard Hinnant756c69b2010-09-22 16:48:34 +00001843 _LIBCPP_INLINE_VISIBILITY
Marshall Clow657cbc42016-08-17 05:58:40 +00001844 allocator_type get_allocator() const _NOEXCEPT {return allocator_type(__tree_.__alloc());}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001845 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001846 key_compare key_comp() const {return __tree_.value_comp().key_comp();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001847 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001848 value_compare value_comp() const
1849 {return value_compare(__tree_.value_comp().key_comp());}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001850
Eric Fiselierd06276b2016-03-31 02:15:15 +00001851#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant74279a52010-09-04 23:28:19 +00001852
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001853 template <class ..._Args>
Eric Fiselierd06276b2016-03-31 02:15:15 +00001854 _LIBCPP_INLINE_VISIBILITY
1855 iterator emplace(_Args&& ...__args) {
1856 return __tree_.__emplace_multi(_VSTD::forward<_Args>(__args)...);
1857 }
Howard Hinnantc51e1022010-05-11 19:42:16 +00001858
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001859 template <class ..._Args>
Eric Fiselierd06276b2016-03-31 02:15:15 +00001860 _LIBCPP_INLINE_VISIBILITY
1861 iterator emplace_hint(const_iterator __p, _Args&& ...__args) {
1862 return __tree_.__emplace_hint_multi(__p.__i_, _VSTD::forward<_Args>(__args)...);
1863 }
Howard Hinnant74279a52010-09-04 23:28:19 +00001864
Howard Hinnantc834c512011-11-29 18:15:50 +00001865 template <class _Pp,
1866 class = typename enable_if<is_constructible<value_type, _Pp>::value>::type>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001867 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc834c512011-11-29 18:15:50 +00001868 iterator insert(_Pp&& __p)
1869 {return __tree_.__insert_multi(_VSTD::forward<_Pp>(__p));}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001870
Howard Hinnantc834c512011-11-29 18:15:50 +00001871 template <class _Pp,
1872 class = typename enable_if<is_constructible<value_type, _Pp>::value>::type>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001873 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc834c512011-11-29 18:15:50 +00001874 iterator insert(const_iterator __pos, _Pp&& __p)
1875 {return __tree_.__insert_multi(__pos.__i_, _VSTD::forward<_Pp>(__p));}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001876
Eric Fiselierd6143132016-04-18 01:40:45 +00001877 _LIBCPP_INLINE_VISIBILITY
1878 iterator insert(value_type&& __v)
1879 {return __tree_.__insert_multi(_VSTD::move(__v));}
1880
1881 _LIBCPP_INLINE_VISIBILITY
1882 iterator insert(const_iterator __p, value_type&& __v)
1883 {return __tree_.__insert_multi(__p.__i_, _VSTD::move(__v));}
1884
Eric Fiseliera85b1282017-04-18 21:08:06 +00001885
1886 _LIBCPP_INLINE_VISIBILITY
1887 void insert(initializer_list<value_type> __il)
1888 {insert(__il.begin(), __il.end());}
1889
Eric Fiselierd06276b2016-03-31 02:15:15 +00001890#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001891
Howard Hinnant756c69b2010-09-22 16:48:34 +00001892 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001893 iterator insert(const value_type& __v) {return __tree_.__insert_multi(__v);}
1894
Howard Hinnant756c69b2010-09-22 16:48:34 +00001895 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001896 iterator insert(const_iterator __p, const value_type& __v)
1897 {return __tree_.__insert_multi(__p.__i_, __v);}
1898
1899 template <class _InputIterator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001900 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001901 void insert(_InputIterator __f, _InputIterator __l)
1902 {
1903 for (const_iterator __e = cend(); __f != __l; ++__f)
1904 __tree_.__insert_multi(__e.__i_, *__f);
1905 }
1906
Howard Hinnant756c69b2010-09-22 16:48:34 +00001907 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001908 iterator erase(const_iterator __p) {return __tree_.erase(__p.__i_);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001909 _LIBCPP_INLINE_VISIBILITY
Marshall Clow22ea5b82015-05-10 13:35:00 +00001910 iterator erase(iterator __p) {return __tree_.erase(__p.__i_);}
1911 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001912 size_type erase(const key_type& __k) {return __tree_.__erase_multi(__k);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001913 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001914 iterator erase(const_iterator __f, const_iterator __l)
1915 {return __tree_.erase(__f.__i_, __l.__i_);}
Erik Pilkingtonc37a3d82018-08-01 01:33:38 +00001916
1917#if _LIBCPP_STD_VER > 14
1918 _LIBCPP_INLINE_VISIBILITY
1919 iterator insert(node_type&& __nh)
1920 {
1921 _LIBCPP_ASSERT(__nh.empty() || __nh.get_allocator() == get_allocator(),
1922 "node_type with incompatible allocator passed to multimap::insert()");
1923 return __tree_.template __node_handle_insert_multi<node_type>(
1924 _VSTD::move(__nh));
1925 }
1926 _LIBCPP_INLINE_VISIBILITY
1927 iterator insert(const_iterator __hint, node_type&& __nh)
1928 {
1929 _LIBCPP_ASSERT(__nh.empty() || __nh.get_allocator() == get_allocator(),
1930 "node_type with incompatible allocator passed to multimap::insert()");
1931 return __tree_.template __node_handle_insert_multi<node_type>(
1932 __hint.__i_, _VSTD::move(__nh));
1933 }
1934 _LIBCPP_INLINE_VISIBILITY
1935 node_type extract(key_type const& __key)
1936 {
1937 return __tree_.template __node_handle_extract<node_type>(__key);
1938 }
1939 _LIBCPP_INLINE_VISIBILITY
1940 node_type extract(const_iterator __it)
1941 {
1942 return __tree_.template __node_handle_extract<node_type>(
1943 __it.__i_);
1944 }
Erik Pilkington82a65ad2018-10-31 17:31:35 +00001945 template <class _C2>
1946 _LIBCPP_INLINE_VISIBILITY
1947 void merge(multimap<key_type, mapped_type, _C2, allocator_type>& __source)
1948 {
1949 _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
1950 "merging container with incompatible allocator");
1951 return __tree_.__node_handle_merge_multi(__source.__tree_);
1952 }
1953 template <class _C2>
1954 _LIBCPP_INLINE_VISIBILITY
1955 void merge(multimap<key_type, mapped_type, _C2, allocator_type>&& __source)
1956 {
1957 _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
1958 "merging container with incompatible allocator");
1959 return __tree_.__node_handle_merge_multi(__source.__tree_);
1960 }
1961 template <class _C2>
1962 _LIBCPP_INLINE_VISIBILITY
1963 void merge(map<key_type, mapped_type, _C2, allocator_type>& __source)
1964 {
1965 _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
1966 "merging container with incompatible allocator");
1967 return __tree_.__node_handle_merge_multi(__source.__tree_);
1968 }
1969 template <class _C2>
1970 _LIBCPP_INLINE_VISIBILITY
1971 void merge(map<key_type, mapped_type, _C2, allocator_type>&& __source)
1972 {
1973 _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
1974 "merging container with incompatible allocator");
1975 return __tree_.__node_handle_merge_multi(__source.__tree_);
1976 }
Erik Pilkingtonc37a3d82018-08-01 01:33:38 +00001977#endif
1978
Howard Hinnant756c69b2010-09-22 16:48:34 +00001979 _LIBCPP_INLINE_VISIBILITY
Marshall Clowde1312a2018-08-22 04:28:43 +00001980 void clear() _NOEXCEPT {__tree_.clear();}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001981
Howard Hinnant756c69b2010-09-22 16:48:34 +00001982 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001983 void swap(multimap& __m)
1984 _NOEXCEPT_(__is_nothrow_swappable<__base>::value)
1985 {__tree_.swap(__m.__tree_);}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001986
Howard Hinnant756c69b2010-09-22 16:48:34 +00001987 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001988 iterator find(const key_type& __k) {return __tree_.find(__k);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001989 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001990 const_iterator find(const key_type& __k) const {return __tree_.find(__k);}
Marshall Clowebb57322013-08-13 22:18:47 +00001991#if _LIBCPP_STD_VER > 11
1992 template <typename _K2>
1993 _LIBCPP_INLINE_VISIBILITY
1994 typename enable_if<__is_transparent<_Compare, _K2>::value,iterator>::type
1995 find(const _K2& __k) {return __tree_.find(__k);}
1996 template <typename _K2>
1997 _LIBCPP_INLINE_VISIBILITY
1998 typename enable_if<__is_transparent<_Compare, _K2>::value,const_iterator>::type
1999 find(const _K2& __k) const {return __tree_.find(__k);}
2000#endif
2001
Howard Hinnant756c69b2010-09-22 16:48:34 +00002002 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002003 size_type count(const key_type& __k) const
2004 {return __tree_.__count_multi(__k);}
Marshall Clowe6a5f522014-08-24 23:54:16 +00002005#if _LIBCPP_STD_VER > 11
2006 template <typename _K2>
2007 _LIBCPP_INLINE_VISIBILITY
2008 typename enable_if<__is_transparent<_Compare, _K2>::value,size_type>::type
Marshall Clow141e47b2015-06-30 18:15:41 +00002009 count(const _K2& __k) const {return __tree_.__count_multi(__k);}
Marshall Clowe6a5f522014-08-24 23:54:16 +00002010#endif
Howard Hinnant756c69b2010-09-22 16:48:34 +00002011 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002012 iterator lower_bound(const key_type& __k)
2013 {return __tree_.lower_bound(__k);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00002014 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002015 const_iterator lower_bound(const key_type& __k) const
2016 {return __tree_.lower_bound(__k);}
Marshall Clowebb57322013-08-13 22:18:47 +00002017#if _LIBCPP_STD_VER > 11
2018 template <typename _K2>
2019 _LIBCPP_INLINE_VISIBILITY
2020 typename enable_if<__is_transparent<_Compare, _K2>::value,iterator>::type
2021 lower_bound(const _K2& __k) {return __tree_.lower_bound(__k);}
2022
2023 template <typename _K2>
2024 _LIBCPP_INLINE_VISIBILITY
2025 typename enable_if<__is_transparent<_Compare, _K2>::value,const_iterator>::type
2026 lower_bound(const _K2& __k) const {return __tree_.lower_bound(__k);}
2027#endif
2028
Howard Hinnant756c69b2010-09-22 16:48:34 +00002029 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002030 iterator upper_bound(const key_type& __k)
2031 {return __tree_.upper_bound(__k);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00002032 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002033 const_iterator upper_bound(const key_type& __k) const
2034 {return __tree_.upper_bound(__k);}
Marshall Clowebb57322013-08-13 22:18:47 +00002035#if _LIBCPP_STD_VER > 11
2036 template <typename _K2>
2037 _LIBCPP_INLINE_VISIBILITY
2038 typename enable_if<__is_transparent<_Compare, _K2>::value,iterator>::type
2039 upper_bound(const _K2& __k) {return __tree_.upper_bound(__k);}
2040 template <typename _K2>
2041 _LIBCPP_INLINE_VISIBILITY
2042 typename enable_if<__is_transparent<_Compare, _K2>::value,const_iterator>::type
2043 upper_bound(const _K2& __k) const {return __tree_.upper_bound(__k);}
2044#endif
2045
Howard Hinnant756c69b2010-09-22 16:48:34 +00002046 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002047 pair<iterator,iterator> equal_range(const key_type& __k)
2048 {return __tree_.__equal_range_multi(__k);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00002049 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002050 pair<const_iterator,const_iterator> equal_range(const key_type& __k) const
2051 {return __tree_.__equal_range_multi(__k);}
Marshall Clowebb57322013-08-13 22:18:47 +00002052#if _LIBCPP_STD_VER > 11
2053 template <typename _K2>
2054 _LIBCPP_INLINE_VISIBILITY
2055 typename enable_if<__is_transparent<_Compare, _K2>::value,pair<iterator,iterator>>::type
2056 equal_range(const _K2& __k) {return __tree_.__equal_range_multi(__k);}
2057 template <typename _K2>
2058 _LIBCPP_INLINE_VISIBILITY
2059 typename enable_if<__is_transparent<_Compare, _K2>::value,pair<const_iterator,const_iterator>>::type
2060 equal_range(const _K2& __k) const {return __tree_.__equal_range_multi(__k);}
2061#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00002062
2063private:
2064 typedef typename __base::__node __node;
2065 typedef typename __base::__node_allocator __node_allocator;
2066 typedef typename __base::__node_pointer __node_pointer;
Eric Fiseliera92b0732016-02-20 07:12:17 +00002067
Howard Hinnantc834c512011-11-29 18:15:50 +00002068 typedef __map_node_destructor<__node_allocator> _Dp;
2069 typedef unique_ptr<__node, _Dp> __node_holder;
Howard Hinnantc51e1022010-05-11 19:42:16 +00002070};
2071
Eric Fiselierd06276b2016-03-31 02:15:15 +00002072#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00002073template <class _Key, class _Tp, class _Compare, class _Allocator>
2074multimap<_Key, _Tp, _Compare, _Allocator>::multimap(multimap&& __m, const allocator_type& __a)
Marshall Clow657cbc42016-08-17 05:58:40 +00002075 : __tree_(_VSTD::move(__m.__tree_), typename __base::allocator_type(__a))
Howard Hinnantc51e1022010-05-11 19:42:16 +00002076{
2077 if (__a != __m.get_allocator())
2078 {
2079 const_iterator __e = cend();
2080 while (!__m.empty())
2081 __tree_.__insert_multi(__e.__i_,
Erik Pilkingtond3fe2992018-06-04 20:38:23 +00002082 _VSTD::move(__m.__tree_.remove(__m.begin().__i_)->__value_.__move()));
Howard Hinnantc51e1022010-05-11 19:42:16 +00002083 }
2084}
Eric Fiselierd06276b2016-03-31 02:15:15 +00002085#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00002086
2087template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00002088inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002089bool
2090operator==(const multimap<_Key, _Tp, _Compare, _Allocator>& __x,
2091 const multimap<_Key, _Tp, _Compare, _Allocator>& __y)
2092{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00002093 return __x.size() == __y.size() && _VSTD::equal(__x.begin(), __x.end(), __y.begin());
Howard Hinnantc51e1022010-05-11 19:42:16 +00002094}
2095
2096template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00002097inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002098bool
2099operator< (const multimap<_Key, _Tp, _Compare, _Allocator>& __x,
2100 const multimap<_Key, _Tp, _Compare, _Allocator>& __y)
2101{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00002102 return _VSTD::lexicographical_compare(__x.begin(), __x.end(), __y.begin(), __y.end());
Howard Hinnantc51e1022010-05-11 19:42:16 +00002103}
2104
2105template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00002106inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002107bool
2108operator!=(const multimap<_Key, _Tp, _Compare, _Allocator>& __x,
2109 const multimap<_Key, _Tp, _Compare, _Allocator>& __y)
2110{
2111 return !(__x == __y);
2112}
2113
2114template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00002115inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002116bool
2117operator> (const multimap<_Key, _Tp, _Compare, _Allocator>& __x,
2118 const multimap<_Key, _Tp, _Compare, _Allocator>& __y)
2119{
2120 return __y < __x;
2121}
2122
2123template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00002124inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002125bool
2126operator>=(const multimap<_Key, _Tp, _Compare, _Allocator>& __x,
2127 const multimap<_Key, _Tp, _Compare, _Allocator>& __y)
2128{
2129 return !(__x < __y);
2130}
2131
2132template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00002133inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002134bool
2135operator<=(const multimap<_Key, _Tp, _Compare, _Allocator>& __x,
2136 const multimap<_Key, _Tp, _Compare, _Allocator>& __y)
2137{
2138 return !(__y < __x);
2139}
2140
2141template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00002142inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002143void
2144swap(multimap<_Key, _Tp, _Compare, _Allocator>& __x,
2145 multimap<_Key, _Tp, _Compare, _Allocator>& __y)
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00002146 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
Howard Hinnantc51e1022010-05-11 19:42:16 +00002147{
2148 __x.swap(__y);
2149}
2150
2151_LIBCPP_END_NAMESPACE_STD
2152
2153#endif // _LIBCPP_MAP