blob: 0f689b7e4c454e51b21be3b8ddc3c21647a5df93 [file] [log] [blame]
Howard Hinnantc51e1022010-05-11 19:42:16 +00001// -*- C++ -*-
2//===----------------------------- map ------------------------------------===//
3//
Howard Hinnantc566dc32010-05-11 21:36:01 +00004// The LLVM Compiler Infrastructure
Howard Hinnantc51e1022010-05-11 19:42:16 +00005//
Howard Hinnantee11c312010-11-16 22:09:02 +00006// This file is dual licensed under the MIT and the University of Illinois Open
7// Source Licenses. See LICENSE.TXT for details.
Howard Hinnantc51e1022010-05-11 19:42:16 +00008//
9//===----------------------------------------------------------------------===//
10
11#ifndef _LIBCPP_MAP
12#define _LIBCPP_MAP
13
14/*
15
16 map synopsis
17
18namespace std
19{
20
21template <class Key, class T, class Compare = less<Key>,
22 class Allocator = allocator<pair<const Key, T>>>
23class map
24{
25public:
26 // types:
27 typedef Key key_type;
28 typedef T mapped_type;
29 typedef pair<const key_type, mapped_type> value_type;
30 typedef Compare key_compare;
31 typedef Allocator allocator_type;
32 typedef typename allocator_type::reference reference;
33 typedef typename allocator_type::const_reference const_reference;
34 typedef typename allocator_type::pointer pointer;
35 typedef typename allocator_type::const_pointer const_pointer;
36 typedef typename allocator_type::size_type size_type;
37 typedef typename allocator_type::difference_type difference_type;
38
39 typedef implementation-defined iterator;
40 typedef implementation-defined const_iterator;
41 typedef std::reverse_iterator<iterator> reverse_iterator;
42 typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
43
44 class value_compare
45 : public binary_function<value_type, value_type, bool>
46 {
47 friend class map;
48 protected:
49 key_compare comp;
50
51 value_compare(key_compare c);
52 public:
53 bool operator()(const value_type& x, const value_type& y) const;
54 };
55
56 // construct/copy/destroy:
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +000057 map()
58 noexcept(
59 is_nothrow_default_constructible<allocator_type>::value &&
60 is_nothrow_default_constructible<key_compare>::value &&
61 is_nothrow_copy_constructible<key_compare>::value);
Howard Hinnantc51e1022010-05-11 19:42:16 +000062 explicit map(const key_compare& comp);
63 map(const key_compare& comp, const allocator_type& a);
64 template <class InputIterator>
65 map(InputIterator first, InputIterator last,
66 const key_compare& comp = key_compare());
67 template <class InputIterator>
68 map(InputIterator first, InputIterator last,
69 const key_compare& comp, const allocator_type& a);
70 map(const map& m);
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +000071 map(map&& m)
72 noexcept(
73 is_nothrow_move_constructible<allocator_type>::value &&
74 is_nothrow_move_constructible<key_compare>::value);
Howard Hinnantc51e1022010-05-11 19:42:16 +000075 explicit map(const allocator_type& a);
76 map(const map& m, const allocator_type& a);
77 map(map&& m, const allocator_type& a);
78 map(initializer_list<value_type> il, const key_compare& comp = key_compare());
79 map(initializer_list<value_type> il, const key_compare& comp, const allocator_type& a);
Marshall Clow300abfb2013-09-11 01:15:47 +000080 template <class InputIterator>
81 map(InputIterator first, InputIterator last, const allocator_type& a)
82 : map(first, last, Compare(), a) {} // C++14
83 map(initializer_list<value_type> il, const allocator_type& a)
84 : map(il, Compare(), a) {} // C++14
85 ~map();
Howard Hinnantc51e1022010-05-11 19:42:16 +000086
87 map& operator=(const map& m);
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +000088 map& operator=(map&& m)
89 noexcept(
90 allocator_type::propagate_on_container_move_assignment::value &&
91 is_nothrow_move_assignable<allocator_type>::value &&
Howard Hinnantf95f4f52011-06-04 15:22:34 +000092 is_nothrow_move_assignable<key_compare>::value);
Howard Hinnantc51e1022010-05-11 19:42:16 +000093 map& operator=(initializer_list<value_type> il);
94
95 // iterators:
Howard Hinnantf95f4f52011-06-04 15:22:34 +000096 iterator begin() noexcept;
97 const_iterator begin() const noexcept;
98 iterator end() noexcept;
99 const_iterator end() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000100
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000101 reverse_iterator rbegin() noexcept;
102 const_reverse_iterator rbegin() const noexcept;
103 reverse_iterator rend() noexcept;
104 const_reverse_iterator rend() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000105
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000106 const_iterator cbegin() const noexcept;
107 const_iterator cend() const noexcept;
108 const_reverse_iterator crbegin() const noexcept;
109 const_reverse_iterator crend() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000110
111 // capacity:
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000112 bool empty() const noexcept;
113 size_type size() const noexcept;
114 size_type max_size() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000115
116 // element access:
117 mapped_type& operator[](const key_type& k);
118 mapped_type& operator[](key_type&& k);
119
120 mapped_type& at(const key_type& k);
121 const mapped_type& at(const key_type& k) const;
122
123 // modifiers:
124 template <class... Args>
125 pair<iterator, bool> emplace(Args&&... args);
126 template <class... Args>
127 iterator emplace_hint(const_iterator position, Args&&... args);
128 pair<iterator, bool> insert(const value_type& v);
129 template <class P>
130 pair<iterator, bool> insert(P&& p);
131 iterator insert(const_iterator position, const value_type& v);
132 template <class P>
133 iterator insert(const_iterator position, P&& p);
134 template <class InputIterator>
135 void insert(InputIterator first, InputIterator last);
136 void insert(initializer_list<value_type> il);
137
Marshall Clow3223db82015-07-07 03:37:33 +0000138 template <class... Args>
139 pair<iterator, bool> try_emplace(const key_type& k, Args&&... args); // C++17
140 template <class... Args>
141 pair<iterator, bool> try_emplace(key_type&& k, Args&&... args); // C++17
142 template <class... Args>
143 iterator try_emplace(const_iterator hint, const key_type& k, Args&&... args); // C++17
144 template <class... Args>
145 iterator try_emplace(const_iterator hint, key_type&& k, Args&&... args); // C++17
146 template <class M>
147 pair<iterator, bool> insert_or_assign(const key_type& k, M&& obj); // C++17
148 template <class M>
149 pair<iterator, bool> insert_or_assign(key_type&& k, M&& obj); // C++17
150 template <class M>
151 iterator insert_or_assign(const_iterator hint, const key_type& k, M&& obj); // C++17
152 template <class M>
153 iterator insert_or_assign(const_iterator hint, key_type&& k, M&& obj); // C++17
154
Howard Hinnantc51e1022010-05-11 19:42:16 +0000155 iterator erase(const_iterator position);
Marshall Clow22ea5b82015-05-10 13:35:00 +0000156 iterator erase(iterator position); // C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000157 size_type erase(const key_type& k);
158 iterator erase(const_iterator first, const_iterator last);
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000159 void clear() noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000160
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000161 void swap(map& m)
162 noexcept(
163 __is_nothrow_swappable<key_compare>::value &&
164 (!allocator_type::propagate_on_container_swap::value ||
165 __is_nothrow_swappable<allocator_type>::value));
Howard Hinnantc51e1022010-05-11 19:42:16 +0000166
167 // observers:
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000168 allocator_type get_allocator() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000169 key_compare key_comp() const;
170 value_compare value_comp() const;
171
172 // map operations:
173 iterator find(const key_type& k);
174 const_iterator find(const key_type& k) const;
Marshall Clowebb57322013-08-13 22:18:47 +0000175 template<typename K>
176 iterator find(const K& x); // C++14
177 template<typename K>
178 const_iterator find(const K& x) const; // C++14
179 template<typename K>
Marshall Clowe6a5f522014-08-24 23:54:16 +0000180 size_type count(const K& x) const; // C++14
Marshall Clowebb57322013-08-13 22:18:47 +0000181
Howard Hinnantc51e1022010-05-11 19:42:16 +0000182 size_type count(const key_type& k) const;
183 iterator lower_bound(const key_type& k);
184 const_iterator lower_bound(const key_type& k) const;
Marshall Clowebb57322013-08-13 22:18:47 +0000185 template<typename K>
186 iterator lower_bound(const K& x); // C++14
187 template<typename K>
188 const_iterator lower_bound(const K& x) const; // C++14
189
Howard Hinnantc51e1022010-05-11 19:42:16 +0000190 iterator upper_bound(const key_type& k);
191 const_iterator upper_bound(const key_type& k) const;
Marshall Clowebb57322013-08-13 22:18:47 +0000192 template<typename K>
193 iterator upper_bound(const K& x); // C++14
194 template<typename K>
195 const_iterator upper_bound(const K& x) const; // C++14
196
Howard Hinnantc51e1022010-05-11 19:42:16 +0000197 pair<iterator,iterator> equal_range(const key_type& k);
198 pair<const_iterator,const_iterator> equal_range(const key_type& k) const;
Marshall Clowebb57322013-08-13 22:18:47 +0000199 template<typename K>
200 pair<iterator,iterator> equal_range(const K& x); // C++14
201 template<typename K>
202 pair<const_iterator,const_iterator> equal_range(const K& x) const; // C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000203};
204
205template <class Key, class T, class Compare, class Allocator>
206bool
207operator==(const map<Key, T, Compare, Allocator>& x,
208 const map<Key, T, Compare, Allocator>& y);
209
210template <class Key, class T, class Compare, class Allocator>
211bool
212operator< (const map<Key, T, Compare, Allocator>& x,
213 const map<Key, T, Compare, Allocator>& y);
214
215template <class Key, class T, class Compare, class Allocator>
216bool
217operator!=(const map<Key, T, Compare, Allocator>& x,
218 const map<Key, T, Compare, Allocator>& y);
219
220template <class Key, class T, class Compare, class Allocator>
221bool
222operator> (const map<Key, T, Compare, Allocator>& x,
223 const map<Key, T, Compare, Allocator>& y);
224
225template <class Key, class T, class Compare, class Allocator>
226bool
227operator>=(const map<Key, T, Compare, Allocator>& x,
228 const map<Key, T, Compare, Allocator>& y);
229
230template <class Key, class T, class Compare, class Allocator>
231bool
232operator<=(const map<Key, T, Compare, Allocator>& x,
233 const map<Key, T, Compare, Allocator>& y);
234
235// specialized algorithms:
236template <class Key, class T, class Compare, class Allocator>
237void
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000238swap(map<Key, T, Compare, Allocator>& x, map<Key, T, Compare, Allocator>& y)
239 noexcept(noexcept(x.swap(y)));
Howard Hinnantc51e1022010-05-11 19:42:16 +0000240
241template <class Key, class T, class Compare = less<Key>,
242 class Allocator = allocator<pair<const Key, T>>>
243class multimap
244{
245public:
246 // types:
247 typedef Key key_type;
248 typedef T mapped_type;
249 typedef pair<const key_type,mapped_type> value_type;
250 typedef Compare key_compare;
251 typedef Allocator allocator_type;
252 typedef typename allocator_type::reference reference;
253 typedef typename allocator_type::const_reference const_reference;
254 typedef typename allocator_type::size_type size_type;
255 typedef typename allocator_type::difference_type difference_type;
256 typedef typename allocator_type::pointer pointer;
257 typedef typename allocator_type::const_pointer const_pointer;
258
259 typedef implementation-defined iterator;
260 typedef implementation-defined const_iterator;
261 typedef std::reverse_iterator<iterator> reverse_iterator;
262 typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
263
264 class value_compare
265 : public binary_function<value_type,value_type,bool>
266 {
267 friend class multimap;
268 protected:
269 key_compare comp;
270 value_compare(key_compare c);
271 public:
272 bool operator()(const value_type& x, const value_type& y) const;
273 };
274
275 // construct/copy/destroy:
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000276 multimap()
277 noexcept(
278 is_nothrow_default_constructible<allocator_type>::value &&
279 is_nothrow_default_constructible<key_compare>::value &&
280 is_nothrow_copy_constructible<key_compare>::value);
281 explicit multimap(const key_compare& comp);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000282 multimap(const key_compare& comp, const allocator_type& a);
283 template <class InputIterator>
284 multimap(InputIterator first, InputIterator last, const key_compare& comp);
285 template <class InputIterator>
286 multimap(InputIterator first, InputIterator last, const key_compare& comp,
287 const allocator_type& a);
288 multimap(const multimap& m);
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000289 multimap(multimap&& m)
290 noexcept(
291 is_nothrow_move_constructible<allocator_type>::value &&
292 is_nothrow_move_constructible<key_compare>::value);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000293 explicit multimap(const allocator_type& a);
294 multimap(const multimap& m, const allocator_type& a);
295 multimap(multimap&& m, const allocator_type& a);
296 multimap(initializer_list<value_type> il, const key_compare& comp = key_compare());
297 multimap(initializer_list<value_type> il, const key_compare& comp,
298 const allocator_type& a);
Marshall Clow300abfb2013-09-11 01:15:47 +0000299 template <class InputIterator>
300 multimap(InputIterator first, InputIterator last, const allocator_type& a)
301 : multimap(first, last, Compare(), a) {} // C++14
302 multimap(initializer_list<value_type> il, const allocator_type& a)
303 : multimap(il, Compare(), a) {} // C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000304 ~multimap();
305
306 multimap& operator=(const multimap& m);
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000307 multimap& operator=(multimap&& m)
308 noexcept(
309 allocator_type::propagate_on_container_move_assignment::value &&
310 is_nothrow_move_assignable<allocator_type>::value &&
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000311 is_nothrow_move_assignable<key_compare>::value);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000312 multimap& operator=(initializer_list<value_type> il);
313
314 // iterators:
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000315 iterator begin() noexcept;
316 const_iterator begin() const noexcept;
317 iterator end() noexcept;
318 const_iterator end() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000319
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000320 reverse_iterator rbegin() noexcept;
321 const_reverse_iterator rbegin() const noexcept;
322 reverse_iterator rend() noexcept;
323 const_reverse_iterator rend() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000324
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000325 const_iterator cbegin() const noexcept;
326 const_iterator cend() const noexcept;
327 const_reverse_iterator crbegin() const noexcept;
328 const_reverse_iterator crend() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000329
330 // capacity:
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000331 bool empty() const noexcept;
332 size_type size() const noexcept;
333 size_type max_size() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000334
335 // modifiers:
336 template <class... Args>
337 iterator emplace(Args&&... args);
338 template <class... Args>
339 iterator emplace_hint(const_iterator position, Args&&... args);
340 iterator insert(const value_type& v);
341 template <class P>
342 iterator insert(P&& p);
343 iterator insert(const_iterator position, const value_type& v);
344 template <class P>
345 iterator insert(const_iterator position, P&& p);
346 template <class InputIterator>
347 void insert(InputIterator first, InputIterator last);
348 void insert(initializer_list<value_type> il);
349
350 iterator erase(const_iterator position);
Marshall Clow22ea5b82015-05-10 13:35:00 +0000351 iterator erase(iterator position); // C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000352 size_type erase(const key_type& k);
353 iterator erase(const_iterator first, const_iterator last);
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000354 void clear() noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000355
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000356 void swap(multimap& m)
357 noexcept(
358 __is_nothrow_swappable<key_compare>::value &&
359 (!allocator_type::propagate_on_container_swap::value ||
360 __is_nothrow_swappable<allocator_type>::value));
Howard Hinnantc51e1022010-05-11 19:42:16 +0000361
362 // observers:
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000363 allocator_type get_allocator() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000364 key_compare key_comp() const;
365 value_compare value_comp() const;
366
367 // map operations:
368 iterator find(const key_type& k);
369 const_iterator find(const key_type& k) const;
Marshall Clowebb57322013-08-13 22:18:47 +0000370 template<typename K>
371 iterator find(const K& x); // C++14
372 template<typename K>
373 const_iterator find(const K& x) const; // C++14
374 template<typename K>
Marshall Clowe6a5f522014-08-24 23:54:16 +0000375 size_type count(const K& x) const; // C++14
Marshall Clowebb57322013-08-13 22:18:47 +0000376
Howard Hinnantc51e1022010-05-11 19:42:16 +0000377 size_type count(const key_type& k) const;
378 iterator lower_bound(const key_type& k);
379 const_iterator lower_bound(const key_type& k) const;
Marshall Clowebb57322013-08-13 22:18:47 +0000380 template<typename K>
381 iterator lower_bound(const K& x); // C++14
382 template<typename K>
383 const_iterator lower_bound(const K& x) const; // C++14
384
Howard Hinnantc51e1022010-05-11 19:42:16 +0000385 iterator upper_bound(const key_type& k);
386 const_iterator upper_bound(const key_type& k) const;
Marshall Clowebb57322013-08-13 22:18:47 +0000387 template<typename K>
388 iterator upper_bound(const K& x); // C++14
389 template<typename K>
390 const_iterator upper_bound(const K& x) const; // C++14
391
Howard Hinnantc51e1022010-05-11 19:42:16 +0000392 pair<iterator,iterator> equal_range(const key_type& k);
393 pair<const_iterator,const_iterator> equal_range(const key_type& k) const;
Marshall Clowebb57322013-08-13 22:18:47 +0000394 template<typename K>
395 pair<iterator,iterator> equal_range(const K& x); // C++14
396 template<typename K>
397 pair<const_iterator,const_iterator> equal_range(const K& x) const; // C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000398};
399
400template <class Key, class T, class Compare, class Allocator>
401bool
402operator==(const multimap<Key, T, Compare, Allocator>& x,
403 const multimap<Key, T, Compare, Allocator>& y);
404
405template <class Key, class T, class Compare, class Allocator>
406bool
407operator< (const multimap<Key, T, Compare, Allocator>& x,
408 const multimap<Key, T, Compare, Allocator>& y);
409
410template <class Key, class T, class Compare, class Allocator>
411bool
412operator!=(const multimap<Key, T, Compare, Allocator>& x,
413 const multimap<Key, T, Compare, Allocator>& y);
414
415template <class Key, class T, class Compare, class Allocator>
416bool
417operator> (const multimap<Key, T, Compare, Allocator>& x,
418 const multimap<Key, T, Compare, Allocator>& y);
419
420template <class Key, class T, class Compare, class Allocator>
421bool
422operator>=(const multimap<Key, T, Compare, Allocator>& x,
423 const multimap<Key, T, Compare, Allocator>& y);
424
425template <class Key, class T, class Compare, class Allocator>
426bool
427operator<=(const multimap<Key, T, Compare, Allocator>& x,
428 const multimap<Key, T, Compare, Allocator>& y);
429
430// specialized algorithms:
431template <class Key, class T, class Compare, class Allocator>
432void
433swap(multimap<Key, T, Compare, Allocator>& x,
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000434 multimap<Key, T, Compare, Allocator>& y)
435 noexcept(noexcept(x.swap(y)));
Howard Hinnantc51e1022010-05-11 19:42:16 +0000436
437} // std
438
439*/
440
441#include <__config>
442#include <__tree>
443#include <iterator>
444#include <memory>
445#include <utility>
446#include <functional>
447#include <initializer_list>
Eric Fiselierf7394302015-06-13 07:08:02 +0000448#include <type_traits>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000449
Howard Hinnantaaaa52b2011-10-17 20:05:10 +0000450#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000451#pragma GCC system_header
Howard Hinnantaaaa52b2011-10-17 20:05:10 +0000452#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000453
454_LIBCPP_BEGIN_NAMESPACE_STD
455
Eric Fiselierf7394302015-06-13 07:08:02 +0000456template <class _Key, class _CP, class _Compare,
457 bool = is_empty<_Compare>::value && !__libcpp_is_final<_Compare>::value
Howard Hinnantd0aabf82011-12-11 20:31:33 +0000458 >
Howard Hinnantc51e1022010-05-11 19:42:16 +0000459class __map_value_compare
460 : private _Compare
461{
Howard Hinnantc51e1022010-05-11 19:42:16 +0000462public:
Howard Hinnant756c69b2010-09-22 16:48:34 +0000463 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000464 __map_value_compare()
465 _NOEXCEPT_(is_nothrow_default_constructible<_Compare>::value)
466 : _Compare() {}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000467 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000468 __map_value_compare(_Compare c)
469 _NOEXCEPT_(is_nothrow_copy_constructible<_Compare>::value)
470 : _Compare(c) {}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000471 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000472 const _Compare& key_comp() const _NOEXCEPT {return *this;}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000473 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000474 bool operator()(const _CP& __x, const _CP& __y) const
Howard Hinnant90b91592013-07-05 18:06:00 +0000475 {return static_cast<const _Compare&>(*this)(__x.__cc.first, __y.__cc.first);}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000476 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000477 bool operator()(const _CP& __x, const _Key& __y) const
Howard Hinnant90b91592013-07-05 18:06:00 +0000478 {return static_cast<const _Compare&>(*this)(__x.__cc.first, __y);}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000479 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000480 bool operator()(const _Key& __x, const _CP& __y) const
Howard Hinnant90b91592013-07-05 18:06:00 +0000481 {return static_cast<const _Compare&>(*this)(__x, __y.__cc.first);}
Marshall Clowebb57322013-08-13 22:18:47 +0000482
483#if _LIBCPP_STD_VER > 11
484 template <typename _K2>
485 _LIBCPP_INLINE_VISIBILITY
486 typename enable_if<__is_transparent<_Compare, _K2>::value, bool>::type
487 operator () ( const _K2& __x, const _CP& __y ) const
488 {return static_cast<const _Compare&>(*this) (__x, __y.__cc.first);}
489
490 template <typename _K2>
491 _LIBCPP_INLINE_VISIBILITY
492 typename enable_if<__is_transparent<_Compare, _K2>::value, bool>::type
493 operator () (const _CP& __x, const _K2& __y) const
494 {return static_cast<const _Compare&>(*this) (__x.__cc.first, __y);}
495#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000496};
497
Howard Hinnant90b91592013-07-05 18:06:00 +0000498template <class _Key, class _CP, class _Compare>
499class __map_value_compare<_Key, _CP, _Compare, false>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000500{
501 _Compare comp;
502
Howard Hinnantc51e1022010-05-11 19:42:16 +0000503public:
Howard Hinnant756c69b2010-09-22 16:48:34 +0000504 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000505 __map_value_compare()
506 _NOEXCEPT_(is_nothrow_default_constructible<_Compare>::value)
507 : comp() {}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000508 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000509 __map_value_compare(_Compare c)
510 _NOEXCEPT_(is_nothrow_copy_constructible<_Compare>::value)
511 : comp(c) {}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000512 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000513 const _Compare& key_comp() const _NOEXCEPT {return comp;}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000514
Howard Hinnant756c69b2010-09-22 16:48:34 +0000515 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000516 bool operator()(const _CP& __x, const _CP& __y) const
Howard Hinnant90b91592013-07-05 18:06:00 +0000517 {return comp(__x.__cc.first, __y.__cc.first);}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000518 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000519 bool operator()(const _CP& __x, const _Key& __y) const
Howard Hinnant90b91592013-07-05 18:06:00 +0000520 {return comp(__x.__cc.first, __y);}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000521 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000522 bool operator()(const _Key& __x, const _CP& __y) const
Howard Hinnant90b91592013-07-05 18:06:00 +0000523 {return comp(__x, __y.__cc.first);}
Marshall Clowebb57322013-08-13 22:18:47 +0000524
525#if _LIBCPP_STD_VER > 11
526 template <typename _K2>
527 _LIBCPP_INLINE_VISIBILITY
528 typename enable_if<__is_transparent<_Compare, _K2>::value, bool>::type
529 operator () ( const _K2& __x, const _CP& __y ) const
530 {return comp (__x, __y.__cc.first);}
531
532 template <typename _K2>
533 _LIBCPP_INLINE_VISIBILITY
534 typename enable_if<__is_transparent<_Compare, _K2>::value, bool>::type
535 operator () (const _CP& __x, const _K2& __y) const
536 {return comp (__x.__cc.first, __y);}
537#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000538};
539
540template <class _Allocator>
541class __map_node_destructor
542{
543 typedef _Allocator allocator_type;
544 typedef allocator_traits<allocator_type> __alloc_traits;
545 typedef typename __alloc_traits::value_type::value_type value_type;
546public:
547 typedef typename __alloc_traits::pointer pointer;
548private:
Howard Hinnant2d0046b2013-06-19 21:29:40 +0000549 typedef typename value_type::value_type::first_type first_type;
550 typedef typename value_type::value_type::second_type second_type;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000551
552 allocator_type& __na_;
553
554 __map_node_destructor& operator=(const __map_node_destructor&);
555
556public:
557 bool __first_constructed;
558 bool __second_constructed;
559
Howard Hinnant756c69b2010-09-22 16:48:34 +0000560 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000561 explicit __map_node_destructor(allocator_type& __na) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +0000562 : __na_(__na),
563 __first_constructed(false),
564 __second_constructed(false)
565 {}
566
Howard Hinnant74279a52010-09-04 23:28:19 +0000567#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant756c69b2010-09-22 16:48:34 +0000568 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000569 __map_node_destructor(__tree_node_destructor<allocator_type>&& __x) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +0000570 : __na_(__x.__na_),
571 __first_constructed(__x.__value_constructed),
572 __second_constructed(__x.__value_constructed)
573 {
574 __x.__value_constructed = false;
575 }
Howard Hinnant5dc89112010-09-04 23:46:48 +0000576#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +0000577
Howard Hinnant756c69b2010-09-22 16:48:34 +0000578 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000579 void operator()(pointer __p) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +0000580 {
581 if (__second_constructed)
Howard Hinnant2d0046b2013-06-19 21:29:40 +0000582 __alloc_traits::destroy(__na_, _VSTD::addressof(__p->__value_.__cc.second));
Howard Hinnantc51e1022010-05-11 19:42:16 +0000583 if (__first_constructed)
Howard Hinnant2d0046b2013-06-19 21:29:40 +0000584 __alloc_traits::destroy(__na_, _VSTD::addressof(__p->__value_.__cc.first));
Howard Hinnantc51e1022010-05-11 19:42:16 +0000585 if (__p)
586 __alloc_traits::deallocate(__na_, __p, 1);
587 }
588};
589
Howard Hinnant944510a2011-06-14 19:58:17 +0000590template <class _Key, class _Tp, class _Compare, class _Allocator>
591 class map;
592template <class _Key, class _Tp, class _Compare, class _Allocator>
593 class multimap;
594template <class _TreeIterator> class __map_const_iterator;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000595
Howard Hinnant89f8b792013-09-30 19:08:22 +0000596#if __cplusplus >= 201103L
597
598template <class _Key, class _Tp>
599union __value_type
600{
601 typedef _Key key_type;
602 typedef _Tp mapped_type;
603 typedef pair<const key_type, mapped_type> value_type;
604 typedef pair<key_type, mapped_type> __nc_value_type;
605
606 value_type __cc;
607 __nc_value_type __nc;
608
609 template <class ..._Args>
610 _LIBCPP_INLINE_VISIBILITY
611 __value_type(_Args&& ...__args)
612 : __cc(std::forward<_Args>(__args)...) {}
613
614 _LIBCPP_INLINE_VISIBILITY
615 __value_type(const __value_type& __v)
616 : __cc(__v.__cc) {}
617
618 _LIBCPP_INLINE_VISIBILITY
619 __value_type(__value_type& __v)
620 : __cc(__v.__cc) {}
621
622 _LIBCPP_INLINE_VISIBILITY
623 __value_type(__value_type&& __v)
624 : __nc(std::move(__v.__nc)) {}
625
626 _LIBCPP_INLINE_VISIBILITY
627 __value_type& operator=(const __value_type& __v)
628 {__nc = __v.__cc; return *this;}
629
630 _LIBCPP_INLINE_VISIBILITY
631 __value_type& operator=(__value_type&& __v)
632 {__nc = std::move(__v.__nc); return *this;}
633
634 _LIBCPP_INLINE_VISIBILITY
635 ~__value_type() {__cc.~value_type();}
636};
637
638#else
639
640template <class _Key, class _Tp>
641struct __value_type
642{
643 typedef _Key key_type;
644 typedef _Tp mapped_type;
645 typedef pair<const key_type, mapped_type> value_type;
646
647 value_type __cc;
648
649 _LIBCPP_INLINE_VISIBILITY
650 __value_type() {}
651
652 template <class _A0>
653 _LIBCPP_INLINE_VISIBILITY
654 __value_type(const _A0& __a0)
655 : __cc(__a0) {}
656
657 template <class _A0, class _A1>
658 _LIBCPP_INLINE_VISIBILITY
659 __value_type(const _A0& __a0, const _A1& __a1)
660 : __cc(__a0, __a1) {}
661};
662
663#endif
664
Eric Fiselier44f9fd02015-03-03 20:10:01 +0000665template <class _Tp>
666struct __extract_key_value_types;
667
668template <class _Key, class _Tp>
669struct __extract_key_value_types<__value_type<_Key, _Tp> >
670{
671 typedef _Key const __key_type;
672 typedef _Tp __mapped_type;
673};
674
Howard Hinnantc51e1022010-05-11 19:42:16 +0000675template <class _TreeIterator>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +0000676class _LIBCPP_TYPE_VIS_ONLY __map_iterator
Howard Hinnantc51e1022010-05-11 19:42:16 +0000677{
678 _TreeIterator __i_;
679
680 typedef typename _TreeIterator::__pointer_traits __pointer_traits;
Eric Fiselier44f9fd02015-03-03 20:10:01 +0000681 typedef typename _TreeIterator::value_type __value_type;
682 typedef typename __extract_key_value_types<__value_type>::__key_type __key_type;
683 typedef typename __extract_key_value_types<__value_type>::__mapped_type __mapped_type;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000684public:
685 typedef bidirectional_iterator_tag iterator_category;
Howard Hinnantb2e8a422011-02-27 18:02:02 +0000686 typedef pair<__key_type, __mapped_type> value_type;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000687 typedef typename _TreeIterator::difference_type difference_type;
688 typedef value_type& reference;
689 typedef typename __pointer_traits::template
690#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
691 rebind<value_type>
692#else
693 rebind<value_type>::other
694#endif
695 pointer;
696
Howard Hinnant756c69b2010-09-22 16:48:34 +0000697 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000698 __map_iterator() _NOEXCEPT {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000699
Howard Hinnant756c69b2010-09-22 16:48:34 +0000700 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000701 __map_iterator(_TreeIterator __i) _NOEXCEPT : __i_(__i) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000702
Howard Hinnant756c69b2010-09-22 16:48:34 +0000703 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2d0046b2013-06-19 21:29:40 +0000704 reference operator*() const {return __i_->__cc;}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000705 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2d0046b2013-06-19 21:29:40 +0000706 pointer operator->() const {return pointer_traits<pointer>::pointer_to(__i_->__cc);}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000707
Howard Hinnant756c69b2010-09-22 16:48:34 +0000708 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000709 __map_iterator& operator++() {++__i_; return *this;}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000710 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000711 __map_iterator operator++(int)
712 {
713 __map_iterator __t(*this);
714 ++(*this);
715 return __t;
716 }
717
Howard Hinnant756c69b2010-09-22 16:48:34 +0000718 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000719 __map_iterator& operator--() {--__i_; return *this;}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000720 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000721 __map_iterator operator--(int)
722 {
723 __map_iterator __t(*this);
724 --(*this);
725 return __t;
726 }
727
Howard Hinnant756c69b2010-09-22 16:48:34 +0000728 friend _LIBCPP_INLINE_VISIBILITY
729 bool operator==(const __map_iterator& __x, const __map_iterator& __y)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000730 {return __x.__i_ == __y.__i_;}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000731 friend
732 _LIBCPP_INLINE_VISIBILITY
733 bool operator!=(const __map_iterator& __x, const __map_iterator& __y)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000734 {return __x.__i_ != __y.__i_;}
735
Howard Hinnanta37d3cf2013-08-12 18:38:34 +0000736 template <class, class, class, class> friend class _LIBCPP_TYPE_VIS_ONLY map;
737 template <class, class, class, class> friend class _LIBCPP_TYPE_VIS_ONLY multimap;
738 template <class> friend class _LIBCPP_TYPE_VIS_ONLY __map_const_iterator;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000739};
740
741template <class _TreeIterator>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +0000742class _LIBCPP_TYPE_VIS_ONLY __map_const_iterator
Howard Hinnantc51e1022010-05-11 19:42:16 +0000743{
744 _TreeIterator __i_;
745
746 typedef typename _TreeIterator::__pointer_traits __pointer_traits;
Eric Fiselier44f9fd02015-03-03 20:10:01 +0000747 typedef typename _TreeIterator::value_type __value_type;
748 typedef typename __extract_key_value_types<__value_type>::__key_type __key_type;
749 typedef typename __extract_key_value_types<__value_type>::__mapped_type __mapped_type;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000750public:
751 typedef bidirectional_iterator_tag iterator_category;
Howard Hinnantb2e8a422011-02-27 18:02:02 +0000752 typedef pair<__key_type, __mapped_type> value_type;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000753 typedef typename _TreeIterator::difference_type difference_type;
754 typedef const value_type& reference;
755 typedef typename __pointer_traits::template
756#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
Howard Hinnant73f3c8a2011-04-11 02:18:41 +0000757 rebind<const value_type>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000758#else
Howard Hinnant73f3c8a2011-04-11 02:18:41 +0000759 rebind<const value_type>::other
Howard Hinnantc51e1022010-05-11 19:42:16 +0000760#endif
761 pointer;
762
Howard Hinnant756c69b2010-09-22 16:48:34 +0000763 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000764 __map_const_iterator() _NOEXCEPT {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000765
Howard Hinnant756c69b2010-09-22 16:48:34 +0000766 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000767 __map_const_iterator(_TreeIterator __i) _NOEXCEPT : __i_(__i) {}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000768 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier44f9fd02015-03-03 20:10:01 +0000769 __map_const_iterator(__map_iterator<
770 typename _TreeIterator::__non_const_iterator> __i) _NOEXCEPT
771 : __i_(__i.__i_) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000772
Howard Hinnant756c69b2010-09-22 16:48:34 +0000773 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2d0046b2013-06-19 21:29:40 +0000774 reference operator*() const {return __i_->__cc;}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000775 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2d0046b2013-06-19 21:29:40 +0000776 pointer operator->() const {return pointer_traits<pointer>::pointer_to(__i_->__cc);}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000777
Howard Hinnant756c69b2010-09-22 16:48:34 +0000778 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000779 __map_const_iterator& operator++() {++__i_; return *this;}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000780 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000781 __map_const_iterator operator++(int)
782 {
783 __map_const_iterator __t(*this);
784 ++(*this);
785 return __t;
786 }
787
Howard Hinnant756c69b2010-09-22 16:48:34 +0000788 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000789 __map_const_iterator& operator--() {--__i_; return *this;}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000790 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000791 __map_const_iterator operator--(int)
792 {
793 __map_const_iterator __t(*this);
794 --(*this);
795 return __t;
796 }
797
Howard Hinnant756c69b2010-09-22 16:48:34 +0000798 friend _LIBCPP_INLINE_VISIBILITY
799 bool operator==(const __map_const_iterator& __x, const __map_const_iterator& __y)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000800 {return __x.__i_ == __y.__i_;}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000801 friend _LIBCPP_INLINE_VISIBILITY
802 bool operator!=(const __map_const_iterator& __x, const __map_const_iterator& __y)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000803 {return __x.__i_ != __y.__i_;}
804
Howard Hinnanta37d3cf2013-08-12 18:38:34 +0000805 template <class, class, class, class> friend class _LIBCPP_TYPE_VIS_ONLY map;
806 template <class, class, class, class> friend class _LIBCPP_TYPE_VIS_ONLY multimap;
807 template <class, class, class> friend class _LIBCPP_TYPE_VIS_ONLY __tree_const_iterator;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000808};
809
810template <class _Key, class _Tp, class _Compare = less<_Key>,
811 class _Allocator = allocator<pair<const _Key, _Tp> > >
Howard Hinnanta37d3cf2013-08-12 18:38:34 +0000812class _LIBCPP_TYPE_VIS_ONLY map
Howard Hinnantc51e1022010-05-11 19:42:16 +0000813{
814public:
815 // types:
816 typedef _Key key_type;
817 typedef _Tp mapped_type;
818 typedef pair<const key_type, mapped_type> value_type;
Howard Hinnant2d0046b2013-06-19 21:29:40 +0000819 typedef pair<key_type, mapped_type> __nc_value_type;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000820 typedef _Compare key_compare;
821 typedef _Allocator allocator_type;
822 typedef value_type& reference;
823 typedef const value_type& const_reference;
824
Howard Hinnanta37d3cf2013-08-12 18:38:34 +0000825 class _LIBCPP_TYPE_VIS_ONLY value_compare
Howard Hinnantc51e1022010-05-11 19:42:16 +0000826 : public binary_function<value_type, value_type, bool>
827 {
828 friend class map;
829 protected:
830 key_compare comp;
831
Howard Hinnant756c69b2010-09-22 16:48:34 +0000832 _LIBCPP_INLINE_VISIBILITY value_compare(key_compare c) : comp(c) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000833 public:
Howard Hinnant756c69b2010-09-22 16:48:34 +0000834 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000835 bool operator()(const value_type& __x, const value_type& __y) const
836 {return comp(__x.first, __y.first);}
837 };
838
839private:
Howard Hinnant2d0046b2013-06-19 21:29:40 +0000840
Howard Hinnant89f8b792013-09-30 19:08:22 +0000841 typedef _VSTD::__value_type<key_type, mapped_type> __value_type;
Howard Hinnant90b91592013-07-05 18:06:00 +0000842 typedef __map_value_compare<key_type, __value_type, key_compare> __vc;
Marshall Clow940e01c2015-04-07 05:21:38 +0000843 typedef typename __rebind_alloc_helper<allocator_traits<allocator_type>,
844 __value_type>::type __allocator_type;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000845 typedef __tree<__value_type, __vc, __allocator_type> __base;
846 typedef typename __base::__node_traits __node_traits;
847 typedef allocator_traits<allocator_type> __alloc_traits;
848
849 __base __tree_;
850
851public:
852 typedef typename __alloc_traits::pointer pointer;
853 typedef typename __alloc_traits::const_pointer const_pointer;
854 typedef typename __alloc_traits::size_type size_type;
855 typedef typename __alloc_traits::difference_type difference_type;
Eric Fiselier44f9fd02015-03-03 20:10:01 +0000856 typedef __map_iterator<typename __base::iterator> iterator;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000857 typedef __map_const_iterator<typename __base::const_iterator> const_iterator;
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000858 typedef _VSTD::reverse_iterator<iterator> reverse_iterator;
859 typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000860
Howard Hinnant756c69b2010-09-22 16:48:34 +0000861 _LIBCPP_INLINE_VISIBILITY
Marshall Clow7086a5a2014-03-10 04:50:10 +0000862 map()
863 _NOEXCEPT_(
864 is_nothrow_default_constructible<allocator_type>::value &&
865 is_nothrow_default_constructible<key_compare>::value &&
866 is_nothrow_copy_constructible<key_compare>::value)
867 : __tree_(__vc(key_compare())) {}
868
869 _LIBCPP_INLINE_VISIBILITY
870 explicit map(const key_compare& __comp)
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000871 _NOEXCEPT_(
872 is_nothrow_default_constructible<allocator_type>::value &&
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000873 is_nothrow_copy_constructible<key_compare>::value)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000874 : __tree_(__vc(__comp)) {}
875
Howard Hinnant756c69b2010-09-22 16:48:34 +0000876 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000877 explicit map(const key_compare& __comp, const allocator_type& __a)
878 : __tree_(__vc(__comp), __a) {}
879
880 template <class _InputIterator>
Howard Hinnant756c69b2010-09-22 16:48:34 +0000881 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000882 map(_InputIterator __f, _InputIterator __l,
883 const key_compare& __comp = key_compare())
884 : __tree_(__vc(__comp))
885 {
886 insert(__f, __l);
887 }
888
889 template <class _InputIterator>
Howard Hinnant756c69b2010-09-22 16:48:34 +0000890 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000891 map(_InputIterator __f, _InputIterator __l,
892 const key_compare& __comp, const allocator_type& __a)
893 : __tree_(__vc(__comp), __a)
894 {
895 insert(__f, __l);
896 }
897
Marshall Clow300abfb2013-09-11 01:15:47 +0000898#if _LIBCPP_STD_VER > 11
899 template <class _InputIterator>
900 _LIBCPP_INLINE_VISIBILITY
901 map(_InputIterator __f, _InputIterator __l, const allocator_type& __a)
902 : map(__f, __l, key_compare(), __a) {}
903#endif
904
Howard Hinnant756c69b2010-09-22 16:48:34 +0000905 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000906 map(const map& __m)
907 : __tree_(__m.__tree_)
908 {
909 insert(__m.begin(), __m.end());
910 }
911
Howard Hinnantd3a657f2011-07-01 19:24:36 +0000912 _LIBCPP_INLINE_VISIBILITY
913 map& operator=(const map& __m)
914 {
Howard Hinnant2d0046b2013-06-19 21:29:40 +0000915#if __cplusplus >= 201103L
Howard Hinnantd3a657f2011-07-01 19:24:36 +0000916 __tree_ = __m.__tree_;
Howard Hinnant2d0046b2013-06-19 21:29:40 +0000917#else
Marshall Clowdb3cfcb2014-02-08 04:03:14 +0000918 if (this != &__m) {
919 __tree_.clear();
920 __tree_.value_comp() = __m.__tree_.value_comp();
921 __tree_.__copy_assign_alloc(__m.__tree_);
922 insert(__m.begin(), __m.end());
923 }
Howard Hinnant2d0046b2013-06-19 21:29:40 +0000924#endif
Howard Hinnantd3a657f2011-07-01 19:24:36 +0000925 return *this;
926 }
927
Howard Hinnant74279a52010-09-04 23:28:19 +0000928#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +0000929
Howard Hinnant756c69b2010-09-22 16:48:34 +0000930 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000931 map(map&& __m)
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000932 _NOEXCEPT_(is_nothrow_move_constructible<__base>::value)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000933 : __tree_(_VSTD::move(__m.__tree_))
Howard Hinnantc51e1022010-05-11 19:42:16 +0000934 {
935 }
936
937 map(map&& __m, const allocator_type& __a);
938
Howard Hinnant756c69b2010-09-22 16:48:34 +0000939 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant33711792011-08-12 21:56:02 +0000940 map& operator=(map&& __m)
941 _NOEXCEPT_(is_nothrow_move_assignable<__base>::value)
942 {
943 __tree_ = _VSTD::move(__m.__tree_);
944 return *this;
945 }
946
947#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
948
949#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
950
951 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000952 map(initializer_list<value_type> __il, const key_compare& __comp = key_compare())
953 : __tree_(__vc(__comp))
954 {
955 insert(__il.begin(), __il.end());
956 }
957
Howard Hinnant756c69b2010-09-22 16:48:34 +0000958 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000959 map(initializer_list<value_type> __il, const key_compare& __comp, const allocator_type& __a)
960 : __tree_(__vc(__comp), __a)
961 {
962 insert(__il.begin(), __il.end());
963 }
964
Marshall Clow300abfb2013-09-11 01:15:47 +0000965#if _LIBCPP_STD_VER > 11
966 _LIBCPP_INLINE_VISIBILITY
967 map(initializer_list<value_type> __il, const allocator_type& __a)
968 : map(__il, key_compare(), __a) {}
969#endif
970
Howard Hinnant756c69b2010-09-22 16:48:34 +0000971 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000972 map& operator=(initializer_list<value_type> __il)
973 {
974 __tree_.__assign_unique(__il.begin(), __il.end());
975 return *this;
976 }
977
Howard Hinnant33711792011-08-12 21:56:02 +0000978#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000979
Howard Hinnant756c69b2010-09-22 16:48:34 +0000980 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000981 explicit map(const allocator_type& __a)
982 : __tree_(__a)
983 {
984 }
985
Howard Hinnant756c69b2010-09-22 16:48:34 +0000986 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000987 map(const map& __m, const allocator_type& __a)
988 : __tree_(__m.__tree_.value_comp(), __a)
989 {
990 insert(__m.begin(), __m.end());
991 }
992
Howard Hinnant756c69b2010-09-22 16:48:34 +0000993 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000994 iterator begin() _NOEXCEPT {return __tree_.begin();}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000995 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000996 const_iterator begin() const _NOEXCEPT {return __tree_.begin();}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000997 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000998 iterator end() _NOEXCEPT {return __tree_.end();}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000999 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001000 const_iterator end() const _NOEXCEPT {return __tree_.end();}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001001
Howard Hinnant756c69b2010-09-22 16:48:34 +00001002 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001003 reverse_iterator rbegin() _NOEXCEPT {return reverse_iterator(end());}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001004 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001005 const_reverse_iterator rbegin() const _NOEXCEPT
1006 {return const_reverse_iterator(end());}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001007 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001008 reverse_iterator rend() _NOEXCEPT
1009 {return reverse_iterator(begin());}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001010 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001011 const_reverse_iterator rend() const _NOEXCEPT
1012 {return const_reverse_iterator(begin());}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001013
Howard Hinnant756c69b2010-09-22 16:48:34 +00001014 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001015 const_iterator cbegin() const _NOEXCEPT {return begin();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001016 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001017 const_iterator cend() const _NOEXCEPT {return end();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001018 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001019 const_reverse_iterator crbegin() const _NOEXCEPT {return rbegin();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001020 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001021 const_reverse_iterator crend() const _NOEXCEPT {return rend();}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001022
Howard Hinnant756c69b2010-09-22 16:48:34 +00001023 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001024 bool empty() const _NOEXCEPT {return __tree_.size() == 0;}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001025 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001026 size_type size() const _NOEXCEPT {return __tree_.size();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001027 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001028 size_type max_size() const _NOEXCEPT {return __tree_.max_size();}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001029
1030 mapped_type& operator[](const key_type& __k);
Howard Hinnant74279a52010-09-04 23:28:19 +00001031#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +00001032 mapped_type& operator[](key_type&& __k);
1033#endif
1034
1035 mapped_type& at(const key_type& __k);
1036 const mapped_type& at(const key_type& __k) const;
1037
Howard Hinnant756c69b2010-09-22 16:48:34 +00001038 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001039 allocator_type get_allocator() const _NOEXCEPT {return __tree_.__alloc();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001040 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001041 key_compare key_comp() const {return __tree_.value_comp().key_comp();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001042 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001043 value_compare value_comp() const {return value_compare(__tree_.value_comp().key_comp());}
1044
Howard Hinnant74279a52010-09-04 23:28:19 +00001045#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant74279a52010-09-04 23:28:19 +00001046#ifndef _LIBCPP_HAS_NO_VARIADICS
1047
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001048 template <class ..._Args>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001049 pair<iterator, bool>
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001050 emplace(_Args&& ...__args);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001051
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001052 template <class ..._Args>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001053 iterator
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001054 emplace_hint(const_iterator __p, _Args&& ...__args);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001055
Howard Hinnant74279a52010-09-04 23:28:19 +00001056#endif // _LIBCPP_HAS_NO_VARIADICS
1057
Howard Hinnantc834c512011-11-29 18:15:50 +00001058 template <class _Pp,
1059 class = typename enable_if<is_constructible<value_type, _Pp>::value>::type>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001060 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc834c512011-11-29 18:15:50 +00001061 pair<iterator, bool> insert(_Pp&& __p)
1062 {return __tree_.__insert_unique(_VSTD::forward<_Pp>(__p));}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001063
Howard Hinnantc834c512011-11-29 18:15:50 +00001064 template <class _Pp,
1065 class = typename enable_if<is_constructible<value_type, _Pp>::value>::type>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001066 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc834c512011-11-29 18:15:50 +00001067 iterator insert(const_iterator __pos, _Pp&& __p)
1068 {return __tree_.__insert_unique(__pos.__i_, _VSTD::forward<_Pp>(__p));}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001069
Howard Hinnant74279a52010-09-04 23:28:19 +00001070#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +00001071
Howard Hinnant756c69b2010-09-22 16:48:34 +00001072 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001073 pair<iterator, bool>
1074 insert(const value_type& __v) {return __tree_.__insert_unique(__v);}
1075
Howard Hinnant756c69b2010-09-22 16:48:34 +00001076 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001077 iterator
1078 insert(const_iterator __p, const value_type& __v)
1079 {return __tree_.__insert_unique(__p.__i_, __v);}
1080
1081 template <class _InputIterator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001082 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001083 void insert(_InputIterator __f, _InputIterator __l)
1084 {
1085 for (const_iterator __e = cend(); __f != __l; ++__f)
1086 insert(__e.__i_, *__f);
1087 }
1088
Howard Hinnant33711792011-08-12 21:56:02 +00001089#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1090
Howard Hinnant756c69b2010-09-22 16:48:34 +00001091 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001092 void insert(initializer_list<value_type> __il)
1093 {insert(__il.begin(), __il.end());}
1094
Howard Hinnant33711792011-08-12 21:56:02 +00001095#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1096
Marshall Clow3223db82015-07-07 03:37:33 +00001097#if _LIBCPP_STD_VER > 14
1098#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
1099#ifndef _LIBCPP_HAS_NO_VARIADICS
1100 template <class... _Args>
1101 _LIBCPP_INLINE_VISIBILITY
1102 pair<iterator, bool> try_emplace(const key_type& __k, _Args&&... __args)
1103 {
1104 iterator __p = lower_bound(__k);
1105 if ( __p != end() && !key_comp()(__k, __p->first))
1106 return _VSTD::make_pair(__p, false);
1107 else
1108 return _VSTD::make_pair(
1109 emplace_hint(__p,
1110 _VSTD::piecewise_construct, _VSTD::forward_as_tuple(__k),
1111 _VSTD::forward_as_tuple(_VSTD::forward<_Args>(__args)...)),
1112 true);
1113 }
1114
1115 template <class... _Args>
1116 _LIBCPP_INLINE_VISIBILITY
1117 pair<iterator, bool> try_emplace(key_type&& __k, _Args&&... __args)
1118 {
1119 iterator __p = lower_bound(__k);
1120 if ( __p != end() && !key_comp()(__k, __p->first))
1121 return _VSTD::make_pair(__p, false);
1122 else
1123 return _VSTD::make_pair(
1124 emplace_hint(__p,
1125 _VSTD::piecewise_construct, _VSTD::forward_as_tuple(_VSTD::move(__k)),
1126 _VSTD::forward_as_tuple(_VSTD::forward<_Args>(__args)...)),
1127 true);
1128 }
1129
1130 template <class... _Args>
1131 _LIBCPP_INLINE_VISIBILITY
1132 iterator try_emplace(const_iterator __h, const key_type& __k, _Args&&... __args)
1133 {
1134 iterator __p = lower_bound(__k);
1135 if ( __p != end() && !key_comp()(__k, __p->first))
1136 return __p;
1137 else
1138 return emplace_hint(__p,
1139 _VSTD::piecewise_construct, _VSTD::forward_as_tuple(__k),
1140 _VSTD::forward_as_tuple(_VSTD::forward<_Args>(__args)...));
1141 }
1142
1143 template <class... _Args>
1144 _LIBCPP_INLINE_VISIBILITY
1145 iterator try_emplace(const_iterator __h, key_type&& __k, _Args&&... __args)
1146 {
1147 iterator __p = lower_bound(__k);
1148 if ( __p != end() && !key_comp()(__k, __p->first))
1149 return __p;
1150 else
1151 return emplace_hint(__p,
1152 _VSTD::piecewise_construct, _VSTD::forward_as_tuple(_VSTD::move(__k)),
1153 _VSTD::forward_as_tuple(_VSTD::forward<_Args>(__args)...));
1154 }
1155
1156 template <class _Vp>
1157 _LIBCPP_INLINE_VISIBILITY
1158 pair<iterator, bool> insert_or_assign(const key_type& __k, _Vp&& __v)
1159 {
1160 iterator __p = lower_bound(__k);
1161 if ( __p != end() && !key_comp()(__k, __p->first))
1162 {
1163 __p->second = _VSTD::forward<_Vp>(__v);
1164 return _VSTD::make_pair(__p, false);
1165 }
1166 return _VSTD::make_pair(emplace_hint(__p, __k, _VSTD::forward<_Vp>(__v)), true);
1167 }
1168
1169 template <class _Vp>
1170 _LIBCPP_INLINE_VISIBILITY
1171 pair<iterator, bool> insert_or_assign(key_type&& __k, _Vp&& __v)
1172 {
1173 iterator __p = lower_bound(__k);
1174 if ( __p != end() && !key_comp()(__k, __p->first))
1175 {
1176 __p->second = _VSTD::forward<_Vp>(__v);
1177 return _VSTD::make_pair(__p, false);
1178 }
1179 return _VSTD::make_pair(emplace_hint(__p, _VSTD::move(__k), _VSTD::forward<_Vp>(__v)), true);
1180 }
1181
1182 template <class _Vp>
1183 _LIBCPP_INLINE_VISIBILITY
1184 iterator insert_or_assign(const_iterator __h, const key_type& __k, _Vp&& __v)
1185 {
1186 iterator __p = lower_bound(__k);
1187 if ( __p != end() && !key_comp()(__k, __p->first))
1188 {
1189 __p->second = _VSTD::forward<_Vp>(__v);
1190 return __p;
1191 }
1192 return emplace_hint(__h, __k, _VSTD::forward<_Vp>(__v));
1193 }
1194
1195 template <class _Vp>
1196 _LIBCPP_INLINE_VISIBILITY
1197 iterator insert_or_assign(const_iterator __h, key_type&& __k, _Vp&& __v)
1198 {
1199 iterator __p = lower_bound(__k);
1200 if ( __p != end() && !key_comp()(__k, __p->first))
1201 {
1202 __p->second = _VSTD::forward<_Vp>(__v);
1203 return __p;
1204 }
1205 return emplace_hint(__h, _VSTD::move(__k), _VSTD::forward<_Vp>(__v));
1206 }
1207#endif
1208#endif
1209#endif
1210
Howard Hinnant756c69b2010-09-22 16:48:34 +00001211 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001212 iterator erase(const_iterator __p) {return __tree_.erase(__p.__i_);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001213 _LIBCPP_INLINE_VISIBILITY
Marshall Clow22ea5b82015-05-10 13:35:00 +00001214 iterator erase(iterator __p) {return __tree_.erase(__p.__i_);}
1215 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001216 size_type erase(const key_type& __k)
1217 {return __tree_.__erase_unique(__k);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001218 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001219 iterator erase(const_iterator __f, const_iterator __l)
1220 {return __tree_.erase(__f.__i_, __l.__i_);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001221 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001222 void clear() _NOEXCEPT {__tree_.clear();}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001223
Howard Hinnant756c69b2010-09-22 16:48:34 +00001224 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001225 void swap(map& __m)
1226 _NOEXCEPT_(__is_nothrow_swappable<__base>::value)
1227 {__tree_.swap(__m.__tree_);}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001228
Howard Hinnant756c69b2010-09-22 16:48:34 +00001229 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001230 iterator find(const key_type& __k) {return __tree_.find(__k);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001231 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001232 const_iterator find(const key_type& __k) const {return __tree_.find(__k);}
Marshall Clowebb57322013-08-13 22:18:47 +00001233#if _LIBCPP_STD_VER > 11
1234 template <typename _K2>
1235 _LIBCPP_INLINE_VISIBILITY
1236 typename enable_if<__is_transparent<_Compare, _K2>::value,iterator>::type
1237 find(const _K2& __k) {return __tree_.find(__k);}
1238 template <typename _K2>
1239 _LIBCPP_INLINE_VISIBILITY
1240 typename enable_if<__is_transparent<_Compare, _K2>::value,const_iterator>::type
1241 find(const _K2& __k) const {return __tree_.find(__k);}
1242#endif
1243
Howard Hinnant756c69b2010-09-22 16:48:34 +00001244 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001245 size_type count(const key_type& __k) const
1246 {return __tree_.__count_unique(__k);}
Marshall Clowe6a5f522014-08-24 23:54:16 +00001247#if _LIBCPP_STD_VER > 11
1248 template <typename _K2>
1249 _LIBCPP_INLINE_VISIBILITY
1250 typename enable_if<__is_transparent<_Compare, _K2>::value,size_type>::type
Marshall Clow141e47b2015-06-30 18:15:41 +00001251 count(const _K2& __k) const {return __tree_.__count_unique(__k);}
Marshall Clowe6a5f522014-08-24 23:54:16 +00001252#endif
Howard Hinnant756c69b2010-09-22 16:48:34 +00001253 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001254 iterator lower_bound(const key_type& __k)
1255 {return __tree_.lower_bound(__k);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001256 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001257 const_iterator lower_bound(const key_type& __k) const
1258 {return __tree_.lower_bound(__k);}
Marshall Clowebb57322013-08-13 22:18:47 +00001259#if _LIBCPP_STD_VER > 11
1260 template <typename _K2>
1261 _LIBCPP_INLINE_VISIBILITY
1262 typename enable_if<__is_transparent<_Compare, _K2>::value,iterator>::type
1263 lower_bound(const _K2& __k) {return __tree_.lower_bound(__k);}
1264
1265 template <typename _K2>
1266 _LIBCPP_INLINE_VISIBILITY
1267 typename enable_if<__is_transparent<_Compare, _K2>::value,const_iterator>::type
1268 lower_bound(const _K2& __k) const {return __tree_.lower_bound(__k);}
1269#endif
1270
Howard Hinnant756c69b2010-09-22 16:48:34 +00001271 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001272 iterator upper_bound(const key_type& __k)
1273 {return __tree_.upper_bound(__k);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001274 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001275 const_iterator upper_bound(const key_type& __k) const
1276 {return __tree_.upper_bound(__k);}
Marshall Clowebb57322013-08-13 22:18:47 +00001277#if _LIBCPP_STD_VER > 11
1278 template <typename _K2>
1279 _LIBCPP_INLINE_VISIBILITY
1280 typename enable_if<__is_transparent<_Compare, _K2>::value,iterator>::type
1281 upper_bound(const _K2& __k) {return __tree_.upper_bound(__k);}
1282 template <typename _K2>
1283 _LIBCPP_INLINE_VISIBILITY
1284 typename enable_if<__is_transparent<_Compare, _K2>::value,const_iterator>::type
1285 upper_bound(const _K2& __k) const {return __tree_.upper_bound(__k);}
1286#endif
1287
Howard Hinnant756c69b2010-09-22 16:48:34 +00001288 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001289 pair<iterator,iterator> equal_range(const key_type& __k)
1290 {return __tree_.__equal_range_unique(__k);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001291 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001292 pair<const_iterator,const_iterator> equal_range(const key_type& __k) const
1293 {return __tree_.__equal_range_unique(__k);}
Marshall Clowebb57322013-08-13 22:18:47 +00001294#if _LIBCPP_STD_VER > 11
1295 template <typename _K2>
1296 _LIBCPP_INLINE_VISIBILITY
1297 typename enable_if<__is_transparent<_Compare, _K2>::value,pair<iterator,iterator>>::type
1298 equal_range(const _K2& __k) {return __tree_.__equal_range_unique(__k);}
1299 template <typename _K2>
1300 _LIBCPP_INLINE_VISIBILITY
1301 typename enable_if<__is_transparent<_Compare, _K2>::value,pair<const_iterator,const_iterator>>::type
1302 equal_range(const _K2& __k) const {return __tree_.__equal_range_unique(__k);}
1303#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001304
1305private:
1306 typedef typename __base::__node __node;
1307 typedef typename __base::__node_allocator __node_allocator;
1308 typedef typename __base::__node_pointer __node_pointer;
1309 typedef typename __base::__node_const_pointer __node_const_pointer;
1310 typedef typename __base::__node_base_pointer __node_base_pointer;
1311 typedef typename __base::__node_base_const_pointer __node_base_const_pointer;
Howard Hinnantc834c512011-11-29 18:15:50 +00001312 typedef __map_node_destructor<__node_allocator> _Dp;
1313 typedef unique_ptr<__node, _Dp> __node_holder;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001314
Howard Hinnant74279a52010-09-04 23:28:19 +00001315#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +00001316 __node_holder __construct_node();
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001317 template <class _A0>
Howard Hinnantac7e7482013-07-04 20:59:16 +00001318 __node_holder __construct_node(_A0&& __a0);
1319 __node_holder __construct_node_with_key(key_type&& __k);
Howard Hinnant74279a52010-09-04 23:28:19 +00001320#ifndef _LIBCPP_HAS_NO_VARIADICS
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001321 template <class _A0, class _A1, class ..._Args>
1322 __node_holder __construct_node(_A0&& __a0, _A1&& __a1, _Args&& ...__args);
Howard Hinnant74279a52010-09-04 23:28:19 +00001323#endif // _LIBCPP_HAS_NO_VARIADICS
Howard Hinnantc51e1022010-05-11 19:42:16 +00001324#endif
Howard Hinnantac7e7482013-07-04 20:59:16 +00001325 __node_holder __construct_node_with_key(const key_type& __k);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001326
1327 __node_base_pointer&
1328 __find_equal_key(__node_base_pointer& __parent, const key_type& __k);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001329 __node_base_const_pointer
1330 __find_equal_key(__node_base_const_pointer& __parent, const key_type& __k) const;
1331};
1332
1333// Find place to insert if __k doesn't exist
1334// Set __parent to parent of null leaf
1335// Return reference to null leaf
1336// If __k exists, set parent to node of __k and return reference to node of __k
1337template <class _Key, class _Tp, class _Compare, class _Allocator>
1338typename map<_Key, _Tp, _Compare, _Allocator>::__node_base_pointer&
1339map<_Key, _Tp, _Compare, _Allocator>::__find_equal_key(__node_base_pointer& __parent,
1340 const key_type& __k)
1341{
1342 __node_pointer __nd = __tree_.__root();
1343 if (__nd != nullptr)
1344 {
1345 while (true)
1346 {
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001347 if (__tree_.value_comp().key_comp()(__k, __nd->__value_.__cc.first))
Howard Hinnantc51e1022010-05-11 19:42:16 +00001348 {
1349 if (__nd->__left_ != nullptr)
1350 __nd = static_cast<__node_pointer>(__nd->__left_);
1351 else
1352 {
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001353 __parent = static_cast<__node_base_pointer>(__nd);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001354 return __parent->__left_;
1355 }
1356 }
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001357 else if (__tree_.value_comp().key_comp()(__nd->__value_.__cc.first, __k))
Howard Hinnantc51e1022010-05-11 19:42:16 +00001358 {
1359 if (__nd->__right_ != nullptr)
1360 __nd = static_cast<__node_pointer>(__nd->__right_);
1361 else
1362 {
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001363 __parent = static_cast<__node_base_pointer>(__nd);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001364 return __parent->__right_;
1365 }
1366 }
1367 else
1368 {
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001369 __parent = static_cast<__node_base_pointer>(__nd);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001370 return __parent;
1371 }
1372 }
1373 }
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001374 __parent = static_cast<__node_base_pointer>(__tree_.__end_node());
Howard Hinnantc51e1022010-05-11 19:42:16 +00001375 return __parent->__left_;
1376}
1377
Howard Hinnantc51e1022010-05-11 19:42:16 +00001378// Find __k
1379// Set __parent to parent of null leaf and
1380// return reference to null leaf iv __k does not exist.
1381// If __k exists, set parent to node of __k and return reference to node of __k
1382template <class _Key, class _Tp, class _Compare, class _Allocator>
1383typename map<_Key, _Tp, _Compare, _Allocator>::__node_base_const_pointer
1384map<_Key, _Tp, _Compare, _Allocator>::__find_equal_key(__node_base_const_pointer& __parent,
1385 const key_type& __k) const
1386{
1387 __node_const_pointer __nd = __tree_.__root();
1388 if (__nd != nullptr)
1389 {
1390 while (true)
1391 {
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001392 if (__tree_.value_comp().key_comp()(__k, __nd->__value_.__cc.first))
Howard Hinnantc51e1022010-05-11 19:42:16 +00001393 {
1394 if (__nd->__left_ != nullptr)
1395 __nd = static_cast<__node_pointer>(__nd->__left_);
1396 else
1397 {
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001398 __parent = static_cast<__node_base_pointer>(__nd);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001399 return const_cast<const __node_base_const_pointer&>(__parent->__left_);
1400 }
1401 }
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001402 else if (__tree_.value_comp().key_comp()(__nd->__value_.__cc.first, __k))
Howard Hinnantc51e1022010-05-11 19:42:16 +00001403 {
1404 if (__nd->__right_ != nullptr)
1405 __nd = static_cast<__node_pointer>(__nd->__right_);
1406 else
1407 {
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001408 __parent = static_cast<__node_base_pointer>(__nd);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001409 return const_cast<const __node_base_const_pointer&>(__parent->__right_);
1410 }
1411 }
1412 else
1413 {
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001414 __parent = static_cast<__node_base_pointer>(__nd);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001415 return __parent;
1416 }
1417 }
1418 }
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001419 __parent = static_cast<__node_base_pointer>(__tree_.__end_node());
Howard Hinnantc51e1022010-05-11 19:42:16 +00001420 return const_cast<const __node_base_const_pointer&>(__parent->__left_);
1421}
1422
Howard Hinnant74279a52010-09-04 23:28:19 +00001423#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +00001424
1425template <class _Key, class _Tp, class _Compare, class _Allocator>
1426map<_Key, _Tp, _Compare, _Allocator>::map(map&& __m, const allocator_type& __a)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001427 : __tree_(_VSTD::move(__m.__tree_), __a)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001428{
1429 if (__a != __m.get_allocator())
1430 {
1431 const_iterator __e = cend();
1432 while (!__m.empty())
1433 __tree_.__insert_unique(__e.__i_,
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001434 _VSTD::move(__m.__tree_.remove(__m.begin().__i_)->__value_));
Howard Hinnantc51e1022010-05-11 19:42:16 +00001435 }
1436}
1437
1438template <class _Key, class _Tp, class _Compare, class _Allocator>
1439typename map<_Key, _Tp, _Compare, _Allocator>::__node_holder
1440map<_Key, _Tp, _Compare, _Allocator>::__construct_node()
1441{
1442 __node_allocator& __na = __tree_.__node_alloc();
Howard Hinnantc834c512011-11-29 18:15:50 +00001443 __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001444 __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__cc.first));
Howard Hinnantc51e1022010-05-11 19:42:16 +00001445 __h.get_deleter().__first_constructed = true;
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001446 __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__cc.second));
Howard Hinnantc51e1022010-05-11 19:42:16 +00001447 __h.get_deleter().__second_constructed = true;
1448 return __h;
1449}
1450
1451template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001452template <class _A0>
Howard Hinnantac7e7482013-07-04 20:59:16 +00001453typename map<_Key, _Tp, _Compare, _Allocator>::__node_holder
Howard Hinnantc51e1022010-05-11 19:42:16 +00001454map<_Key, _Tp, _Compare, _Allocator>::__construct_node(_A0&& __a0)
1455{
1456 __node_allocator& __na = __tree_.__node_alloc();
Howard Hinnantc834c512011-11-29 18:15:50 +00001457 __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001458 __node_traits::construct(__na, _VSTD::addressof(__h->__value_), _VSTD::forward<_A0>(__a0));
Howard Hinnantc51e1022010-05-11 19:42:16 +00001459 __h.get_deleter().__first_constructed = true;
1460 __h.get_deleter().__second_constructed = true;
1461 return __h;
1462}
1463
1464template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnantac7e7482013-07-04 20:59:16 +00001465typename map<_Key, _Tp, _Compare, _Allocator>::__node_holder
1466map<_Key, _Tp, _Compare, _Allocator>::__construct_node_with_key(key_type&& __k)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001467{
1468 __node_allocator& __na = __tree_.__node_alloc();
Howard Hinnantc834c512011-11-29 18:15:50 +00001469 __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
Howard Hinnantac7e7482013-07-04 20:59:16 +00001470 __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__cc.first), _VSTD::move(__k));
Howard Hinnantc51e1022010-05-11 19:42:16 +00001471 __h.get_deleter().__first_constructed = true;
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001472 __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__cc.second));
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001473 __h.get_deleter().__second_constructed = true;
Howard Hinnanta31e9682013-08-22 18:29:50 +00001474 return __h;
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001475}
1476
1477#ifndef _LIBCPP_HAS_NO_VARIADICS
1478
1479template <class _Key, class _Tp, class _Compare, class _Allocator>
1480template <class _A0, class _A1, class ..._Args>
1481typename map<_Key, _Tp, _Compare, _Allocator>::__node_holder
1482map<_Key, _Tp, _Compare, _Allocator>::__construct_node(_A0&& __a0, _A1&& __a1, _Args&& ...__args)
1483{
1484 __node_allocator& __na = __tree_.__node_alloc();
1485 __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
1486 __node_traits::construct(__na, _VSTD::addressof(__h->__value_),
1487 _VSTD::forward<_A0>(__a0), _VSTD::forward<_A1>(__a1),
1488 _VSTD::forward<_Args>(__args)...);
1489 __h.get_deleter().__first_constructed = true;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001490 __h.get_deleter().__second_constructed = true;
1491 return __h;
1492}
1493
Howard Hinnant74279a52010-09-04 23:28:19 +00001494#endif // _LIBCPP_HAS_NO_VARIADICS
1495
Howard Hinnantac7e7482013-07-04 20:59:16 +00001496#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +00001497
1498template <class _Key, class _Tp, class _Compare, class _Allocator>
1499typename map<_Key, _Tp, _Compare, _Allocator>::__node_holder
Howard Hinnantac7e7482013-07-04 20:59:16 +00001500map<_Key, _Tp, _Compare, _Allocator>::__construct_node_with_key(const key_type& __k)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001501{
1502 __node_allocator& __na = __tree_.__node_alloc();
Howard Hinnantc834c512011-11-29 18:15:50 +00001503 __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001504 __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__cc.first), __k);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001505 __h.get_deleter().__first_constructed = true;
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001506 __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__cc.second));
Howard Hinnantc51e1022010-05-11 19:42:16 +00001507 __h.get_deleter().__second_constructed = true;
Howard Hinnanta31e9682013-08-22 18:29:50 +00001508 return _VSTD::move(__h); // explicitly moved for C++03
Howard Hinnantc51e1022010-05-11 19:42:16 +00001509}
1510
Howard Hinnantc51e1022010-05-11 19:42:16 +00001511template <class _Key, class _Tp, class _Compare, class _Allocator>
1512_Tp&
1513map<_Key, _Tp, _Compare, _Allocator>::operator[](const key_type& __k)
1514{
1515 __node_base_pointer __parent;
1516 __node_base_pointer& __child = __find_equal_key(__parent, __k);
1517 __node_pointer __r = static_cast<__node_pointer>(__child);
1518 if (__child == nullptr)
1519 {
Howard Hinnantac7e7482013-07-04 20:59:16 +00001520 __node_holder __h = __construct_node_with_key(__k);
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001521 __tree_.__insert_node_at(__parent, __child, static_cast<__node_base_pointer>(__h.get()));
Howard Hinnantc51e1022010-05-11 19:42:16 +00001522 __r = __h.release();
1523 }
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001524 return __r->__value_.__cc.second;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001525}
1526
Howard Hinnant74279a52010-09-04 23:28:19 +00001527#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +00001528
1529template <class _Key, class _Tp, class _Compare, class _Allocator>
1530_Tp&
1531map<_Key, _Tp, _Compare, _Allocator>::operator[](key_type&& __k)
1532{
1533 __node_base_pointer __parent;
1534 __node_base_pointer& __child = __find_equal_key(__parent, __k);
1535 __node_pointer __r = static_cast<__node_pointer>(__child);
1536 if (__child == nullptr)
1537 {
Howard Hinnantac7e7482013-07-04 20:59:16 +00001538 __node_holder __h = __construct_node_with_key(_VSTD::move(__k));
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001539 __tree_.__insert_node_at(__parent, __child, static_cast<__node_base_pointer>(__h.get()));
Howard Hinnantc51e1022010-05-11 19:42:16 +00001540 __r = __h.release();
1541 }
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001542 return __r->__value_.__cc.second;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001543}
1544
Howard Hinnant74279a52010-09-04 23:28:19 +00001545#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +00001546
1547template <class _Key, class _Tp, class _Compare, class _Allocator>
1548_Tp&
1549map<_Key, _Tp, _Compare, _Allocator>::at(const key_type& __k)
1550{
1551 __node_base_pointer __parent;
1552 __node_base_pointer& __child = __find_equal_key(__parent, __k);
Howard Hinnant72f73582010-08-11 17:04:31 +00001553#ifndef _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +00001554 if (__child == nullptr)
1555 throw out_of_range("map::at: key not found");
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001556#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001557 return static_cast<__node_pointer>(__child)->__value_.__cc.second;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001558}
1559
1560template <class _Key, class _Tp, class _Compare, class _Allocator>
1561const _Tp&
1562map<_Key, _Tp, _Compare, _Allocator>::at(const key_type& __k) const
1563{
1564 __node_base_const_pointer __parent;
1565 __node_base_const_pointer __child = __find_equal_key(__parent, __k);
Howard Hinnant72f73582010-08-11 17:04:31 +00001566#ifndef _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +00001567 if (__child == nullptr)
1568 throw out_of_range("map::at: key not found");
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001569#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001570 return static_cast<__node_const_pointer>(__child)->__value_.__cc.second;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001571}
1572
Howard Hinnant74279a52010-09-04 23:28:19 +00001573#if !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001574
1575template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001576template <class ..._Args>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001577pair<typename map<_Key, _Tp, _Compare, _Allocator>::iterator, bool>
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001578map<_Key, _Tp, _Compare, _Allocator>::emplace(_Args&& ...__args)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001579{
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001580 __node_holder __h = __construct_node(_VSTD::forward<_Args>(__args)...);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001581 pair<iterator, bool> __r = __tree_.__node_insert_unique(__h.get());
1582 if (__r.second)
1583 __h.release();
1584 return __r;
1585}
1586
1587template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001588template <class ..._Args>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001589typename map<_Key, _Tp, _Compare, _Allocator>::iterator
1590map<_Key, _Tp, _Compare, _Allocator>::emplace_hint(const_iterator __p,
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001591 _Args&& ...__args)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001592{
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001593 __node_holder __h = __construct_node(_VSTD::forward<_Args>(__args)...);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001594 iterator __r = __tree_.__node_insert_unique(__p.__i_, __h.get());
1595 if (__r.__i_.__ptr_ == __h.get())
1596 __h.release();
1597 return __r;
1598}
1599
Howard Hinnant74279a52010-09-04 23:28:19 +00001600#endif // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001601
1602template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001603inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001604bool
1605operator==(const map<_Key, _Tp, _Compare, _Allocator>& __x,
1606 const map<_Key, _Tp, _Compare, _Allocator>& __y)
1607{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001608 return __x.size() == __y.size() && _VSTD::equal(__x.begin(), __x.end(), __y.begin());
Howard Hinnantc51e1022010-05-11 19:42:16 +00001609}
1610
1611template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001612inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001613bool
1614operator< (const map<_Key, _Tp, _Compare, _Allocator>& __x,
1615 const map<_Key, _Tp, _Compare, _Allocator>& __y)
1616{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001617 return _VSTD::lexicographical_compare(__x.begin(), __x.end(), __y.begin(), __y.end());
Howard Hinnantc51e1022010-05-11 19:42:16 +00001618}
1619
1620template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001621inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001622bool
1623operator!=(const map<_Key, _Tp, _Compare, _Allocator>& __x,
1624 const map<_Key, _Tp, _Compare, _Allocator>& __y)
1625{
1626 return !(__x == __y);
1627}
1628
1629template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001630inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001631bool
1632operator> (const map<_Key, _Tp, _Compare, _Allocator>& __x,
1633 const map<_Key, _Tp, _Compare, _Allocator>& __y)
1634{
1635 return __y < __x;
1636}
1637
1638template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001639inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001640bool
1641operator>=(const map<_Key, _Tp, _Compare, _Allocator>& __x,
1642 const map<_Key, _Tp, _Compare, _Allocator>& __y)
1643{
1644 return !(__x < __y);
1645}
1646
1647template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001648inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001649bool
1650operator<=(const map<_Key, _Tp, _Compare, _Allocator>& __x,
1651 const map<_Key, _Tp, _Compare, _Allocator>& __y)
1652{
1653 return !(__y < __x);
1654}
1655
1656template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001657inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001658void
1659swap(map<_Key, _Tp, _Compare, _Allocator>& __x,
1660 map<_Key, _Tp, _Compare, _Allocator>& __y)
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001661 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
Howard Hinnantc51e1022010-05-11 19:42:16 +00001662{
1663 __x.swap(__y);
1664}
1665
1666template <class _Key, class _Tp, class _Compare = less<_Key>,
1667 class _Allocator = allocator<pair<const _Key, _Tp> > >
Howard Hinnanta37d3cf2013-08-12 18:38:34 +00001668class _LIBCPP_TYPE_VIS_ONLY multimap
Howard Hinnantc51e1022010-05-11 19:42:16 +00001669{
1670public:
1671 // types:
1672 typedef _Key key_type;
1673 typedef _Tp mapped_type;
1674 typedef pair<const key_type, mapped_type> value_type;
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001675 typedef pair<key_type, mapped_type> __nc_value_type;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001676 typedef _Compare key_compare;
1677 typedef _Allocator allocator_type;
1678 typedef value_type& reference;
1679 typedef const value_type& const_reference;
1680
Howard Hinnanta37d3cf2013-08-12 18:38:34 +00001681 class _LIBCPP_TYPE_VIS_ONLY value_compare
Howard Hinnantc51e1022010-05-11 19:42:16 +00001682 : public binary_function<value_type, value_type, bool>
1683 {
1684 friend class multimap;
1685 protected:
1686 key_compare comp;
1687
Howard Hinnant756c69b2010-09-22 16:48:34 +00001688 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001689 value_compare(key_compare c) : comp(c) {}
1690 public:
Howard Hinnant756c69b2010-09-22 16:48:34 +00001691 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001692 bool operator()(const value_type& __x, const value_type& __y) const
1693 {return comp(__x.first, __y.first);}
1694 };
1695
1696private:
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001697
Howard Hinnant89f8b792013-09-30 19:08:22 +00001698 typedef _VSTD::__value_type<key_type, mapped_type> __value_type;
Howard Hinnant90b91592013-07-05 18:06:00 +00001699 typedef __map_value_compare<key_type, __value_type, key_compare> __vc;
Marshall Clow940e01c2015-04-07 05:21:38 +00001700 typedef typename __rebind_alloc_helper<allocator_traits<allocator_type>,
1701 __value_type>::type __allocator_type;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001702 typedef __tree<__value_type, __vc, __allocator_type> __base;
1703 typedef typename __base::__node_traits __node_traits;
1704 typedef allocator_traits<allocator_type> __alloc_traits;
1705
1706 __base __tree_;
1707
1708public:
1709 typedef typename __alloc_traits::pointer pointer;
1710 typedef typename __alloc_traits::const_pointer const_pointer;
1711 typedef typename __alloc_traits::size_type size_type;
1712 typedef typename __alloc_traits::difference_type difference_type;
1713 typedef __map_iterator<typename __base::iterator> iterator;
1714 typedef __map_const_iterator<typename __base::const_iterator> const_iterator;
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001715 typedef _VSTD::reverse_iterator<iterator> reverse_iterator;
1716 typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001717
Howard Hinnant756c69b2010-09-22 16:48:34 +00001718 _LIBCPP_INLINE_VISIBILITY
Marshall Clow7086a5a2014-03-10 04:50:10 +00001719 multimap()
1720 _NOEXCEPT_(
1721 is_nothrow_default_constructible<allocator_type>::value &&
1722 is_nothrow_default_constructible<key_compare>::value &&
1723 is_nothrow_copy_constructible<key_compare>::value)
1724 : __tree_(__vc(key_compare())) {}
1725
1726 _LIBCPP_INLINE_VISIBILITY
1727 explicit multimap(const key_compare& __comp)
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001728 _NOEXCEPT_(
1729 is_nothrow_default_constructible<allocator_type>::value &&
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001730 is_nothrow_copy_constructible<key_compare>::value)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001731 : __tree_(__vc(__comp)) {}
1732
Howard Hinnant756c69b2010-09-22 16:48:34 +00001733 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001734 explicit multimap(const key_compare& __comp, const allocator_type& __a)
1735 : __tree_(__vc(__comp), __a) {}
1736
1737 template <class _InputIterator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001738 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001739 multimap(_InputIterator __f, _InputIterator __l,
1740 const key_compare& __comp = key_compare())
1741 : __tree_(__vc(__comp))
1742 {
1743 insert(__f, __l);
1744 }
1745
1746 template <class _InputIterator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001747 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001748 multimap(_InputIterator __f, _InputIterator __l,
1749 const key_compare& __comp, const allocator_type& __a)
1750 : __tree_(__vc(__comp), __a)
1751 {
1752 insert(__f, __l);
1753 }
1754
Marshall Clow300abfb2013-09-11 01:15:47 +00001755#if _LIBCPP_STD_VER > 11
1756 template <class _InputIterator>
1757 _LIBCPP_INLINE_VISIBILITY
1758 multimap(_InputIterator __f, _InputIterator __l, const allocator_type& __a)
1759 : multimap(__f, __l, key_compare(), __a) {}
1760#endif
1761
Howard Hinnant756c69b2010-09-22 16:48:34 +00001762 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001763 multimap(const multimap& __m)
1764 : __tree_(__m.__tree_.value_comp(),
1765 __alloc_traits::select_on_container_copy_construction(__m.__tree_.__alloc()))
1766 {
1767 insert(__m.begin(), __m.end());
1768 }
1769
Howard Hinnantd3a657f2011-07-01 19:24:36 +00001770 _LIBCPP_INLINE_VISIBILITY
1771 multimap& operator=(const multimap& __m)
1772 {
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001773#if __cplusplus >= 201103L
Howard Hinnantd3a657f2011-07-01 19:24:36 +00001774 __tree_ = __m.__tree_;
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001775#else
Marshall Clowdb3cfcb2014-02-08 04:03:14 +00001776 if (this != &__m) {
1777 __tree_.clear();
1778 __tree_.value_comp() = __m.__tree_.value_comp();
1779 __tree_.__copy_assign_alloc(__m.__tree_);
1780 insert(__m.begin(), __m.end());
1781 }
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001782#endif
Howard Hinnantd3a657f2011-07-01 19:24:36 +00001783 return *this;
1784 }
1785
Howard Hinnant74279a52010-09-04 23:28:19 +00001786#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +00001787
Howard Hinnant756c69b2010-09-22 16:48:34 +00001788 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001789 multimap(multimap&& __m)
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001790 _NOEXCEPT_(is_nothrow_move_constructible<__base>::value)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001791 : __tree_(_VSTD::move(__m.__tree_))
Howard Hinnantc51e1022010-05-11 19:42:16 +00001792 {
1793 }
1794
1795 multimap(multimap&& __m, const allocator_type& __a);
1796
Howard Hinnant756c69b2010-09-22 16:48:34 +00001797 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant33711792011-08-12 21:56:02 +00001798 multimap& operator=(multimap&& __m)
1799 _NOEXCEPT_(is_nothrow_move_assignable<__base>::value)
1800 {
1801 __tree_ = _VSTD::move(__m.__tree_);
1802 return *this;
1803 }
1804
1805#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
1806
1807#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1808
1809 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001810 multimap(initializer_list<value_type> __il, const key_compare& __comp = key_compare())
1811 : __tree_(__vc(__comp))
1812 {
1813 insert(__il.begin(), __il.end());
1814 }
1815
Howard Hinnant756c69b2010-09-22 16:48:34 +00001816 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001817 multimap(initializer_list<value_type> __il, const key_compare& __comp, const allocator_type& __a)
1818 : __tree_(__vc(__comp), __a)
1819 {
1820 insert(__il.begin(), __il.end());
1821 }
1822
Marshall Clow300abfb2013-09-11 01:15:47 +00001823#if _LIBCPP_STD_VER > 11
1824 _LIBCPP_INLINE_VISIBILITY
1825 multimap(initializer_list<value_type> __il, const allocator_type& __a)
1826 : multimap(__il, key_compare(), __a) {}
1827#endif
1828
Howard Hinnant756c69b2010-09-22 16:48:34 +00001829 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001830 multimap& operator=(initializer_list<value_type> __il)
1831 {
1832 __tree_.__assign_multi(__il.begin(), __il.end());
1833 return *this;
1834 }
Howard Hinnant33711792011-08-12 21:56:02 +00001835
1836#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantc51e1022010-05-11 19:42:16 +00001837
Howard Hinnant756c69b2010-09-22 16:48:34 +00001838 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001839 explicit multimap(const allocator_type& __a)
1840 : __tree_(__a)
1841 {
1842 }
1843
Howard Hinnant756c69b2010-09-22 16:48:34 +00001844 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001845 multimap(const multimap& __m, const allocator_type& __a)
1846 : __tree_(__m.__tree_.value_comp(), __a)
1847 {
1848 insert(__m.begin(), __m.end());
1849 }
1850
Howard Hinnant756c69b2010-09-22 16:48:34 +00001851 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001852 iterator begin() _NOEXCEPT {return __tree_.begin();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001853 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001854 const_iterator begin() const _NOEXCEPT {return __tree_.begin();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001855 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001856 iterator end() _NOEXCEPT {return __tree_.end();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001857 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001858 const_iterator end() const _NOEXCEPT {return __tree_.end();}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001859
Howard Hinnant756c69b2010-09-22 16:48:34 +00001860 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001861 reverse_iterator rbegin() _NOEXCEPT {return reverse_iterator(end());}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001862 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001863 const_reverse_iterator rbegin() const _NOEXCEPT
1864 {return const_reverse_iterator(end());}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001865 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001866 reverse_iterator rend() _NOEXCEPT {return reverse_iterator(begin());}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001867 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001868 const_reverse_iterator rend() const _NOEXCEPT
1869 {return const_reverse_iterator(begin());}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001870
Howard Hinnant756c69b2010-09-22 16:48:34 +00001871 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001872 const_iterator cbegin() const _NOEXCEPT {return begin();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001873 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001874 const_iterator cend() const _NOEXCEPT {return end();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001875 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001876 const_reverse_iterator crbegin() const _NOEXCEPT {return rbegin();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001877 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001878 const_reverse_iterator crend() const _NOEXCEPT {return rend();}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001879
Howard Hinnant756c69b2010-09-22 16:48:34 +00001880 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001881 bool empty() const _NOEXCEPT {return __tree_.size() == 0;}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001882 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001883 size_type size() const _NOEXCEPT {return __tree_.size();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001884 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001885 size_type max_size() const _NOEXCEPT {return __tree_.max_size();}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001886
Howard Hinnant756c69b2010-09-22 16:48:34 +00001887 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001888 allocator_type get_allocator() const _NOEXCEPT {return __tree_.__alloc();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001889 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001890 key_compare key_comp() const {return __tree_.value_comp().key_comp();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001891 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001892 value_compare value_comp() const
1893 {return value_compare(__tree_.value_comp().key_comp());}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001894
Howard Hinnant74279a52010-09-04 23:28:19 +00001895#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant74279a52010-09-04 23:28:19 +00001896#ifndef _LIBCPP_HAS_NO_VARIADICS
1897
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001898 template <class ..._Args>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001899 iterator
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001900 emplace(_Args&& ...__args);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001901
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001902 template <class ..._Args>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001903 iterator
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001904 emplace_hint(const_iterator __p, _Args&& ...__args);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001905
Howard Hinnant74279a52010-09-04 23:28:19 +00001906#endif // _LIBCPP_HAS_NO_VARIADICS
1907
Howard Hinnantc834c512011-11-29 18:15:50 +00001908 template <class _Pp,
1909 class = typename enable_if<is_constructible<value_type, _Pp>::value>::type>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001910 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc834c512011-11-29 18:15:50 +00001911 iterator insert(_Pp&& __p)
1912 {return __tree_.__insert_multi(_VSTD::forward<_Pp>(__p));}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001913
Howard Hinnantc834c512011-11-29 18:15:50 +00001914 template <class _Pp,
1915 class = typename enable_if<is_constructible<value_type, _Pp>::value>::type>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001916 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc834c512011-11-29 18:15:50 +00001917 iterator insert(const_iterator __pos, _Pp&& __p)
1918 {return __tree_.__insert_multi(__pos.__i_, _VSTD::forward<_Pp>(__p));}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001919
Howard Hinnant74279a52010-09-04 23:28:19 +00001920#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +00001921
Howard Hinnant756c69b2010-09-22 16:48:34 +00001922 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001923 iterator insert(const value_type& __v) {return __tree_.__insert_multi(__v);}
1924
Howard Hinnant756c69b2010-09-22 16:48:34 +00001925 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001926 iterator insert(const_iterator __p, const value_type& __v)
1927 {return __tree_.__insert_multi(__p.__i_, __v);}
1928
1929 template <class _InputIterator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001930 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001931 void insert(_InputIterator __f, _InputIterator __l)
1932 {
1933 for (const_iterator __e = cend(); __f != __l; ++__f)
1934 __tree_.__insert_multi(__e.__i_, *__f);
1935 }
1936
Howard Hinnant33711792011-08-12 21:56:02 +00001937#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1938
Howard Hinnant756c69b2010-09-22 16:48:34 +00001939 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001940 void insert(initializer_list<value_type> __il)
1941 {insert(__il.begin(), __il.end());}
1942
Howard Hinnant33711792011-08-12 21:56:02 +00001943#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1944
Howard Hinnant756c69b2010-09-22 16:48:34 +00001945 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001946 iterator erase(const_iterator __p) {return __tree_.erase(__p.__i_);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001947 _LIBCPP_INLINE_VISIBILITY
Marshall Clow22ea5b82015-05-10 13:35:00 +00001948 iterator erase(iterator __p) {return __tree_.erase(__p.__i_);}
1949 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001950 size_type erase(const key_type& __k) {return __tree_.__erase_multi(__k);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001951 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001952 iterator erase(const_iterator __f, const_iterator __l)
1953 {return __tree_.erase(__f.__i_, __l.__i_);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001954 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001955 void clear() {__tree_.clear();}
1956
Howard Hinnant756c69b2010-09-22 16:48:34 +00001957 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001958 void swap(multimap& __m)
1959 _NOEXCEPT_(__is_nothrow_swappable<__base>::value)
1960 {__tree_.swap(__m.__tree_);}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001961
Howard Hinnant756c69b2010-09-22 16:48:34 +00001962 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001963 iterator find(const key_type& __k) {return __tree_.find(__k);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001964 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001965 const_iterator find(const key_type& __k) const {return __tree_.find(__k);}
Marshall Clowebb57322013-08-13 22:18:47 +00001966#if _LIBCPP_STD_VER > 11
1967 template <typename _K2>
1968 _LIBCPP_INLINE_VISIBILITY
1969 typename enable_if<__is_transparent<_Compare, _K2>::value,iterator>::type
1970 find(const _K2& __k) {return __tree_.find(__k);}
1971 template <typename _K2>
1972 _LIBCPP_INLINE_VISIBILITY
1973 typename enable_if<__is_transparent<_Compare, _K2>::value,const_iterator>::type
1974 find(const _K2& __k) const {return __tree_.find(__k);}
1975#endif
1976
Howard Hinnant756c69b2010-09-22 16:48:34 +00001977 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001978 size_type count(const key_type& __k) const
1979 {return __tree_.__count_multi(__k);}
Marshall Clowe6a5f522014-08-24 23:54:16 +00001980#if _LIBCPP_STD_VER > 11
1981 template <typename _K2>
1982 _LIBCPP_INLINE_VISIBILITY
1983 typename enable_if<__is_transparent<_Compare, _K2>::value,size_type>::type
Marshall Clow141e47b2015-06-30 18:15:41 +00001984 count(const _K2& __k) const {return __tree_.__count_multi(__k);}
Marshall Clowe6a5f522014-08-24 23:54:16 +00001985#endif
Howard Hinnant756c69b2010-09-22 16:48:34 +00001986 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001987 iterator lower_bound(const key_type& __k)
1988 {return __tree_.lower_bound(__k);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001989 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001990 const_iterator lower_bound(const key_type& __k) const
1991 {return __tree_.lower_bound(__k);}
Marshall Clowebb57322013-08-13 22:18:47 +00001992#if _LIBCPP_STD_VER > 11
1993 template <typename _K2>
1994 _LIBCPP_INLINE_VISIBILITY
1995 typename enable_if<__is_transparent<_Compare, _K2>::value,iterator>::type
1996 lower_bound(const _K2& __k) {return __tree_.lower_bound(__k);}
1997
1998 template <typename _K2>
1999 _LIBCPP_INLINE_VISIBILITY
2000 typename enable_if<__is_transparent<_Compare, _K2>::value,const_iterator>::type
2001 lower_bound(const _K2& __k) const {return __tree_.lower_bound(__k);}
2002#endif
2003
Howard Hinnant756c69b2010-09-22 16:48:34 +00002004 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002005 iterator upper_bound(const key_type& __k)
2006 {return __tree_.upper_bound(__k);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00002007 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002008 const_iterator upper_bound(const key_type& __k) const
2009 {return __tree_.upper_bound(__k);}
Marshall Clowebb57322013-08-13 22:18:47 +00002010#if _LIBCPP_STD_VER > 11
2011 template <typename _K2>
2012 _LIBCPP_INLINE_VISIBILITY
2013 typename enable_if<__is_transparent<_Compare, _K2>::value,iterator>::type
2014 upper_bound(const _K2& __k) {return __tree_.upper_bound(__k);}
2015 template <typename _K2>
2016 _LIBCPP_INLINE_VISIBILITY
2017 typename enable_if<__is_transparent<_Compare, _K2>::value,const_iterator>::type
2018 upper_bound(const _K2& __k) const {return __tree_.upper_bound(__k);}
2019#endif
2020
Howard Hinnant756c69b2010-09-22 16:48:34 +00002021 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002022 pair<iterator,iterator> equal_range(const key_type& __k)
2023 {return __tree_.__equal_range_multi(__k);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00002024 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002025 pair<const_iterator,const_iterator> equal_range(const key_type& __k) const
2026 {return __tree_.__equal_range_multi(__k);}
Marshall Clowebb57322013-08-13 22:18:47 +00002027#if _LIBCPP_STD_VER > 11
2028 template <typename _K2>
2029 _LIBCPP_INLINE_VISIBILITY
2030 typename enable_if<__is_transparent<_Compare, _K2>::value,pair<iterator,iterator>>::type
2031 equal_range(const _K2& __k) {return __tree_.__equal_range_multi(__k);}
2032 template <typename _K2>
2033 _LIBCPP_INLINE_VISIBILITY
2034 typename enable_if<__is_transparent<_Compare, _K2>::value,pair<const_iterator,const_iterator>>::type
2035 equal_range(const _K2& __k) const {return __tree_.__equal_range_multi(__k);}
2036#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00002037
2038private:
2039 typedef typename __base::__node __node;
2040 typedef typename __base::__node_allocator __node_allocator;
2041 typedef typename __base::__node_pointer __node_pointer;
2042 typedef typename __base::__node_const_pointer __node_const_pointer;
Howard Hinnantc834c512011-11-29 18:15:50 +00002043 typedef __map_node_destructor<__node_allocator> _Dp;
2044 typedef unique_ptr<__node, _Dp> __node_holder;
Howard Hinnantc51e1022010-05-11 19:42:16 +00002045
Howard Hinnant74279a52010-09-04 23:28:19 +00002046#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +00002047 __node_holder __construct_node();
Howard Hinnant29eb9b82012-05-25 22:04:21 +00002048 template <class _A0>
Howard Hinnantac7e7482013-07-04 20:59:16 +00002049 __node_holder
Howard Hinnant29eb9b82012-05-25 22:04:21 +00002050 __construct_node(_A0&& __a0);
Howard Hinnant74279a52010-09-04 23:28:19 +00002051#ifndef _LIBCPP_HAS_NO_VARIADICS
Howard Hinnant29eb9b82012-05-25 22:04:21 +00002052 template <class _A0, class _A1, class ..._Args>
2053 __node_holder __construct_node(_A0&& __a0, _A1&& __a1, _Args&& ...__args);
Howard Hinnant74279a52010-09-04 23:28:19 +00002054#endif // _LIBCPP_HAS_NO_VARIADICS
2055#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +00002056};
2057
Howard Hinnant74279a52010-09-04 23:28:19 +00002058#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +00002059
2060template <class _Key, class _Tp, class _Compare, class _Allocator>
2061multimap<_Key, _Tp, _Compare, _Allocator>::multimap(multimap&& __m, const allocator_type& __a)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00002062 : __tree_(_VSTD::move(__m.__tree_), __a)
Howard Hinnantc51e1022010-05-11 19:42:16 +00002063{
2064 if (__a != __m.get_allocator())
2065 {
2066 const_iterator __e = cend();
2067 while (!__m.empty())
2068 __tree_.__insert_multi(__e.__i_,
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00002069 _VSTD::move(__m.__tree_.remove(__m.begin().__i_)->__value_));
Howard Hinnantc51e1022010-05-11 19:42:16 +00002070 }
2071}
2072
2073template <class _Key, class _Tp, class _Compare, class _Allocator>
2074typename multimap<_Key, _Tp, _Compare, _Allocator>::__node_holder
2075multimap<_Key, _Tp, _Compare, _Allocator>::__construct_node()
2076{
2077 __node_allocator& __na = __tree_.__node_alloc();
Howard Hinnantc834c512011-11-29 18:15:50 +00002078 __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
Howard Hinnant2d0046b2013-06-19 21:29:40 +00002079 __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__cc.first));
Howard Hinnantc51e1022010-05-11 19:42:16 +00002080 __h.get_deleter().__first_constructed = true;
Howard Hinnant2d0046b2013-06-19 21:29:40 +00002081 __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__cc.second));
Howard Hinnantc51e1022010-05-11 19:42:16 +00002082 __h.get_deleter().__second_constructed = true;
2083 return __h;
2084}
2085
2086template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant29eb9b82012-05-25 22:04:21 +00002087template <class _A0>
Howard Hinnantac7e7482013-07-04 20:59:16 +00002088typename multimap<_Key, _Tp, _Compare, _Allocator>::__node_holder
Howard Hinnantc51e1022010-05-11 19:42:16 +00002089multimap<_Key, _Tp, _Compare, _Allocator>::__construct_node(_A0&& __a0)
2090{
2091 __node_allocator& __na = __tree_.__node_alloc();
Howard Hinnantc834c512011-11-29 18:15:50 +00002092 __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00002093 __node_traits::construct(__na, _VSTD::addressof(__h->__value_), _VSTD::forward<_A0>(__a0));
Howard Hinnantc51e1022010-05-11 19:42:16 +00002094 __h.get_deleter().__first_constructed = true;
2095 __h.get_deleter().__second_constructed = true;
2096 return __h;
2097}
2098
Howard Hinnant29eb9b82012-05-25 22:04:21 +00002099#ifndef _LIBCPP_HAS_NO_VARIADICS
2100
2101template <class _Key, class _Tp, class _Compare, class _Allocator>
2102template <class _A0, class _A1, class ..._Args>
2103typename multimap<_Key, _Tp, _Compare, _Allocator>::__node_holder
2104multimap<_Key, _Tp, _Compare, _Allocator>::__construct_node(_A0&& __a0, _A1&& __a1, _Args&& ...__args)
2105{
2106 __node_allocator& __na = __tree_.__node_alloc();
2107 __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
2108 __node_traits::construct(__na, _VSTD::addressof(__h->__value_),
2109 _VSTD::forward<_A0>(__a0), _VSTD::forward<_A1>(__a1),
2110 _VSTD::forward<_Args>(__args)...);
2111 __h.get_deleter().__first_constructed = true;
Howard Hinnantc51e1022010-05-11 19:42:16 +00002112 __h.get_deleter().__second_constructed = true;
2113 return __h;
2114}
2115
Howard Hinnant74279a52010-09-04 23:28:19 +00002116#endif // _LIBCPP_HAS_NO_VARIADICS
2117#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +00002118
Howard Hinnant74279a52010-09-04 23:28:19 +00002119#if !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
Howard Hinnantc51e1022010-05-11 19:42:16 +00002120
2121template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant29eb9b82012-05-25 22:04:21 +00002122template <class ..._Args>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002123typename multimap<_Key, _Tp, _Compare, _Allocator>::iterator
Howard Hinnant29eb9b82012-05-25 22:04:21 +00002124multimap<_Key, _Tp, _Compare, _Allocator>::emplace(_Args&& ...__args)
Howard Hinnantc51e1022010-05-11 19:42:16 +00002125{
Howard Hinnant29eb9b82012-05-25 22:04:21 +00002126 __node_holder __h = __construct_node(_VSTD::forward<_Args>(__args)...);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002127 iterator __r = __tree_.__node_insert_multi(__h.get());
2128 __h.release();
2129 return __r;
2130}
2131
2132template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant29eb9b82012-05-25 22:04:21 +00002133template <class ..._Args>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002134typename multimap<_Key, _Tp, _Compare, _Allocator>::iterator
2135multimap<_Key, _Tp, _Compare, _Allocator>::emplace_hint(const_iterator __p,
Howard Hinnantc51e1022010-05-11 19:42:16 +00002136 _Args&& ...__args)
2137{
Howard Hinnant29eb9b82012-05-25 22:04:21 +00002138 __node_holder __h = __construct_node(_VSTD::forward<_Args>(__args)...);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002139 iterator __r = __tree_.__node_insert_multi(__p.__i_, __h.get());
2140 __h.release();
2141 return __r;
2142}
2143
Howard Hinnant74279a52010-09-04 23:28:19 +00002144#endif // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
Howard Hinnantc51e1022010-05-11 19:42:16 +00002145
2146template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00002147inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002148bool
2149operator==(const multimap<_Key, _Tp, _Compare, _Allocator>& __x,
2150 const multimap<_Key, _Tp, _Compare, _Allocator>& __y)
2151{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00002152 return __x.size() == __y.size() && _VSTD::equal(__x.begin(), __x.end(), __y.begin());
Howard Hinnantc51e1022010-05-11 19:42:16 +00002153}
2154
2155template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00002156inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002157bool
2158operator< (const multimap<_Key, _Tp, _Compare, _Allocator>& __x,
2159 const multimap<_Key, _Tp, _Compare, _Allocator>& __y)
2160{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00002161 return _VSTD::lexicographical_compare(__x.begin(), __x.end(), __y.begin(), __y.end());
Howard Hinnantc51e1022010-05-11 19:42:16 +00002162}
2163
2164template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00002165inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002166bool
2167operator!=(const multimap<_Key, _Tp, _Compare, _Allocator>& __x,
2168 const multimap<_Key, _Tp, _Compare, _Allocator>& __y)
2169{
2170 return !(__x == __y);
2171}
2172
2173template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00002174inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002175bool
2176operator> (const multimap<_Key, _Tp, _Compare, _Allocator>& __x,
2177 const multimap<_Key, _Tp, _Compare, _Allocator>& __y)
2178{
2179 return __y < __x;
2180}
2181
2182template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00002183inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002184bool
2185operator>=(const multimap<_Key, _Tp, _Compare, _Allocator>& __x,
2186 const multimap<_Key, _Tp, _Compare, _Allocator>& __y)
2187{
2188 return !(__x < __y);
2189}
2190
2191template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00002192inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002193bool
2194operator<=(const multimap<_Key, _Tp, _Compare, _Allocator>& __x,
2195 const multimap<_Key, _Tp, _Compare, _Allocator>& __y)
2196{
2197 return !(__y < __x);
2198}
2199
2200template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00002201inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002202void
2203swap(multimap<_Key, _Tp, _Compare, _Allocator>& __x,
2204 multimap<_Key, _Tp, _Compare, _Allocator>& __y)
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00002205 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
Howard Hinnantc51e1022010-05-11 19:42:16 +00002206{
2207 __x.swap(__y);
2208}
2209
2210_LIBCPP_END_NAMESPACE_STD
2211
2212#endif // _LIBCPP_MAP