blob: 2416205d6f0fbef5b9a23514cbf44da9022f8a52 [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)
Marshall Clow8982dcd2015-07-13 20:04:56 +0000162 noexcept(allocator_traits<allocator_type>::is_always_equal::value &&
163 __is_nothrow_swappable<key_compare>::value); // C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000164
165 // observers:
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000166 allocator_type get_allocator() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000167 key_compare key_comp() const;
168 value_compare value_comp() const;
169
170 // map operations:
171 iterator find(const key_type& k);
172 const_iterator find(const key_type& k) const;
Marshall Clowebb57322013-08-13 22:18:47 +0000173 template<typename K>
174 iterator find(const K& x); // C++14
175 template<typename K>
176 const_iterator find(const K& x) const; // C++14
177 template<typename K>
Marshall Clowe6a5f522014-08-24 23:54:16 +0000178 size_type count(const K& x) const; // C++14
Marshall Clowebb57322013-08-13 22:18:47 +0000179
Howard Hinnantc51e1022010-05-11 19:42:16 +0000180 size_type count(const key_type& k) const;
181 iterator lower_bound(const key_type& k);
182 const_iterator lower_bound(const key_type& k) const;
Marshall Clowebb57322013-08-13 22:18:47 +0000183 template<typename K>
184 iterator lower_bound(const K& x); // C++14
185 template<typename K>
186 const_iterator lower_bound(const K& x) const; // C++14
187
Howard Hinnantc51e1022010-05-11 19:42:16 +0000188 iterator upper_bound(const key_type& k);
189 const_iterator upper_bound(const key_type& k) const;
Marshall Clowebb57322013-08-13 22:18:47 +0000190 template<typename K>
191 iterator upper_bound(const K& x); // C++14
192 template<typename K>
193 const_iterator upper_bound(const K& x) const; // C++14
194
Howard Hinnantc51e1022010-05-11 19:42:16 +0000195 pair<iterator,iterator> equal_range(const key_type& k);
196 pair<const_iterator,const_iterator> equal_range(const key_type& k) const;
Marshall Clowebb57322013-08-13 22:18:47 +0000197 template<typename K>
198 pair<iterator,iterator> equal_range(const K& x); // C++14
199 template<typename K>
200 pair<const_iterator,const_iterator> equal_range(const K& x) const; // C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000201};
202
203template <class Key, class T, class Compare, class Allocator>
204bool
205operator==(const map<Key, T, Compare, Allocator>& x,
206 const map<Key, T, Compare, Allocator>& y);
207
208template <class Key, class T, class Compare, class Allocator>
209bool
210operator< (const map<Key, T, Compare, Allocator>& x,
211 const map<Key, T, Compare, Allocator>& y);
212
213template <class Key, class T, class Compare, class Allocator>
214bool
215operator!=(const map<Key, T, Compare, Allocator>& x,
216 const map<Key, T, Compare, Allocator>& y);
217
218template <class Key, class T, class Compare, class Allocator>
219bool
220operator> (const map<Key, T, Compare, Allocator>& x,
221 const map<Key, T, Compare, Allocator>& y);
222
223template <class Key, class T, class Compare, class Allocator>
224bool
225operator>=(const map<Key, T, Compare, Allocator>& x,
226 const map<Key, T, Compare, Allocator>& y);
227
228template <class Key, class T, class Compare, class Allocator>
229bool
230operator<=(const map<Key, T, Compare, Allocator>& x,
231 const map<Key, T, Compare, Allocator>& y);
232
233// specialized algorithms:
234template <class Key, class T, class Compare, class Allocator>
235void
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000236swap(map<Key, T, Compare, Allocator>& x, map<Key, T, Compare, Allocator>& y)
237 noexcept(noexcept(x.swap(y)));
Howard Hinnantc51e1022010-05-11 19:42:16 +0000238
239template <class Key, class T, class Compare = less<Key>,
240 class Allocator = allocator<pair<const Key, T>>>
241class multimap
242{
243public:
244 // types:
245 typedef Key key_type;
246 typedef T mapped_type;
247 typedef pair<const key_type,mapped_type> value_type;
248 typedef Compare key_compare;
249 typedef Allocator allocator_type;
250 typedef typename allocator_type::reference reference;
251 typedef typename allocator_type::const_reference const_reference;
252 typedef typename allocator_type::size_type size_type;
253 typedef typename allocator_type::difference_type difference_type;
254 typedef typename allocator_type::pointer pointer;
255 typedef typename allocator_type::const_pointer const_pointer;
256
257 typedef implementation-defined iterator;
258 typedef implementation-defined const_iterator;
259 typedef std::reverse_iterator<iterator> reverse_iterator;
260 typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
261
262 class value_compare
263 : public binary_function<value_type,value_type,bool>
264 {
265 friend class multimap;
266 protected:
267 key_compare comp;
268 value_compare(key_compare c);
269 public:
270 bool operator()(const value_type& x, const value_type& y) const;
271 };
272
273 // construct/copy/destroy:
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000274 multimap()
275 noexcept(
276 is_nothrow_default_constructible<allocator_type>::value &&
277 is_nothrow_default_constructible<key_compare>::value &&
278 is_nothrow_copy_constructible<key_compare>::value);
279 explicit multimap(const key_compare& comp);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000280 multimap(const key_compare& comp, const allocator_type& a);
281 template <class InputIterator>
282 multimap(InputIterator first, InputIterator last, const key_compare& comp);
283 template <class InputIterator>
284 multimap(InputIterator first, InputIterator last, const key_compare& comp,
285 const allocator_type& a);
286 multimap(const multimap& m);
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000287 multimap(multimap&& m)
288 noexcept(
289 is_nothrow_move_constructible<allocator_type>::value &&
290 is_nothrow_move_constructible<key_compare>::value);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000291 explicit multimap(const allocator_type& a);
292 multimap(const multimap& m, const allocator_type& a);
293 multimap(multimap&& m, const allocator_type& a);
294 multimap(initializer_list<value_type> il, const key_compare& comp = key_compare());
295 multimap(initializer_list<value_type> il, const key_compare& comp,
296 const allocator_type& a);
Marshall Clow300abfb2013-09-11 01:15:47 +0000297 template <class InputIterator>
298 multimap(InputIterator first, InputIterator last, const allocator_type& a)
299 : multimap(first, last, Compare(), a) {} // C++14
300 multimap(initializer_list<value_type> il, const allocator_type& a)
301 : multimap(il, Compare(), a) {} // C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000302 ~multimap();
303
304 multimap& operator=(const multimap& m);
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000305 multimap& operator=(multimap&& m)
306 noexcept(
307 allocator_type::propagate_on_container_move_assignment::value &&
308 is_nothrow_move_assignable<allocator_type>::value &&
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000309 is_nothrow_move_assignable<key_compare>::value);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000310 multimap& operator=(initializer_list<value_type> il);
311
312 // iterators:
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000313 iterator begin() noexcept;
314 const_iterator begin() const noexcept;
315 iterator end() noexcept;
316 const_iterator end() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000317
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000318 reverse_iterator rbegin() noexcept;
319 const_reverse_iterator rbegin() const noexcept;
320 reverse_iterator rend() noexcept;
321 const_reverse_iterator rend() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000322
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000323 const_iterator cbegin() const noexcept;
324 const_iterator cend() const noexcept;
325 const_reverse_iterator crbegin() const noexcept;
326 const_reverse_iterator crend() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000327
328 // capacity:
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000329 bool empty() const noexcept;
330 size_type size() const noexcept;
331 size_type max_size() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000332
333 // modifiers:
334 template <class... Args>
335 iterator emplace(Args&&... args);
336 template <class... Args>
337 iterator emplace_hint(const_iterator position, Args&&... args);
338 iterator insert(const value_type& v);
339 template <class P>
340 iterator insert(P&& p);
341 iterator insert(const_iterator position, const value_type& v);
342 template <class P>
343 iterator insert(const_iterator position, P&& p);
344 template <class InputIterator>
345 void insert(InputIterator first, InputIterator last);
346 void insert(initializer_list<value_type> il);
347
348 iterator erase(const_iterator position);
Marshall Clow22ea5b82015-05-10 13:35:00 +0000349 iterator erase(iterator position); // C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000350 size_type erase(const key_type& k);
351 iterator erase(const_iterator first, const_iterator last);
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000352 void clear() noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000353
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000354 void swap(multimap& m)
Marshall Clow8982dcd2015-07-13 20:04:56 +0000355 noexcept(allocator_traits<allocator_type>::is_always_equal::value &&
356 __is_nothrow_swappable<key_compare>::value); // C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000357
358 // observers:
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000359 allocator_type get_allocator() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000360 key_compare key_comp() const;
361 value_compare value_comp() const;
362
363 // map operations:
364 iterator find(const key_type& k);
365 const_iterator find(const key_type& k) const;
Marshall Clowebb57322013-08-13 22:18:47 +0000366 template<typename K>
367 iterator find(const K& x); // C++14
368 template<typename K>
369 const_iterator find(const K& x) const; // C++14
370 template<typename K>
Marshall Clowe6a5f522014-08-24 23:54:16 +0000371 size_type count(const K& x) const; // C++14
Marshall Clowebb57322013-08-13 22:18:47 +0000372
Howard Hinnantc51e1022010-05-11 19:42:16 +0000373 size_type count(const key_type& k) const;
374 iterator lower_bound(const key_type& k);
375 const_iterator lower_bound(const key_type& k) const;
Marshall Clowebb57322013-08-13 22:18:47 +0000376 template<typename K>
377 iterator lower_bound(const K& x); // C++14
378 template<typename K>
379 const_iterator lower_bound(const K& x) const; // C++14
380
Howard Hinnantc51e1022010-05-11 19:42:16 +0000381 iterator upper_bound(const key_type& k);
382 const_iterator upper_bound(const key_type& k) const;
Marshall Clowebb57322013-08-13 22:18:47 +0000383 template<typename K>
384 iterator upper_bound(const K& x); // C++14
385 template<typename K>
386 const_iterator upper_bound(const K& x) const; // C++14
387
Howard Hinnantc51e1022010-05-11 19:42:16 +0000388 pair<iterator,iterator> equal_range(const key_type& k);
389 pair<const_iterator,const_iterator> equal_range(const key_type& k) const;
Marshall Clowebb57322013-08-13 22:18:47 +0000390 template<typename K>
391 pair<iterator,iterator> equal_range(const K& x); // C++14
392 template<typename K>
393 pair<const_iterator,const_iterator> equal_range(const K& x) const; // C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000394};
395
396template <class Key, class T, class Compare, class Allocator>
397bool
398operator==(const multimap<Key, T, Compare, Allocator>& x,
399 const multimap<Key, T, Compare, Allocator>& y);
400
401template <class Key, class T, class Compare, class Allocator>
402bool
403operator< (const multimap<Key, T, Compare, Allocator>& x,
404 const multimap<Key, T, Compare, Allocator>& y);
405
406template <class Key, class T, class Compare, class Allocator>
407bool
408operator!=(const multimap<Key, T, Compare, Allocator>& x,
409 const multimap<Key, T, Compare, Allocator>& y);
410
411template <class Key, class T, class Compare, class Allocator>
412bool
413operator> (const multimap<Key, T, Compare, Allocator>& x,
414 const multimap<Key, T, Compare, Allocator>& y);
415
416template <class Key, class T, class Compare, class Allocator>
417bool
418operator>=(const multimap<Key, T, Compare, Allocator>& x,
419 const multimap<Key, T, Compare, Allocator>& y);
420
421template <class Key, class T, class Compare, class Allocator>
422bool
423operator<=(const multimap<Key, T, Compare, Allocator>& x,
424 const multimap<Key, T, Compare, Allocator>& y);
425
426// specialized algorithms:
427template <class Key, class T, class Compare, class Allocator>
428void
429swap(multimap<Key, T, Compare, Allocator>& x,
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000430 multimap<Key, T, Compare, Allocator>& y)
431 noexcept(noexcept(x.swap(y)));
Howard Hinnantc51e1022010-05-11 19:42:16 +0000432
433} // std
434
435*/
436
437#include <__config>
438#include <__tree>
439#include <iterator>
440#include <memory>
441#include <utility>
442#include <functional>
443#include <initializer_list>
Eric Fiselierf7394302015-06-13 07:08:02 +0000444#include <type_traits>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000445
Howard Hinnantaaaa52b2011-10-17 20:05:10 +0000446#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000447#pragma GCC system_header
Howard Hinnantaaaa52b2011-10-17 20:05:10 +0000448#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000449
450_LIBCPP_BEGIN_NAMESPACE_STD
451
Eric Fiselierf7394302015-06-13 07:08:02 +0000452template <class _Key, class _CP, class _Compare,
453 bool = is_empty<_Compare>::value && !__libcpp_is_final<_Compare>::value
Howard Hinnantd0aabf82011-12-11 20:31:33 +0000454 >
Howard Hinnantc51e1022010-05-11 19:42:16 +0000455class __map_value_compare
456 : private _Compare
457{
Howard Hinnantc51e1022010-05-11 19:42:16 +0000458public:
Howard Hinnant756c69b2010-09-22 16:48:34 +0000459 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000460 __map_value_compare()
461 _NOEXCEPT_(is_nothrow_default_constructible<_Compare>::value)
462 : _Compare() {}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000463 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000464 __map_value_compare(_Compare c)
465 _NOEXCEPT_(is_nothrow_copy_constructible<_Compare>::value)
466 : _Compare(c) {}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000467 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000468 const _Compare& key_comp() const _NOEXCEPT {return *this;}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000469 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000470 bool operator()(const _CP& __x, const _CP& __y) const
Howard Hinnant90b91592013-07-05 18:06:00 +0000471 {return static_cast<const _Compare&>(*this)(__x.__cc.first, __y.__cc.first);}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000472 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000473 bool operator()(const _CP& __x, const _Key& __y) const
Howard Hinnant90b91592013-07-05 18:06:00 +0000474 {return static_cast<const _Compare&>(*this)(__x.__cc.first, __y);}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000475 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000476 bool operator()(const _Key& __x, const _CP& __y) const
Howard Hinnant90b91592013-07-05 18:06:00 +0000477 {return static_cast<const _Compare&>(*this)(__x, __y.__cc.first);}
Marshall Clow8982dcd2015-07-13 20:04:56 +0000478 void swap(__map_value_compare&__y)
479 _NOEXCEPT_(__is_nothrow_swappable<_Compare>::value)
480 {
481 using _VSTD::swap;
482 swap(static_cast<const _Compare&>(*this), static_cast<const _Compare&>(__y));
483 }
Marshall Clowebb57322013-08-13 22:18:47 +0000484
485#if _LIBCPP_STD_VER > 11
486 template <typename _K2>
487 _LIBCPP_INLINE_VISIBILITY
488 typename enable_if<__is_transparent<_Compare, _K2>::value, bool>::type
489 operator () ( const _K2& __x, const _CP& __y ) const
490 {return static_cast<const _Compare&>(*this) (__x, __y.__cc.first);}
491
492 template <typename _K2>
493 _LIBCPP_INLINE_VISIBILITY
494 typename enable_if<__is_transparent<_Compare, _K2>::value, bool>::type
495 operator () (const _CP& __x, const _K2& __y) const
496 {return static_cast<const _Compare&>(*this) (__x.__cc.first, __y);}
497#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000498};
499
Howard Hinnant90b91592013-07-05 18:06:00 +0000500template <class _Key, class _CP, class _Compare>
501class __map_value_compare<_Key, _CP, _Compare, false>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000502{
503 _Compare comp;
504
Howard Hinnantc51e1022010-05-11 19:42:16 +0000505public:
Howard Hinnant756c69b2010-09-22 16:48:34 +0000506 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000507 __map_value_compare()
508 _NOEXCEPT_(is_nothrow_default_constructible<_Compare>::value)
509 : comp() {}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000510 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000511 __map_value_compare(_Compare c)
512 _NOEXCEPT_(is_nothrow_copy_constructible<_Compare>::value)
513 : comp(c) {}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000514 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000515 const _Compare& key_comp() const _NOEXCEPT {return comp;}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000516
Howard Hinnant756c69b2010-09-22 16:48:34 +0000517 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000518 bool operator()(const _CP& __x, const _CP& __y) const
Howard Hinnant90b91592013-07-05 18:06:00 +0000519 {return comp(__x.__cc.first, __y.__cc.first);}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000520 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000521 bool operator()(const _CP& __x, const _Key& __y) const
Howard Hinnant90b91592013-07-05 18:06:00 +0000522 {return comp(__x.__cc.first, __y);}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000523 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000524 bool operator()(const _Key& __x, const _CP& __y) const
Howard Hinnant90b91592013-07-05 18:06:00 +0000525 {return comp(__x, __y.__cc.first);}
Marshall Clow8982dcd2015-07-13 20:04:56 +0000526 void swap(__map_value_compare&__y)
527 _NOEXCEPT_(__is_nothrow_swappable<_Compare>::value)
528 {
529 using _VSTD::swap;
530 swap(comp, __y.comp);
531 }
532
Marshall Clowebb57322013-08-13 22:18:47 +0000533#if _LIBCPP_STD_VER > 11
534 template <typename _K2>
535 _LIBCPP_INLINE_VISIBILITY
536 typename enable_if<__is_transparent<_Compare, _K2>::value, bool>::type
537 operator () ( const _K2& __x, const _CP& __y ) const
538 {return comp (__x, __y.__cc.first);}
539
540 template <typename _K2>
541 _LIBCPP_INLINE_VISIBILITY
542 typename enable_if<__is_transparent<_Compare, _K2>::value, bool>::type
543 operator () (const _CP& __x, const _K2& __y) const
544 {return comp (__x.__cc.first, __y);}
545#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000546};
547
Marshall Clow8982dcd2015-07-13 20:04:56 +0000548template <class _Key, class _CP, class _Compare, bool __b>
549inline _LIBCPP_INLINE_VISIBILITY
550void
551swap(__map_value_compare<_Key, _CP, _Compare, __b>& __x,
552 __map_value_compare<_Key, _CP, _Compare, __b>& __y)
553 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
554{
555 __x.swap(__y);
556}
557
Howard Hinnantc51e1022010-05-11 19:42:16 +0000558template <class _Allocator>
559class __map_node_destructor
560{
561 typedef _Allocator allocator_type;
562 typedef allocator_traits<allocator_type> __alloc_traits;
563 typedef typename __alloc_traits::value_type::value_type value_type;
564public:
565 typedef typename __alloc_traits::pointer pointer;
566private:
Howard Hinnant2d0046b2013-06-19 21:29:40 +0000567 typedef typename value_type::value_type::first_type first_type;
568 typedef typename value_type::value_type::second_type second_type;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000569
570 allocator_type& __na_;
571
572 __map_node_destructor& operator=(const __map_node_destructor&);
573
574public:
575 bool __first_constructed;
576 bool __second_constructed;
577
Howard Hinnant756c69b2010-09-22 16:48:34 +0000578 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000579 explicit __map_node_destructor(allocator_type& __na) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +0000580 : __na_(__na),
581 __first_constructed(false),
582 __second_constructed(false)
583 {}
584
Howard Hinnant74279a52010-09-04 23:28:19 +0000585#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant756c69b2010-09-22 16:48:34 +0000586 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000587 __map_node_destructor(__tree_node_destructor<allocator_type>&& __x) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +0000588 : __na_(__x.__na_),
589 __first_constructed(__x.__value_constructed),
590 __second_constructed(__x.__value_constructed)
591 {
592 __x.__value_constructed = false;
593 }
Howard Hinnant5dc89112010-09-04 23:46:48 +0000594#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +0000595
Howard Hinnant756c69b2010-09-22 16:48:34 +0000596 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000597 void operator()(pointer __p) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +0000598 {
599 if (__second_constructed)
Howard Hinnant2d0046b2013-06-19 21:29:40 +0000600 __alloc_traits::destroy(__na_, _VSTD::addressof(__p->__value_.__cc.second));
Howard Hinnantc51e1022010-05-11 19:42:16 +0000601 if (__first_constructed)
Howard Hinnant2d0046b2013-06-19 21:29:40 +0000602 __alloc_traits::destroy(__na_, _VSTD::addressof(__p->__value_.__cc.first));
Howard Hinnantc51e1022010-05-11 19:42:16 +0000603 if (__p)
604 __alloc_traits::deallocate(__na_, __p, 1);
605 }
606};
607
Howard Hinnant944510a2011-06-14 19:58:17 +0000608template <class _Key, class _Tp, class _Compare, class _Allocator>
609 class map;
610template <class _Key, class _Tp, class _Compare, class _Allocator>
611 class multimap;
612template <class _TreeIterator> class __map_const_iterator;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000613
Howard Hinnant89f8b792013-09-30 19:08:22 +0000614#if __cplusplus >= 201103L
615
616template <class _Key, class _Tp>
617union __value_type
618{
619 typedef _Key key_type;
620 typedef _Tp mapped_type;
621 typedef pair<const key_type, mapped_type> value_type;
622 typedef pair<key_type, mapped_type> __nc_value_type;
623
624 value_type __cc;
625 __nc_value_type __nc;
626
627 template <class ..._Args>
628 _LIBCPP_INLINE_VISIBILITY
629 __value_type(_Args&& ...__args)
630 : __cc(std::forward<_Args>(__args)...) {}
631
632 _LIBCPP_INLINE_VISIBILITY
633 __value_type(const __value_type& __v)
634 : __cc(__v.__cc) {}
635
636 _LIBCPP_INLINE_VISIBILITY
637 __value_type(__value_type& __v)
638 : __cc(__v.__cc) {}
639
640 _LIBCPP_INLINE_VISIBILITY
641 __value_type(__value_type&& __v)
642 : __nc(std::move(__v.__nc)) {}
643
644 _LIBCPP_INLINE_VISIBILITY
645 __value_type& operator=(const __value_type& __v)
646 {__nc = __v.__cc; return *this;}
647
648 _LIBCPP_INLINE_VISIBILITY
649 __value_type& operator=(__value_type&& __v)
650 {__nc = std::move(__v.__nc); return *this;}
651
652 _LIBCPP_INLINE_VISIBILITY
653 ~__value_type() {__cc.~value_type();}
654};
655
656#else
657
658template <class _Key, class _Tp>
659struct __value_type
660{
661 typedef _Key key_type;
662 typedef _Tp mapped_type;
663 typedef pair<const key_type, mapped_type> value_type;
664
665 value_type __cc;
666
667 _LIBCPP_INLINE_VISIBILITY
668 __value_type() {}
669
670 template <class _A0>
671 _LIBCPP_INLINE_VISIBILITY
672 __value_type(const _A0& __a0)
673 : __cc(__a0) {}
674
675 template <class _A0, class _A1>
676 _LIBCPP_INLINE_VISIBILITY
677 __value_type(const _A0& __a0, const _A1& __a1)
678 : __cc(__a0, __a1) {}
679};
680
681#endif
682
Eric Fiselier44f9fd02015-03-03 20:10:01 +0000683template <class _Tp>
684struct __extract_key_value_types;
685
686template <class _Key, class _Tp>
687struct __extract_key_value_types<__value_type<_Key, _Tp> >
688{
689 typedef _Key const __key_type;
690 typedef _Tp __mapped_type;
691};
692
Howard Hinnantc51e1022010-05-11 19:42:16 +0000693template <class _TreeIterator>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +0000694class _LIBCPP_TYPE_VIS_ONLY __map_iterator
Howard Hinnantc51e1022010-05-11 19:42:16 +0000695{
696 _TreeIterator __i_;
697
698 typedef typename _TreeIterator::__pointer_traits __pointer_traits;
Eric Fiselier44f9fd02015-03-03 20:10:01 +0000699 typedef typename _TreeIterator::value_type __value_type;
700 typedef typename __extract_key_value_types<__value_type>::__key_type __key_type;
701 typedef typename __extract_key_value_types<__value_type>::__mapped_type __mapped_type;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000702public:
703 typedef bidirectional_iterator_tag iterator_category;
Howard Hinnantb2e8a422011-02-27 18:02:02 +0000704 typedef pair<__key_type, __mapped_type> value_type;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000705 typedef typename _TreeIterator::difference_type difference_type;
706 typedef value_type& reference;
Eric Fiselier660c6b02015-12-30 21:52:00 +0000707 typedef typename __rebind_pointer<typename __pointer_traits::pointer, value_type>::type
708 pointer;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000709
Howard Hinnant756c69b2010-09-22 16:48:34 +0000710 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000711 __map_iterator() _NOEXCEPT {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000712
Howard Hinnant756c69b2010-09-22 16:48:34 +0000713 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000714 __map_iterator(_TreeIterator __i) _NOEXCEPT : __i_(__i) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000715
Howard Hinnant756c69b2010-09-22 16:48:34 +0000716 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2d0046b2013-06-19 21:29:40 +0000717 reference operator*() const {return __i_->__cc;}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000718 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2d0046b2013-06-19 21:29:40 +0000719 pointer operator->() const {return pointer_traits<pointer>::pointer_to(__i_->__cc);}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000720
Howard Hinnant756c69b2010-09-22 16:48:34 +0000721 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000722 __map_iterator& operator++() {++__i_; return *this;}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000723 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000724 __map_iterator operator++(int)
725 {
726 __map_iterator __t(*this);
727 ++(*this);
728 return __t;
729 }
730
Howard Hinnant756c69b2010-09-22 16:48:34 +0000731 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000732 __map_iterator& operator--() {--__i_; return *this;}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000733 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000734 __map_iterator operator--(int)
735 {
736 __map_iterator __t(*this);
737 --(*this);
738 return __t;
739 }
740
Howard Hinnant756c69b2010-09-22 16:48:34 +0000741 friend _LIBCPP_INLINE_VISIBILITY
742 bool operator==(const __map_iterator& __x, const __map_iterator& __y)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000743 {return __x.__i_ == __y.__i_;}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000744 friend
745 _LIBCPP_INLINE_VISIBILITY
746 bool operator!=(const __map_iterator& __x, const __map_iterator& __y)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000747 {return __x.__i_ != __y.__i_;}
748
Howard Hinnanta37d3cf2013-08-12 18:38:34 +0000749 template <class, class, class, class> friend class _LIBCPP_TYPE_VIS_ONLY map;
750 template <class, class, class, class> friend class _LIBCPP_TYPE_VIS_ONLY multimap;
751 template <class> friend class _LIBCPP_TYPE_VIS_ONLY __map_const_iterator;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000752};
753
754template <class _TreeIterator>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +0000755class _LIBCPP_TYPE_VIS_ONLY __map_const_iterator
Howard Hinnantc51e1022010-05-11 19:42:16 +0000756{
757 _TreeIterator __i_;
758
759 typedef typename _TreeIterator::__pointer_traits __pointer_traits;
Eric Fiselier44f9fd02015-03-03 20:10:01 +0000760 typedef typename _TreeIterator::value_type __value_type;
761 typedef typename __extract_key_value_types<__value_type>::__key_type __key_type;
762 typedef typename __extract_key_value_types<__value_type>::__mapped_type __mapped_type;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000763public:
764 typedef bidirectional_iterator_tag iterator_category;
Howard Hinnantb2e8a422011-02-27 18:02:02 +0000765 typedef pair<__key_type, __mapped_type> value_type;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000766 typedef typename _TreeIterator::difference_type difference_type;
767 typedef const value_type& reference;
Eric Fiselier660c6b02015-12-30 21:52:00 +0000768 typedef typename __rebind_pointer<typename __pointer_traits::pointer, const value_type>::type
769 pointer;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000770
Howard Hinnant756c69b2010-09-22 16:48:34 +0000771 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000772 __map_const_iterator() _NOEXCEPT {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000773
Howard Hinnant756c69b2010-09-22 16:48:34 +0000774 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000775 __map_const_iterator(_TreeIterator __i) _NOEXCEPT : __i_(__i) {}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000776 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier44f9fd02015-03-03 20:10:01 +0000777 __map_const_iterator(__map_iterator<
778 typename _TreeIterator::__non_const_iterator> __i) _NOEXCEPT
779 : __i_(__i.__i_) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000780
Howard Hinnant756c69b2010-09-22 16:48:34 +0000781 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2d0046b2013-06-19 21:29:40 +0000782 reference operator*() const {return __i_->__cc;}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000783 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2d0046b2013-06-19 21:29:40 +0000784 pointer operator->() const {return pointer_traits<pointer>::pointer_to(__i_->__cc);}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000785
Howard Hinnant756c69b2010-09-22 16:48:34 +0000786 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000787 __map_const_iterator& operator++() {++__i_; return *this;}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000788 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000789 __map_const_iterator operator++(int)
790 {
791 __map_const_iterator __t(*this);
792 ++(*this);
793 return __t;
794 }
795
Howard Hinnant756c69b2010-09-22 16:48:34 +0000796 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000797 __map_const_iterator& operator--() {--__i_; return *this;}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000798 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000799 __map_const_iterator operator--(int)
800 {
801 __map_const_iterator __t(*this);
802 --(*this);
803 return __t;
804 }
805
Howard Hinnant756c69b2010-09-22 16:48:34 +0000806 friend _LIBCPP_INLINE_VISIBILITY
807 bool operator==(const __map_const_iterator& __x, const __map_const_iterator& __y)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000808 {return __x.__i_ == __y.__i_;}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000809 friend _LIBCPP_INLINE_VISIBILITY
810 bool operator!=(const __map_const_iterator& __x, const __map_const_iterator& __y)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000811 {return __x.__i_ != __y.__i_;}
812
Howard Hinnanta37d3cf2013-08-12 18:38:34 +0000813 template <class, class, class, class> friend class _LIBCPP_TYPE_VIS_ONLY map;
814 template <class, class, class, class> friend class _LIBCPP_TYPE_VIS_ONLY multimap;
815 template <class, class, class> friend class _LIBCPP_TYPE_VIS_ONLY __tree_const_iterator;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000816};
817
818template <class _Key, class _Tp, class _Compare = less<_Key>,
819 class _Allocator = allocator<pair<const _Key, _Tp> > >
Howard Hinnanta37d3cf2013-08-12 18:38:34 +0000820class _LIBCPP_TYPE_VIS_ONLY map
Howard Hinnantc51e1022010-05-11 19:42:16 +0000821{
822public:
823 // types:
824 typedef _Key key_type;
825 typedef _Tp mapped_type;
826 typedef pair<const key_type, mapped_type> value_type;
Howard Hinnant2d0046b2013-06-19 21:29:40 +0000827 typedef pair<key_type, mapped_type> __nc_value_type;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000828 typedef _Compare key_compare;
829 typedef _Allocator allocator_type;
830 typedef value_type& reference;
831 typedef const value_type& const_reference;
832
Marshall Clow5128cf32015-11-26 01:24:04 +0000833 static_assert((is_same<typename allocator_type::value_type, value_type>::value),
834 "Allocator::value_type must be same type as value_type");
835
Howard Hinnanta37d3cf2013-08-12 18:38:34 +0000836 class _LIBCPP_TYPE_VIS_ONLY value_compare
Howard Hinnantc51e1022010-05-11 19:42:16 +0000837 : public binary_function<value_type, value_type, bool>
838 {
839 friend class map;
840 protected:
841 key_compare comp;
842
Howard Hinnant756c69b2010-09-22 16:48:34 +0000843 _LIBCPP_INLINE_VISIBILITY value_compare(key_compare c) : comp(c) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000844 public:
Howard Hinnant756c69b2010-09-22 16:48:34 +0000845 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000846 bool operator()(const value_type& __x, const value_type& __y) const
847 {return comp(__x.first, __y.first);}
848 };
849
850private:
Howard Hinnant2d0046b2013-06-19 21:29:40 +0000851
Howard Hinnant89f8b792013-09-30 19:08:22 +0000852 typedef _VSTD::__value_type<key_type, mapped_type> __value_type;
Howard Hinnant90b91592013-07-05 18:06:00 +0000853 typedef __map_value_compare<key_type, __value_type, key_compare> __vc;
Marshall Clow940e01c2015-04-07 05:21:38 +0000854 typedef typename __rebind_alloc_helper<allocator_traits<allocator_type>,
855 __value_type>::type __allocator_type;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000856 typedef __tree<__value_type, __vc, __allocator_type> __base;
857 typedef typename __base::__node_traits __node_traits;
858 typedef allocator_traits<allocator_type> __alloc_traits;
859
860 __base __tree_;
861
862public:
863 typedef typename __alloc_traits::pointer pointer;
864 typedef typename __alloc_traits::const_pointer const_pointer;
865 typedef typename __alloc_traits::size_type size_type;
866 typedef typename __alloc_traits::difference_type difference_type;
Eric Fiselier44f9fd02015-03-03 20:10:01 +0000867 typedef __map_iterator<typename __base::iterator> iterator;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000868 typedef __map_const_iterator<typename __base::const_iterator> const_iterator;
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000869 typedef _VSTD::reverse_iterator<iterator> reverse_iterator;
870 typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000871
Howard Hinnant756c69b2010-09-22 16:48:34 +0000872 _LIBCPP_INLINE_VISIBILITY
Marshall Clow7086a5a2014-03-10 04:50:10 +0000873 map()
874 _NOEXCEPT_(
875 is_nothrow_default_constructible<allocator_type>::value &&
876 is_nothrow_default_constructible<key_compare>::value &&
877 is_nothrow_copy_constructible<key_compare>::value)
878 : __tree_(__vc(key_compare())) {}
879
880 _LIBCPP_INLINE_VISIBILITY
881 explicit map(const key_compare& __comp)
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000882 _NOEXCEPT_(
883 is_nothrow_default_constructible<allocator_type>::value &&
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000884 is_nothrow_copy_constructible<key_compare>::value)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000885 : __tree_(__vc(__comp)) {}
886
Howard Hinnant756c69b2010-09-22 16:48:34 +0000887 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000888 explicit map(const key_compare& __comp, const allocator_type& __a)
889 : __tree_(__vc(__comp), __a) {}
890
891 template <class _InputIterator>
Howard Hinnant756c69b2010-09-22 16:48:34 +0000892 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000893 map(_InputIterator __f, _InputIterator __l,
894 const key_compare& __comp = key_compare())
895 : __tree_(__vc(__comp))
896 {
897 insert(__f, __l);
898 }
899
900 template <class _InputIterator>
Howard Hinnant756c69b2010-09-22 16:48:34 +0000901 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000902 map(_InputIterator __f, _InputIterator __l,
903 const key_compare& __comp, const allocator_type& __a)
904 : __tree_(__vc(__comp), __a)
905 {
906 insert(__f, __l);
907 }
908
Marshall Clow300abfb2013-09-11 01:15:47 +0000909#if _LIBCPP_STD_VER > 11
910 template <class _InputIterator>
911 _LIBCPP_INLINE_VISIBILITY
912 map(_InputIterator __f, _InputIterator __l, const allocator_type& __a)
913 : map(__f, __l, key_compare(), __a) {}
914#endif
915
Howard Hinnant756c69b2010-09-22 16:48:34 +0000916 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000917 map(const map& __m)
918 : __tree_(__m.__tree_)
919 {
920 insert(__m.begin(), __m.end());
921 }
922
Howard Hinnantd3a657f2011-07-01 19:24:36 +0000923 _LIBCPP_INLINE_VISIBILITY
924 map& operator=(const map& __m)
925 {
Howard Hinnant2d0046b2013-06-19 21:29:40 +0000926#if __cplusplus >= 201103L
Howard Hinnantd3a657f2011-07-01 19:24:36 +0000927 __tree_ = __m.__tree_;
Howard Hinnant2d0046b2013-06-19 21:29:40 +0000928#else
Marshall Clowdb3cfcb2014-02-08 04:03:14 +0000929 if (this != &__m) {
930 __tree_.clear();
931 __tree_.value_comp() = __m.__tree_.value_comp();
932 __tree_.__copy_assign_alloc(__m.__tree_);
933 insert(__m.begin(), __m.end());
934 }
Howard Hinnant2d0046b2013-06-19 21:29:40 +0000935#endif
Howard Hinnantd3a657f2011-07-01 19:24:36 +0000936 return *this;
937 }
938
Howard Hinnant74279a52010-09-04 23:28:19 +0000939#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +0000940
Howard Hinnant756c69b2010-09-22 16:48:34 +0000941 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000942 map(map&& __m)
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000943 _NOEXCEPT_(is_nothrow_move_constructible<__base>::value)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000944 : __tree_(_VSTD::move(__m.__tree_))
Howard Hinnantc51e1022010-05-11 19:42:16 +0000945 {
946 }
947
948 map(map&& __m, const allocator_type& __a);
949
Howard Hinnant756c69b2010-09-22 16:48:34 +0000950 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant33711792011-08-12 21:56:02 +0000951 map& operator=(map&& __m)
952 _NOEXCEPT_(is_nothrow_move_assignable<__base>::value)
953 {
954 __tree_ = _VSTD::move(__m.__tree_);
955 return *this;
956 }
957
958#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
959
960#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
961
962 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000963 map(initializer_list<value_type> __il, const key_compare& __comp = key_compare())
964 : __tree_(__vc(__comp))
965 {
966 insert(__il.begin(), __il.end());
967 }
968
Howard Hinnant756c69b2010-09-22 16:48:34 +0000969 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000970 map(initializer_list<value_type> __il, const key_compare& __comp, const allocator_type& __a)
971 : __tree_(__vc(__comp), __a)
972 {
973 insert(__il.begin(), __il.end());
974 }
975
Marshall Clow300abfb2013-09-11 01:15:47 +0000976#if _LIBCPP_STD_VER > 11
977 _LIBCPP_INLINE_VISIBILITY
978 map(initializer_list<value_type> __il, const allocator_type& __a)
979 : map(__il, key_compare(), __a) {}
980#endif
981
Howard Hinnant756c69b2010-09-22 16:48:34 +0000982 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000983 map& operator=(initializer_list<value_type> __il)
984 {
985 __tree_.__assign_unique(__il.begin(), __il.end());
986 return *this;
987 }
988
Howard Hinnant33711792011-08-12 21:56:02 +0000989#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000990
Howard Hinnant756c69b2010-09-22 16:48:34 +0000991 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000992 explicit map(const allocator_type& __a)
993 : __tree_(__a)
994 {
995 }
996
Howard Hinnant756c69b2010-09-22 16:48:34 +0000997 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000998 map(const map& __m, const allocator_type& __a)
999 : __tree_(__m.__tree_.value_comp(), __a)
1000 {
1001 insert(__m.begin(), __m.end());
1002 }
1003
Howard Hinnant756c69b2010-09-22 16:48:34 +00001004 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001005 iterator begin() _NOEXCEPT {return __tree_.begin();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001006 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001007 const_iterator begin() const _NOEXCEPT {return __tree_.begin();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001008 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001009 iterator end() _NOEXCEPT {return __tree_.end();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001010 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001011 const_iterator end() const _NOEXCEPT {return __tree_.end();}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001012
Howard Hinnant756c69b2010-09-22 16:48:34 +00001013 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001014 reverse_iterator rbegin() _NOEXCEPT {return reverse_iterator(end());}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001015 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001016 const_reverse_iterator rbegin() const _NOEXCEPT
1017 {return const_reverse_iterator(end());}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001018 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001019 reverse_iterator rend() _NOEXCEPT
1020 {return reverse_iterator(begin());}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001021 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001022 const_reverse_iterator rend() const _NOEXCEPT
1023 {return const_reverse_iterator(begin());}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001024
Howard Hinnant756c69b2010-09-22 16:48:34 +00001025 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001026 const_iterator cbegin() const _NOEXCEPT {return begin();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001027 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001028 const_iterator cend() const _NOEXCEPT {return end();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001029 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001030 const_reverse_iterator crbegin() const _NOEXCEPT {return rbegin();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001031 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001032 const_reverse_iterator crend() const _NOEXCEPT {return rend();}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001033
Howard Hinnant756c69b2010-09-22 16:48:34 +00001034 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001035 bool empty() const _NOEXCEPT {return __tree_.size() == 0;}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001036 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001037 size_type size() const _NOEXCEPT {return __tree_.size();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001038 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001039 size_type max_size() const _NOEXCEPT {return __tree_.max_size();}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001040
1041 mapped_type& operator[](const key_type& __k);
Howard Hinnant74279a52010-09-04 23:28:19 +00001042#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +00001043 mapped_type& operator[](key_type&& __k);
1044#endif
1045
1046 mapped_type& at(const key_type& __k);
1047 const mapped_type& at(const key_type& __k) const;
1048
Howard Hinnant756c69b2010-09-22 16:48:34 +00001049 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001050 allocator_type get_allocator() const _NOEXCEPT {return __tree_.__alloc();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001051 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001052 key_compare key_comp() const {return __tree_.value_comp().key_comp();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001053 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001054 value_compare value_comp() const {return value_compare(__tree_.value_comp().key_comp());}
1055
Howard Hinnant74279a52010-09-04 23:28:19 +00001056#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant74279a52010-09-04 23:28:19 +00001057#ifndef _LIBCPP_HAS_NO_VARIADICS
1058
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001059 template <class ..._Args>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001060 pair<iterator, bool>
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001061 emplace(_Args&& ...__args);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001062
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001063 template <class ..._Args>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001064 iterator
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001065 emplace_hint(const_iterator __p, _Args&& ...__args);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001066
Howard Hinnant74279a52010-09-04 23:28:19 +00001067#endif // _LIBCPP_HAS_NO_VARIADICS
1068
Howard Hinnantc834c512011-11-29 18:15:50 +00001069 template <class _Pp,
1070 class = typename enable_if<is_constructible<value_type, _Pp>::value>::type>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001071 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc834c512011-11-29 18:15:50 +00001072 pair<iterator, bool> insert(_Pp&& __p)
1073 {return __tree_.__insert_unique(_VSTD::forward<_Pp>(__p));}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001074
Howard Hinnantc834c512011-11-29 18:15:50 +00001075 template <class _Pp,
1076 class = typename enable_if<is_constructible<value_type, _Pp>::value>::type>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001077 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc834c512011-11-29 18:15:50 +00001078 iterator insert(const_iterator __pos, _Pp&& __p)
1079 {return __tree_.__insert_unique(__pos.__i_, _VSTD::forward<_Pp>(__p));}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001080
Howard Hinnant74279a52010-09-04 23:28:19 +00001081#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +00001082
Howard Hinnant756c69b2010-09-22 16:48:34 +00001083 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001084 pair<iterator, bool>
1085 insert(const value_type& __v) {return __tree_.__insert_unique(__v);}
1086
Howard Hinnant756c69b2010-09-22 16:48:34 +00001087 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001088 iterator
1089 insert(const_iterator __p, const value_type& __v)
1090 {return __tree_.__insert_unique(__p.__i_, __v);}
1091
1092 template <class _InputIterator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001093 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001094 void insert(_InputIterator __f, _InputIterator __l)
1095 {
1096 for (const_iterator __e = cend(); __f != __l; ++__f)
1097 insert(__e.__i_, *__f);
1098 }
1099
Howard Hinnant33711792011-08-12 21:56:02 +00001100#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1101
Howard Hinnant756c69b2010-09-22 16:48:34 +00001102 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001103 void insert(initializer_list<value_type> __il)
1104 {insert(__il.begin(), __il.end());}
1105
Howard Hinnant33711792011-08-12 21:56:02 +00001106#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1107
Marshall Clow3223db82015-07-07 03:37:33 +00001108#if _LIBCPP_STD_VER > 14
1109#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
1110#ifndef _LIBCPP_HAS_NO_VARIADICS
1111 template <class... _Args>
1112 _LIBCPP_INLINE_VISIBILITY
1113 pair<iterator, bool> try_emplace(const key_type& __k, _Args&&... __args)
1114 {
1115 iterator __p = lower_bound(__k);
1116 if ( __p != end() && !key_comp()(__k, __p->first))
1117 return _VSTD::make_pair(__p, false);
1118 else
1119 return _VSTD::make_pair(
1120 emplace_hint(__p,
1121 _VSTD::piecewise_construct, _VSTD::forward_as_tuple(__k),
1122 _VSTD::forward_as_tuple(_VSTD::forward<_Args>(__args)...)),
1123 true);
1124 }
1125
1126 template <class... _Args>
1127 _LIBCPP_INLINE_VISIBILITY
1128 pair<iterator, bool> try_emplace(key_type&& __k, _Args&&... __args)
1129 {
1130 iterator __p = lower_bound(__k);
1131 if ( __p != end() && !key_comp()(__k, __p->first))
1132 return _VSTD::make_pair(__p, false);
1133 else
1134 return _VSTD::make_pair(
1135 emplace_hint(__p,
1136 _VSTD::piecewise_construct, _VSTD::forward_as_tuple(_VSTD::move(__k)),
1137 _VSTD::forward_as_tuple(_VSTD::forward<_Args>(__args)...)),
1138 true);
1139 }
1140
1141 template <class... _Args>
1142 _LIBCPP_INLINE_VISIBILITY
1143 iterator try_emplace(const_iterator __h, const key_type& __k, _Args&&... __args)
1144 {
1145 iterator __p = lower_bound(__k);
1146 if ( __p != end() && !key_comp()(__k, __p->first))
1147 return __p;
1148 else
1149 return emplace_hint(__p,
1150 _VSTD::piecewise_construct, _VSTD::forward_as_tuple(__k),
1151 _VSTD::forward_as_tuple(_VSTD::forward<_Args>(__args)...));
1152 }
1153
1154 template <class... _Args>
1155 _LIBCPP_INLINE_VISIBILITY
1156 iterator try_emplace(const_iterator __h, key_type&& __k, _Args&&... __args)
1157 {
1158 iterator __p = lower_bound(__k);
1159 if ( __p != end() && !key_comp()(__k, __p->first))
1160 return __p;
1161 else
1162 return emplace_hint(__p,
1163 _VSTD::piecewise_construct, _VSTD::forward_as_tuple(_VSTD::move(__k)),
1164 _VSTD::forward_as_tuple(_VSTD::forward<_Args>(__args)...));
1165 }
1166
1167 template <class _Vp>
1168 _LIBCPP_INLINE_VISIBILITY
1169 pair<iterator, bool> insert_or_assign(const key_type& __k, _Vp&& __v)
1170 {
1171 iterator __p = lower_bound(__k);
1172 if ( __p != end() && !key_comp()(__k, __p->first))
1173 {
1174 __p->second = _VSTD::forward<_Vp>(__v);
1175 return _VSTD::make_pair(__p, false);
1176 }
1177 return _VSTD::make_pair(emplace_hint(__p, __k, _VSTD::forward<_Vp>(__v)), true);
1178 }
1179
1180 template <class _Vp>
1181 _LIBCPP_INLINE_VISIBILITY
1182 pair<iterator, bool> insert_or_assign(key_type&& __k, _Vp&& __v)
1183 {
1184 iterator __p = lower_bound(__k);
1185 if ( __p != end() && !key_comp()(__k, __p->first))
1186 {
1187 __p->second = _VSTD::forward<_Vp>(__v);
1188 return _VSTD::make_pair(__p, false);
1189 }
1190 return _VSTD::make_pair(emplace_hint(__p, _VSTD::move(__k), _VSTD::forward<_Vp>(__v)), true);
1191 }
1192
1193 template <class _Vp>
1194 _LIBCPP_INLINE_VISIBILITY
1195 iterator insert_or_assign(const_iterator __h, const key_type& __k, _Vp&& __v)
1196 {
1197 iterator __p = lower_bound(__k);
1198 if ( __p != end() && !key_comp()(__k, __p->first))
1199 {
1200 __p->second = _VSTD::forward<_Vp>(__v);
1201 return __p;
1202 }
1203 return emplace_hint(__h, __k, _VSTD::forward<_Vp>(__v));
1204 }
1205
1206 template <class _Vp>
1207 _LIBCPP_INLINE_VISIBILITY
1208 iterator insert_or_assign(const_iterator __h, key_type&& __k, _Vp&& __v)
1209 {
1210 iterator __p = lower_bound(__k);
1211 if ( __p != end() && !key_comp()(__k, __p->first))
1212 {
1213 __p->second = _VSTD::forward<_Vp>(__v);
1214 return __p;
1215 }
1216 return emplace_hint(__h, _VSTD::move(__k), _VSTD::forward<_Vp>(__v));
1217 }
1218#endif
1219#endif
1220#endif
1221
Howard Hinnant756c69b2010-09-22 16:48:34 +00001222 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001223 iterator erase(const_iterator __p) {return __tree_.erase(__p.__i_);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001224 _LIBCPP_INLINE_VISIBILITY
Marshall Clow22ea5b82015-05-10 13:35:00 +00001225 iterator erase(iterator __p) {return __tree_.erase(__p.__i_);}
1226 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001227 size_type erase(const key_type& __k)
1228 {return __tree_.__erase_unique(__k);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001229 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001230 iterator erase(const_iterator __f, const_iterator __l)
1231 {return __tree_.erase(__f.__i_, __l.__i_);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001232 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001233 void clear() _NOEXCEPT {__tree_.clear();}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001234
Howard Hinnant756c69b2010-09-22 16:48:34 +00001235 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001236 void swap(map& __m)
1237 _NOEXCEPT_(__is_nothrow_swappable<__base>::value)
1238 {__tree_.swap(__m.__tree_);}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001239
Howard Hinnant756c69b2010-09-22 16:48:34 +00001240 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001241 iterator find(const key_type& __k) {return __tree_.find(__k);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001242 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001243 const_iterator find(const key_type& __k) const {return __tree_.find(__k);}
Marshall Clowebb57322013-08-13 22:18:47 +00001244#if _LIBCPP_STD_VER > 11
1245 template <typename _K2>
1246 _LIBCPP_INLINE_VISIBILITY
1247 typename enable_if<__is_transparent<_Compare, _K2>::value,iterator>::type
1248 find(const _K2& __k) {return __tree_.find(__k);}
1249 template <typename _K2>
1250 _LIBCPP_INLINE_VISIBILITY
1251 typename enable_if<__is_transparent<_Compare, _K2>::value,const_iterator>::type
1252 find(const _K2& __k) const {return __tree_.find(__k);}
1253#endif
1254
Howard Hinnant756c69b2010-09-22 16:48:34 +00001255 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001256 size_type count(const key_type& __k) const
1257 {return __tree_.__count_unique(__k);}
Marshall Clowe6a5f522014-08-24 23:54:16 +00001258#if _LIBCPP_STD_VER > 11
1259 template <typename _K2>
1260 _LIBCPP_INLINE_VISIBILITY
1261 typename enable_if<__is_transparent<_Compare, _K2>::value,size_type>::type
Marshall Clow141e47b2015-06-30 18:15:41 +00001262 count(const _K2& __k) const {return __tree_.__count_unique(__k);}
Marshall Clowe6a5f522014-08-24 23:54:16 +00001263#endif
Howard Hinnant756c69b2010-09-22 16:48:34 +00001264 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001265 iterator lower_bound(const key_type& __k)
1266 {return __tree_.lower_bound(__k);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001267 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001268 const_iterator lower_bound(const key_type& __k) const
1269 {return __tree_.lower_bound(__k);}
Marshall Clowebb57322013-08-13 22:18:47 +00001270#if _LIBCPP_STD_VER > 11
1271 template <typename _K2>
1272 _LIBCPP_INLINE_VISIBILITY
1273 typename enable_if<__is_transparent<_Compare, _K2>::value,iterator>::type
1274 lower_bound(const _K2& __k) {return __tree_.lower_bound(__k);}
1275
1276 template <typename _K2>
1277 _LIBCPP_INLINE_VISIBILITY
1278 typename enable_if<__is_transparent<_Compare, _K2>::value,const_iterator>::type
1279 lower_bound(const _K2& __k) const {return __tree_.lower_bound(__k);}
1280#endif
1281
Howard Hinnant756c69b2010-09-22 16:48:34 +00001282 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001283 iterator upper_bound(const key_type& __k)
1284 {return __tree_.upper_bound(__k);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001285 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001286 const_iterator upper_bound(const key_type& __k) const
1287 {return __tree_.upper_bound(__k);}
Marshall Clowebb57322013-08-13 22:18:47 +00001288#if _LIBCPP_STD_VER > 11
1289 template <typename _K2>
1290 _LIBCPP_INLINE_VISIBILITY
1291 typename enable_if<__is_transparent<_Compare, _K2>::value,iterator>::type
1292 upper_bound(const _K2& __k) {return __tree_.upper_bound(__k);}
1293 template <typename _K2>
1294 _LIBCPP_INLINE_VISIBILITY
1295 typename enable_if<__is_transparent<_Compare, _K2>::value,const_iterator>::type
1296 upper_bound(const _K2& __k) const {return __tree_.upper_bound(__k);}
1297#endif
1298
Howard Hinnant756c69b2010-09-22 16:48:34 +00001299 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001300 pair<iterator,iterator> equal_range(const key_type& __k)
1301 {return __tree_.__equal_range_unique(__k);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001302 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001303 pair<const_iterator,const_iterator> equal_range(const key_type& __k) const
1304 {return __tree_.__equal_range_unique(__k);}
Marshall Clowebb57322013-08-13 22:18:47 +00001305#if _LIBCPP_STD_VER > 11
1306 template <typename _K2>
1307 _LIBCPP_INLINE_VISIBILITY
1308 typename enable_if<__is_transparent<_Compare, _K2>::value,pair<iterator,iterator>>::type
1309 equal_range(const _K2& __k) {return __tree_.__equal_range_unique(__k);}
1310 template <typename _K2>
1311 _LIBCPP_INLINE_VISIBILITY
1312 typename enable_if<__is_transparent<_Compare, _K2>::value,pair<const_iterator,const_iterator>>::type
1313 equal_range(const _K2& __k) const {return __tree_.__equal_range_unique(__k);}
1314#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001315
1316private:
1317 typedef typename __base::__node __node;
1318 typedef typename __base::__node_allocator __node_allocator;
1319 typedef typename __base::__node_pointer __node_pointer;
1320 typedef typename __base::__node_const_pointer __node_const_pointer;
1321 typedef typename __base::__node_base_pointer __node_base_pointer;
1322 typedef typename __base::__node_base_const_pointer __node_base_const_pointer;
Howard Hinnantc834c512011-11-29 18:15:50 +00001323 typedef __map_node_destructor<__node_allocator> _Dp;
1324 typedef unique_ptr<__node, _Dp> __node_holder;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001325
Howard Hinnant74279a52010-09-04 23:28:19 +00001326#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +00001327 __node_holder __construct_node();
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001328 template <class _A0>
Howard Hinnantac7e7482013-07-04 20:59:16 +00001329 __node_holder __construct_node(_A0&& __a0);
1330 __node_holder __construct_node_with_key(key_type&& __k);
Howard Hinnant74279a52010-09-04 23:28:19 +00001331#ifndef _LIBCPP_HAS_NO_VARIADICS
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001332 template <class _A0, class _A1, class ..._Args>
1333 __node_holder __construct_node(_A0&& __a0, _A1&& __a1, _Args&& ...__args);
Howard Hinnant74279a52010-09-04 23:28:19 +00001334#endif // _LIBCPP_HAS_NO_VARIADICS
Howard Hinnantc51e1022010-05-11 19:42:16 +00001335#endif
Howard Hinnantac7e7482013-07-04 20:59:16 +00001336 __node_holder __construct_node_with_key(const key_type& __k);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001337
1338 __node_base_pointer&
1339 __find_equal_key(__node_base_pointer& __parent, const key_type& __k);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001340 __node_base_const_pointer
1341 __find_equal_key(__node_base_const_pointer& __parent, const key_type& __k) const;
1342};
1343
1344// Find place to insert if __k doesn't exist
1345// Set __parent to parent of null leaf
1346// Return reference to null leaf
1347// If __k exists, set parent to node of __k and return reference to node of __k
1348template <class _Key, class _Tp, class _Compare, class _Allocator>
1349typename map<_Key, _Tp, _Compare, _Allocator>::__node_base_pointer&
1350map<_Key, _Tp, _Compare, _Allocator>::__find_equal_key(__node_base_pointer& __parent,
1351 const key_type& __k)
1352{
1353 __node_pointer __nd = __tree_.__root();
1354 if (__nd != nullptr)
1355 {
1356 while (true)
1357 {
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001358 if (__tree_.value_comp().key_comp()(__k, __nd->__value_.__cc.first))
Howard Hinnantc51e1022010-05-11 19:42:16 +00001359 {
1360 if (__nd->__left_ != nullptr)
1361 __nd = static_cast<__node_pointer>(__nd->__left_);
1362 else
1363 {
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001364 __parent = static_cast<__node_base_pointer>(__nd);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001365 return __parent->__left_;
1366 }
1367 }
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001368 else if (__tree_.value_comp().key_comp()(__nd->__value_.__cc.first, __k))
Howard Hinnantc51e1022010-05-11 19:42:16 +00001369 {
1370 if (__nd->__right_ != nullptr)
1371 __nd = static_cast<__node_pointer>(__nd->__right_);
1372 else
1373 {
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001374 __parent = static_cast<__node_base_pointer>(__nd);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001375 return __parent->__right_;
1376 }
1377 }
1378 else
1379 {
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001380 __parent = static_cast<__node_base_pointer>(__nd);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001381 return __parent;
1382 }
1383 }
1384 }
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001385 __parent = static_cast<__node_base_pointer>(__tree_.__end_node());
Howard Hinnantc51e1022010-05-11 19:42:16 +00001386 return __parent->__left_;
1387}
1388
Howard Hinnantc51e1022010-05-11 19:42:16 +00001389// Find __k
1390// Set __parent to parent of null leaf and
1391// return reference to null leaf iv __k does not exist.
1392// If __k exists, set parent to node of __k and return reference to node of __k
1393template <class _Key, class _Tp, class _Compare, class _Allocator>
1394typename map<_Key, _Tp, _Compare, _Allocator>::__node_base_const_pointer
1395map<_Key, _Tp, _Compare, _Allocator>::__find_equal_key(__node_base_const_pointer& __parent,
1396 const key_type& __k) const
1397{
1398 __node_const_pointer __nd = __tree_.__root();
1399 if (__nd != nullptr)
1400 {
1401 while (true)
1402 {
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001403 if (__tree_.value_comp().key_comp()(__k, __nd->__value_.__cc.first))
Howard Hinnantc51e1022010-05-11 19:42:16 +00001404 {
1405 if (__nd->__left_ != nullptr)
1406 __nd = static_cast<__node_pointer>(__nd->__left_);
1407 else
1408 {
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001409 __parent = static_cast<__node_base_pointer>(__nd);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001410 return const_cast<const __node_base_const_pointer&>(__parent->__left_);
1411 }
1412 }
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001413 else if (__tree_.value_comp().key_comp()(__nd->__value_.__cc.first, __k))
Howard Hinnantc51e1022010-05-11 19:42:16 +00001414 {
1415 if (__nd->__right_ != nullptr)
1416 __nd = static_cast<__node_pointer>(__nd->__right_);
1417 else
1418 {
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001419 __parent = static_cast<__node_base_pointer>(__nd);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001420 return const_cast<const __node_base_const_pointer&>(__parent->__right_);
1421 }
1422 }
1423 else
1424 {
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001425 __parent = static_cast<__node_base_pointer>(__nd);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001426 return __parent;
1427 }
1428 }
1429 }
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001430 __parent = static_cast<__node_base_pointer>(__tree_.__end_node());
Howard Hinnantc51e1022010-05-11 19:42:16 +00001431 return const_cast<const __node_base_const_pointer&>(__parent->__left_);
1432}
1433
Howard Hinnant74279a52010-09-04 23:28:19 +00001434#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +00001435
1436template <class _Key, class _Tp, class _Compare, class _Allocator>
1437map<_Key, _Tp, _Compare, _Allocator>::map(map&& __m, const allocator_type& __a)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001438 : __tree_(_VSTD::move(__m.__tree_), __a)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001439{
1440 if (__a != __m.get_allocator())
1441 {
1442 const_iterator __e = cend();
1443 while (!__m.empty())
1444 __tree_.__insert_unique(__e.__i_,
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001445 _VSTD::move(__m.__tree_.remove(__m.begin().__i_)->__value_));
Howard Hinnantc51e1022010-05-11 19:42:16 +00001446 }
1447}
1448
1449template <class _Key, class _Tp, class _Compare, class _Allocator>
1450typename map<_Key, _Tp, _Compare, _Allocator>::__node_holder
1451map<_Key, _Tp, _Compare, _Allocator>::__construct_node()
1452{
1453 __node_allocator& __na = __tree_.__node_alloc();
Howard Hinnantc834c512011-11-29 18:15:50 +00001454 __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001455 __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__cc.first));
Howard Hinnantc51e1022010-05-11 19:42:16 +00001456 __h.get_deleter().__first_constructed = true;
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001457 __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__cc.second));
Howard Hinnantc51e1022010-05-11 19:42:16 +00001458 __h.get_deleter().__second_constructed = true;
1459 return __h;
1460}
1461
1462template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001463template <class _A0>
Howard Hinnantac7e7482013-07-04 20:59:16 +00001464typename map<_Key, _Tp, _Compare, _Allocator>::__node_holder
Howard Hinnantc51e1022010-05-11 19:42:16 +00001465map<_Key, _Tp, _Compare, _Allocator>::__construct_node(_A0&& __a0)
1466{
1467 __node_allocator& __na = __tree_.__node_alloc();
Howard Hinnantc834c512011-11-29 18:15:50 +00001468 __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001469 __node_traits::construct(__na, _VSTD::addressof(__h->__value_), _VSTD::forward<_A0>(__a0));
Howard Hinnantc51e1022010-05-11 19:42:16 +00001470 __h.get_deleter().__first_constructed = true;
1471 __h.get_deleter().__second_constructed = true;
1472 return __h;
1473}
1474
1475template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnantac7e7482013-07-04 20:59:16 +00001476typename map<_Key, _Tp, _Compare, _Allocator>::__node_holder
1477map<_Key, _Tp, _Compare, _Allocator>::__construct_node_with_key(key_type&& __k)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001478{
1479 __node_allocator& __na = __tree_.__node_alloc();
Howard Hinnantc834c512011-11-29 18:15:50 +00001480 __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
Howard Hinnantac7e7482013-07-04 20:59:16 +00001481 __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__cc.first), _VSTD::move(__k));
Howard Hinnantc51e1022010-05-11 19:42:16 +00001482 __h.get_deleter().__first_constructed = true;
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001483 __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__cc.second));
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001484 __h.get_deleter().__second_constructed = true;
Howard Hinnanta31e9682013-08-22 18:29:50 +00001485 return __h;
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001486}
1487
1488#ifndef _LIBCPP_HAS_NO_VARIADICS
1489
1490template <class _Key, class _Tp, class _Compare, class _Allocator>
1491template <class _A0, class _A1, class ..._Args>
1492typename map<_Key, _Tp, _Compare, _Allocator>::__node_holder
1493map<_Key, _Tp, _Compare, _Allocator>::__construct_node(_A0&& __a0, _A1&& __a1, _Args&& ...__args)
1494{
1495 __node_allocator& __na = __tree_.__node_alloc();
1496 __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
1497 __node_traits::construct(__na, _VSTD::addressof(__h->__value_),
1498 _VSTD::forward<_A0>(__a0), _VSTD::forward<_A1>(__a1),
1499 _VSTD::forward<_Args>(__args)...);
1500 __h.get_deleter().__first_constructed = true;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001501 __h.get_deleter().__second_constructed = true;
1502 return __h;
1503}
1504
Howard Hinnant74279a52010-09-04 23:28:19 +00001505#endif // _LIBCPP_HAS_NO_VARIADICS
1506
Howard Hinnantac7e7482013-07-04 20:59:16 +00001507#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +00001508
1509template <class _Key, class _Tp, class _Compare, class _Allocator>
1510typename map<_Key, _Tp, _Compare, _Allocator>::__node_holder
Howard Hinnantac7e7482013-07-04 20:59:16 +00001511map<_Key, _Tp, _Compare, _Allocator>::__construct_node_with_key(const key_type& __k)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001512{
1513 __node_allocator& __na = __tree_.__node_alloc();
Howard Hinnantc834c512011-11-29 18:15:50 +00001514 __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001515 __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__cc.first), __k);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001516 __h.get_deleter().__first_constructed = true;
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001517 __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__cc.second));
Howard Hinnantc51e1022010-05-11 19:42:16 +00001518 __h.get_deleter().__second_constructed = true;
Dimitry Andric830fb602015-08-19 06:43:33 +00001519 return _LIBCPP_EXPLICIT_MOVE(__h); // explicitly moved for C++03
Howard Hinnantc51e1022010-05-11 19:42:16 +00001520}
1521
Howard Hinnantc51e1022010-05-11 19:42:16 +00001522template <class _Key, class _Tp, class _Compare, class _Allocator>
1523_Tp&
1524map<_Key, _Tp, _Compare, _Allocator>::operator[](const key_type& __k)
1525{
1526 __node_base_pointer __parent;
1527 __node_base_pointer& __child = __find_equal_key(__parent, __k);
1528 __node_pointer __r = static_cast<__node_pointer>(__child);
1529 if (__child == nullptr)
1530 {
Howard Hinnantac7e7482013-07-04 20:59:16 +00001531 __node_holder __h = __construct_node_with_key(__k);
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001532 __tree_.__insert_node_at(__parent, __child, static_cast<__node_base_pointer>(__h.get()));
Howard Hinnantc51e1022010-05-11 19:42:16 +00001533 __r = __h.release();
1534 }
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001535 return __r->__value_.__cc.second;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001536}
1537
Howard Hinnant74279a52010-09-04 23:28:19 +00001538#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +00001539
1540template <class _Key, class _Tp, class _Compare, class _Allocator>
1541_Tp&
1542map<_Key, _Tp, _Compare, _Allocator>::operator[](key_type&& __k)
1543{
1544 __node_base_pointer __parent;
1545 __node_base_pointer& __child = __find_equal_key(__parent, __k);
1546 __node_pointer __r = static_cast<__node_pointer>(__child);
1547 if (__child == nullptr)
1548 {
Howard Hinnantac7e7482013-07-04 20:59:16 +00001549 __node_holder __h = __construct_node_with_key(_VSTD::move(__k));
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001550 __tree_.__insert_node_at(__parent, __child, static_cast<__node_base_pointer>(__h.get()));
Howard Hinnantc51e1022010-05-11 19:42:16 +00001551 __r = __h.release();
1552 }
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001553 return __r->__value_.__cc.second;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001554}
1555
Howard Hinnant74279a52010-09-04 23:28:19 +00001556#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +00001557
1558template <class _Key, class _Tp, class _Compare, class _Allocator>
1559_Tp&
1560map<_Key, _Tp, _Compare, _Allocator>::at(const key_type& __k)
1561{
1562 __node_base_pointer __parent;
1563 __node_base_pointer& __child = __find_equal_key(__parent, __k);
Howard Hinnant72f73582010-08-11 17:04:31 +00001564#ifndef _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +00001565 if (__child == nullptr)
1566 throw out_of_range("map::at: key not found");
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001567#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001568 return static_cast<__node_pointer>(__child)->__value_.__cc.second;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001569}
1570
1571template <class _Key, class _Tp, class _Compare, class _Allocator>
1572const _Tp&
1573map<_Key, _Tp, _Compare, _Allocator>::at(const key_type& __k) const
1574{
1575 __node_base_const_pointer __parent;
1576 __node_base_const_pointer __child = __find_equal_key(__parent, __k);
Howard Hinnant72f73582010-08-11 17:04:31 +00001577#ifndef _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +00001578 if (__child == nullptr)
1579 throw out_of_range("map::at: key not found");
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001580#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001581 return static_cast<__node_const_pointer>(__child)->__value_.__cc.second;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001582}
1583
Howard Hinnant74279a52010-09-04 23:28:19 +00001584#if !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001585
1586template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001587template <class ..._Args>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001588pair<typename map<_Key, _Tp, _Compare, _Allocator>::iterator, bool>
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001589map<_Key, _Tp, _Compare, _Allocator>::emplace(_Args&& ...__args)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001590{
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001591 __node_holder __h = __construct_node(_VSTD::forward<_Args>(__args)...);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001592 pair<iterator, bool> __r = __tree_.__node_insert_unique(__h.get());
1593 if (__r.second)
1594 __h.release();
1595 return __r;
1596}
1597
1598template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001599template <class ..._Args>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001600typename map<_Key, _Tp, _Compare, _Allocator>::iterator
1601map<_Key, _Tp, _Compare, _Allocator>::emplace_hint(const_iterator __p,
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001602 _Args&& ...__args)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001603{
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001604 __node_holder __h = __construct_node(_VSTD::forward<_Args>(__args)...);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001605 iterator __r = __tree_.__node_insert_unique(__p.__i_, __h.get());
1606 if (__r.__i_.__ptr_ == __h.get())
1607 __h.release();
1608 return __r;
1609}
1610
Howard Hinnant74279a52010-09-04 23:28:19 +00001611#endif // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001612
1613template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001614inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001615bool
1616operator==(const map<_Key, _Tp, _Compare, _Allocator>& __x,
1617 const map<_Key, _Tp, _Compare, _Allocator>& __y)
1618{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001619 return __x.size() == __y.size() && _VSTD::equal(__x.begin(), __x.end(), __y.begin());
Howard Hinnantc51e1022010-05-11 19:42:16 +00001620}
1621
1622template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001623inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001624bool
1625operator< (const map<_Key, _Tp, _Compare, _Allocator>& __x,
1626 const map<_Key, _Tp, _Compare, _Allocator>& __y)
1627{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001628 return _VSTD::lexicographical_compare(__x.begin(), __x.end(), __y.begin(), __y.end());
Howard Hinnantc51e1022010-05-11 19:42:16 +00001629}
1630
1631template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001632inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001633bool
1634operator!=(const map<_Key, _Tp, _Compare, _Allocator>& __x,
1635 const map<_Key, _Tp, _Compare, _Allocator>& __y)
1636{
1637 return !(__x == __y);
1638}
1639
1640template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001641inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001642bool
1643operator> (const map<_Key, _Tp, _Compare, _Allocator>& __x,
1644 const map<_Key, _Tp, _Compare, _Allocator>& __y)
1645{
1646 return __y < __x;
1647}
1648
1649template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001650inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001651bool
1652operator>=(const map<_Key, _Tp, _Compare, _Allocator>& __x,
1653 const map<_Key, _Tp, _Compare, _Allocator>& __y)
1654{
1655 return !(__x < __y);
1656}
1657
1658template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001659inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001660bool
1661operator<=(const map<_Key, _Tp, _Compare, _Allocator>& __x,
1662 const map<_Key, _Tp, _Compare, _Allocator>& __y)
1663{
1664 return !(__y < __x);
1665}
1666
1667template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001668inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001669void
1670swap(map<_Key, _Tp, _Compare, _Allocator>& __x,
1671 map<_Key, _Tp, _Compare, _Allocator>& __y)
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001672 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
Howard Hinnantc51e1022010-05-11 19:42:16 +00001673{
1674 __x.swap(__y);
1675}
1676
1677template <class _Key, class _Tp, class _Compare = less<_Key>,
1678 class _Allocator = allocator<pair<const _Key, _Tp> > >
Howard Hinnanta37d3cf2013-08-12 18:38:34 +00001679class _LIBCPP_TYPE_VIS_ONLY multimap
Howard Hinnantc51e1022010-05-11 19:42:16 +00001680{
1681public:
1682 // types:
1683 typedef _Key key_type;
1684 typedef _Tp mapped_type;
1685 typedef pair<const key_type, mapped_type> value_type;
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001686 typedef pair<key_type, mapped_type> __nc_value_type;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001687 typedef _Compare key_compare;
1688 typedef _Allocator allocator_type;
1689 typedef value_type& reference;
1690 typedef const value_type& const_reference;
1691
Marshall Clow5128cf32015-11-26 01:24:04 +00001692 static_assert((is_same<typename allocator_type::value_type, value_type>::value),
1693 "Allocator::value_type must be same type as value_type");
1694
Howard Hinnanta37d3cf2013-08-12 18:38:34 +00001695 class _LIBCPP_TYPE_VIS_ONLY value_compare
Howard Hinnantc51e1022010-05-11 19:42:16 +00001696 : public binary_function<value_type, value_type, bool>
1697 {
1698 friend class multimap;
1699 protected:
1700 key_compare comp;
1701
Howard Hinnant756c69b2010-09-22 16:48:34 +00001702 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001703 value_compare(key_compare c) : comp(c) {}
1704 public:
Howard Hinnant756c69b2010-09-22 16:48:34 +00001705 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001706 bool operator()(const value_type& __x, const value_type& __y) const
1707 {return comp(__x.first, __y.first);}
1708 };
1709
1710private:
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001711
Howard Hinnant89f8b792013-09-30 19:08:22 +00001712 typedef _VSTD::__value_type<key_type, mapped_type> __value_type;
Howard Hinnant90b91592013-07-05 18:06:00 +00001713 typedef __map_value_compare<key_type, __value_type, key_compare> __vc;
Marshall Clow940e01c2015-04-07 05:21:38 +00001714 typedef typename __rebind_alloc_helper<allocator_traits<allocator_type>,
1715 __value_type>::type __allocator_type;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001716 typedef __tree<__value_type, __vc, __allocator_type> __base;
1717 typedef typename __base::__node_traits __node_traits;
1718 typedef allocator_traits<allocator_type> __alloc_traits;
1719
1720 __base __tree_;
1721
1722public:
1723 typedef typename __alloc_traits::pointer pointer;
1724 typedef typename __alloc_traits::const_pointer const_pointer;
1725 typedef typename __alloc_traits::size_type size_type;
1726 typedef typename __alloc_traits::difference_type difference_type;
1727 typedef __map_iterator<typename __base::iterator> iterator;
1728 typedef __map_const_iterator<typename __base::const_iterator> const_iterator;
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001729 typedef _VSTD::reverse_iterator<iterator> reverse_iterator;
1730 typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001731
Howard Hinnant756c69b2010-09-22 16:48:34 +00001732 _LIBCPP_INLINE_VISIBILITY
Marshall Clow7086a5a2014-03-10 04:50:10 +00001733 multimap()
1734 _NOEXCEPT_(
1735 is_nothrow_default_constructible<allocator_type>::value &&
1736 is_nothrow_default_constructible<key_compare>::value &&
1737 is_nothrow_copy_constructible<key_compare>::value)
1738 : __tree_(__vc(key_compare())) {}
1739
1740 _LIBCPP_INLINE_VISIBILITY
1741 explicit multimap(const key_compare& __comp)
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001742 _NOEXCEPT_(
1743 is_nothrow_default_constructible<allocator_type>::value &&
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001744 is_nothrow_copy_constructible<key_compare>::value)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001745 : __tree_(__vc(__comp)) {}
1746
Howard Hinnant756c69b2010-09-22 16:48:34 +00001747 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001748 explicit multimap(const key_compare& __comp, const allocator_type& __a)
1749 : __tree_(__vc(__comp), __a) {}
1750
1751 template <class _InputIterator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001752 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001753 multimap(_InputIterator __f, _InputIterator __l,
1754 const key_compare& __comp = key_compare())
1755 : __tree_(__vc(__comp))
1756 {
1757 insert(__f, __l);
1758 }
1759
1760 template <class _InputIterator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001761 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001762 multimap(_InputIterator __f, _InputIterator __l,
1763 const key_compare& __comp, const allocator_type& __a)
1764 : __tree_(__vc(__comp), __a)
1765 {
1766 insert(__f, __l);
1767 }
1768
Marshall Clow300abfb2013-09-11 01:15:47 +00001769#if _LIBCPP_STD_VER > 11
1770 template <class _InputIterator>
1771 _LIBCPP_INLINE_VISIBILITY
1772 multimap(_InputIterator __f, _InputIterator __l, const allocator_type& __a)
1773 : multimap(__f, __l, key_compare(), __a) {}
1774#endif
1775
Howard Hinnant756c69b2010-09-22 16:48:34 +00001776 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001777 multimap(const multimap& __m)
1778 : __tree_(__m.__tree_.value_comp(),
1779 __alloc_traits::select_on_container_copy_construction(__m.__tree_.__alloc()))
1780 {
1781 insert(__m.begin(), __m.end());
1782 }
1783
Howard Hinnantd3a657f2011-07-01 19:24:36 +00001784 _LIBCPP_INLINE_VISIBILITY
1785 multimap& operator=(const multimap& __m)
1786 {
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001787#if __cplusplus >= 201103L
Howard Hinnantd3a657f2011-07-01 19:24:36 +00001788 __tree_ = __m.__tree_;
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001789#else
Marshall Clowdb3cfcb2014-02-08 04:03:14 +00001790 if (this != &__m) {
1791 __tree_.clear();
1792 __tree_.value_comp() = __m.__tree_.value_comp();
1793 __tree_.__copy_assign_alloc(__m.__tree_);
1794 insert(__m.begin(), __m.end());
1795 }
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001796#endif
Howard Hinnantd3a657f2011-07-01 19:24:36 +00001797 return *this;
1798 }
1799
Howard Hinnant74279a52010-09-04 23:28:19 +00001800#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +00001801
Howard Hinnant756c69b2010-09-22 16:48:34 +00001802 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001803 multimap(multimap&& __m)
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001804 _NOEXCEPT_(is_nothrow_move_constructible<__base>::value)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001805 : __tree_(_VSTD::move(__m.__tree_))
Howard Hinnantc51e1022010-05-11 19:42:16 +00001806 {
1807 }
1808
1809 multimap(multimap&& __m, const allocator_type& __a);
1810
Howard Hinnant756c69b2010-09-22 16:48:34 +00001811 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant33711792011-08-12 21:56:02 +00001812 multimap& operator=(multimap&& __m)
1813 _NOEXCEPT_(is_nothrow_move_assignable<__base>::value)
1814 {
1815 __tree_ = _VSTD::move(__m.__tree_);
1816 return *this;
1817 }
1818
1819#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
1820
1821#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1822
1823 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001824 multimap(initializer_list<value_type> __il, const key_compare& __comp = key_compare())
1825 : __tree_(__vc(__comp))
1826 {
1827 insert(__il.begin(), __il.end());
1828 }
1829
Howard Hinnant756c69b2010-09-22 16:48:34 +00001830 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001831 multimap(initializer_list<value_type> __il, const key_compare& __comp, const allocator_type& __a)
1832 : __tree_(__vc(__comp), __a)
1833 {
1834 insert(__il.begin(), __il.end());
1835 }
1836
Marshall Clow300abfb2013-09-11 01:15:47 +00001837#if _LIBCPP_STD_VER > 11
1838 _LIBCPP_INLINE_VISIBILITY
1839 multimap(initializer_list<value_type> __il, const allocator_type& __a)
1840 : multimap(__il, key_compare(), __a) {}
1841#endif
1842
Howard Hinnant756c69b2010-09-22 16:48:34 +00001843 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001844 multimap& operator=(initializer_list<value_type> __il)
1845 {
1846 __tree_.__assign_multi(__il.begin(), __il.end());
1847 return *this;
1848 }
Howard Hinnant33711792011-08-12 21:56:02 +00001849
1850#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantc51e1022010-05-11 19:42:16 +00001851
Howard Hinnant756c69b2010-09-22 16:48:34 +00001852 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001853 explicit multimap(const allocator_type& __a)
1854 : __tree_(__a)
1855 {
1856 }
1857
Howard Hinnant756c69b2010-09-22 16:48:34 +00001858 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001859 multimap(const multimap& __m, const allocator_type& __a)
1860 : __tree_(__m.__tree_.value_comp(), __a)
1861 {
1862 insert(__m.begin(), __m.end());
1863 }
1864
Howard Hinnant756c69b2010-09-22 16:48:34 +00001865 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001866 iterator begin() _NOEXCEPT {return __tree_.begin();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001867 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001868 const_iterator begin() const _NOEXCEPT {return __tree_.begin();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001869 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001870 iterator end() _NOEXCEPT {return __tree_.end();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001871 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001872 const_iterator end() const _NOEXCEPT {return __tree_.end();}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001873
Howard Hinnant756c69b2010-09-22 16:48:34 +00001874 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001875 reverse_iterator rbegin() _NOEXCEPT {return reverse_iterator(end());}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001876 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001877 const_reverse_iterator rbegin() const _NOEXCEPT
1878 {return const_reverse_iterator(end());}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001879 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001880 reverse_iterator rend() _NOEXCEPT {return reverse_iterator(begin());}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001881 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001882 const_reverse_iterator rend() const _NOEXCEPT
1883 {return const_reverse_iterator(begin());}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001884
Howard Hinnant756c69b2010-09-22 16:48:34 +00001885 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001886 const_iterator cbegin() const _NOEXCEPT {return begin();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001887 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001888 const_iterator cend() const _NOEXCEPT {return end();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001889 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001890 const_reverse_iterator crbegin() const _NOEXCEPT {return rbegin();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001891 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001892 const_reverse_iterator crend() const _NOEXCEPT {return rend();}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001893
Howard Hinnant756c69b2010-09-22 16:48:34 +00001894 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001895 bool empty() const _NOEXCEPT {return __tree_.size() == 0;}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001896 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001897 size_type size() const _NOEXCEPT {return __tree_.size();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001898 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001899 size_type max_size() const _NOEXCEPT {return __tree_.max_size();}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001900
Howard Hinnant756c69b2010-09-22 16:48:34 +00001901 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001902 allocator_type get_allocator() const _NOEXCEPT {return __tree_.__alloc();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001903 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001904 key_compare key_comp() const {return __tree_.value_comp().key_comp();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001905 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001906 value_compare value_comp() const
1907 {return value_compare(__tree_.value_comp().key_comp());}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001908
Howard Hinnant74279a52010-09-04 23:28:19 +00001909#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant74279a52010-09-04 23:28:19 +00001910#ifndef _LIBCPP_HAS_NO_VARIADICS
1911
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001912 template <class ..._Args>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001913 iterator
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001914 emplace(_Args&& ...__args);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001915
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001916 template <class ..._Args>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001917 iterator
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001918 emplace_hint(const_iterator __p, _Args&& ...__args);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001919
Howard Hinnant74279a52010-09-04 23:28:19 +00001920#endif // _LIBCPP_HAS_NO_VARIADICS
1921
Howard Hinnantc834c512011-11-29 18:15:50 +00001922 template <class _Pp,
1923 class = typename enable_if<is_constructible<value_type, _Pp>::value>::type>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001924 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc834c512011-11-29 18:15:50 +00001925 iterator insert(_Pp&& __p)
1926 {return __tree_.__insert_multi(_VSTD::forward<_Pp>(__p));}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001927
Howard Hinnantc834c512011-11-29 18:15:50 +00001928 template <class _Pp,
1929 class = typename enable_if<is_constructible<value_type, _Pp>::value>::type>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001930 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc834c512011-11-29 18:15:50 +00001931 iterator insert(const_iterator __pos, _Pp&& __p)
1932 {return __tree_.__insert_multi(__pos.__i_, _VSTD::forward<_Pp>(__p));}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001933
Howard Hinnant74279a52010-09-04 23:28:19 +00001934#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +00001935
Howard Hinnant756c69b2010-09-22 16:48:34 +00001936 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001937 iterator insert(const value_type& __v) {return __tree_.__insert_multi(__v);}
1938
Howard Hinnant756c69b2010-09-22 16:48:34 +00001939 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001940 iterator insert(const_iterator __p, const value_type& __v)
1941 {return __tree_.__insert_multi(__p.__i_, __v);}
1942
1943 template <class _InputIterator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001944 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001945 void insert(_InputIterator __f, _InputIterator __l)
1946 {
1947 for (const_iterator __e = cend(); __f != __l; ++__f)
1948 __tree_.__insert_multi(__e.__i_, *__f);
1949 }
1950
Howard Hinnant33711792011-08-12 21:56:02 +00001951#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1952
Howard Hinnant756c69b2010-09-22 16:48:34 +00001953 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001954 void insert(initializer_list<value_type> __il)
1955 {insert(__il.begin(), __il.end());}
1956
Howard Hinnant33711792011-08-12 21:56:02 +00001957#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1958
Howard Hinnant756c69b2010-09-22 16:48:34 +00001959 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001960 iterator erase(const_iterator __p) {return __tree_.erase(__p.__i_);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001961 _LIBCPP_INLINE_VISIBILITY
Marshall Clow22ea5b82015-05-10 13:35:00 +00001962 iterator erase(iterator __p) {return __tree_.erase(__p.__i_);}
1963 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001964 size_type erase(const key_type& __k) {return __tree_.__erase_multi(__k);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001965 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001966 iterator erase(const_iterator __f, const_iterator __l)
1967 {return __tree_.erase(__f.__i_, __l.__i_);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001968 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001969 void clear() {__tree_.clear();}
1970
Howard Hinnant756c69b2010-09-22 16:48:34 +00001971 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001972 void swap(multimap& __m)
1973 _NOEXCEPT_(__is_nothrow_swappable<__base>::value)
1974 {__tree_.swap(__m.__tree_);}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001975
Howard Hinnant756c69b2010-09-22 16:48:34 +00001976 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001977 iterator find(const key_type& __k) {return __tree_.find(__k);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001978 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001979 const_iterator find(const key_type& __k) const {return __tree_.find(__k);}
Marshall Clowebb57322013-08-13 22:18:47 +00001980#if _LIBCPP_STD_VER > 11
1981 template <typename _K2>
1982 _LIBCPP_INLINE_VISIBILITY
1983 typename enable_if<__is_transparent<_Compare, _K2>::value,iterator>::type
1984 find(const _K2& __k) {return __tree_.find(__k);}
1985 template <typename _K2>
1986 _LIBCPP_INLINE_VISIBILITY
1987 typename enable_if<__is_transparent<_Compare, _K2>::value,const_iterator>::type
1988 find(const _K2& __k) const {return __tree_.find(__k);}
1989#endif
1990
Howard Hinnant756c69b2010-09-22 16:48:34 +00001991 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001992 size_type count(const key_type& __k) const
1993 {return __tree_.__count_multi(__k);}
Marshall Clowe6a5f522014-08-24 23:54:16 +00001994#if _LIBCPP_STD_VER > 11
1995 template <typename _K2>
1996 _LIBCPP_INLINE_VISIBILITY
1997 typename enable_if<__is_transparent<_Compare, _K2>::value,size_type>::type
Marshall Clow141e47b2015-06-30 18:15:41 +00001998 count(const _K2& __k) const {return __tree_.__count_multi(__k);}
Marshall Clowe6a5f522014-08-24 23:54:16 +00001999#endif
Howard Hinnant756c69b2010-09-22 16:48:34 +00002000 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002001 iterator lower_bound(const key_type& __k)
2002 {return __tree_.lower_bound(__k);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00002003 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002004 const_iterator lower_bound(const key_type& __k) const
2005 {return __tree_.lower_bound(__k);}
Marshall Clowebb57322013-08-13 22:18:47 +00002006#if _LIBCPP_STD_VER > 11
2007 template <typename _K2>
2008 _LIBCPP_INLINE_VISIBILITY
2009 typename enable_if<__is_transparent<_Compare, _K2>::value,iterator>::type
2010 lower_bound(const _K2& __k) {return __tree_.lower_bound(__k);}
2011
2012 template <typename _K2>
2013 _LIBCPP_INLINE_VISIBILITY
2014 typename enable_if<__is_transparent<_Compare, _K2>::value,const_iterator>::type
2015 lower_bound(const _K2& __k) const {return __tree_.lower_bound(__k);}
2016#endif
2017
Howard Hinnant756c69b2010-09-22 16:48:34 +00002018 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002019 iterator upper_bound(const key_type& __k)
2020 {return __tree_.upper_bound(__k);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00002021 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002022 const_iterator upper_bound(const key_type& __k) const
2023 {return __tree_.upper_bound(__k);}
Marshall Clowebb57322013-08-13 22:18:47 +00002024#if _LIBCPP_STD_VER > 11
2025 template <typename _K2>
2026 _LIBCPP_INLINE_VISIBILITY
2027 typename enable_if<__is_transparent<_Compare, _K2>::value,iterator>::type
2028 upper_bound(const _K2& __k) {return __tree_.upper_bound(__k);}
2029 template <typename _K2>
2030 _LIBCPP_INLINE_VISIBILITY
2031 typename enable_if<__is_transparent<_Compare, _K2>::value,const_iterator>::type
2032 upper_bound(const _K2& __k) const {return __tree_.upper_bound(__k);}
2033#endif
2034
Howard Hinnant756c69b2010-09-22 16:48:34 +00002035 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002036 pair<iterator,iterator> equal_range(const key_type& __k)
2037 {return __tree_.__equal_range_multi(__k);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00002038 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002039 pair<const_iterator,const_iterator> equal_range(const key_type& __k) const
2040 {return __tree_.__equal_range_multi(__k);}
Marshall Clowebb57322013-08-13 22:18:47 +00002041#if _LIBCPP_STD_VER > 11
2042 template <typename _K2>
2043 _LIBCPP_INLINE_VISIBILITY
2044 typename enable_if<__is_transparent<_Compare, _K2>::value,pair<iterator,iterator>>::type
2045 equal_range(const _K2& __k) {return __tree_.__equal_range_multi(__k);}
2046 template <typename _K2>
2047 _LIBCPP_INLINE_VISIBILITY
2048 typename enable_if<__is_transparent<_Compare, _K2>::value,pair<const_iterator,const_iterator>>::type
2049 equal_range(const _K2& __k) const {return __tree_.__equal_range_multi(__k);}
2050#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00002051
2052private:
2053 typedef typename __base::__node __node;
2054 typedef typename __base::__node_allocator __node_allocator;
2055 typedef typename __base::__node_pointer __node_pointer;
2056 typedef typename __base::__node_const_pointer __node_const_pointer;
Howard Hinnantc834c512011-11-29 18:15:50 +00002057 typedef __map_node_destructor<__node_allocator> _Dp;
2058 typedef unique_ptr<__node, _Dp> __node_holder;
Howard Hinnantc51e1022010-05-11 19:42:16 +00002059
Howard Hinnant74279a52010-09-04 23:28:19 +00002060#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +00002061 __node_holder __construct_node();
Howard Hinnant29eb9b82012-05-25 22:04:21 +00002062 template <class _A0>
Howard Hinnantac7e7482013-07-04 20:59:16 +00002063 __node_holder
Howard Hinnant29eb9b82012-05-25 22:04:21 +00002064 __construct_node(_A0&& __a0);
Howard Hinnant74279a52010-09-04 23:28:19 +00002065#ifndef _LIBCPP_HAS_NO_VARIADICS
Howard Hinnant29eb9b82012-05-25 22:04:21 +00002066 template <class _A0, class _A1, class ..._Args>
2067 __node_holder __construct_node(_A0&& __a0, _A1&& __a1, _Args&& ...__args);
Howard Hinnant74279a52010-09-04 23:28:19 +00002068#endif // _LIBCPP_HAS_NO_VARIADICS
2069#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +00002070};
2071
Howard Hinnant74279a52010-09-04 23:28:19 +00002072#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +00002073
2074template <class _Key, class _Tp, class _Compare, class _Allocator>
2075multimap<_Key, _Tp, _Compare, _Allocator>::multimap(multimap&& __m, const allocator_type& __a)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00002076 : __tree_(_VSTD::move(__m.__tree_), __a)
Howard Hinnantc51e1022010-05-11 19:42:16 +00002077{
2078 if (__a != __m.get_allocator())
2079 {
2080 const_iterator __e = cend();
2081 while (!__m.empty())
2082 __tree_.__insert_multi(__e.__i_,
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00002083 _VSTD::move(__m.__tree_.remove(__m.begin().__i_)->__value_));
Howard Hinnantc51e1022010-05-11 19:42:16 +00002084 }
2085}
2086
2087template <class _Key, class _Tp, class _Compare, class _Allocator>
2088typename multimap<_Key, _Tp, _Compare, _Allocator>::__node_holder
2089multimap<_Key, _Tp, _Compare, _Allocator>::__construct_node()
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 Hinnant2d0046b2013-06-19 21:29:40 +00002093 __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__cc.first));
Howard Hinnantc51e1022010-05-11 19:42:16 +00002094 __h.get_deleter().__first_constructed = true;
Howard Hinnant2d0046b2013-06-19 21:29:40 +00002095 __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__cc.second));
Howard Hinnantc51e1022010-05-11 19:42:16 +00002096 __h.get_deleter().__second_constructed = true;
2097 return __h;
2098}
2099
2100template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant29eb9b82012-05-25 22:04:21 +00002101template <class _A0>
Howard Hinnantac7e7482013-07-04 20:59:16 +00002102typename multimap<_Key, _Tp, _Compare, _Allocator>::__node_holder
Howard Hinnantc51e1022010-05-11 19:42:16 +00002103multimap<_Key, _Tp, _Compare, _Allocator>::__construct_node(_A0&& __a0)
2104{
2105 __node_allocator& __na = __tree_.__node_alloc();
Howard Hinnantc834c512011-11-29 18:15:50 +00002106 __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00002107 __node_traits::construct(__na, _VSTD::addressof(__h->__value_), _VSTD::forward<_A0>(__a0));
Howard Hinnantc51e1022010-05-11 19:42:16 +00002108 __h.get_deleter().__first_constructed = true;
2109 __h.get_deleter().__second_constructed = true;
2110 return __h;
2111}
2112
Howard Hinnant29eb9b82012-05-25 22:04:21 +00002113#ifndef _LIBCPP_HAS_NO_VARIADICS
2114
2115template <class _Key, class _Tp, class _Compare, class _Allocator>
2116template <class _A0, class _A1, class ..._Args>
2117typename multimap<_Key, _Tp, _Compare, _Allocator>::__node_holder
2118multimap<_Key, _Tp, _Compare, _Allocator>::__construct_node(_A0&& __a0, _A1&& __a1, _Args&& ...__args)
2119{
2120 __node_allocator& __na = __tree_.__node_alloc();
2121 __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
2122 __node_traits::construct(__na, _VSTD::addressof(__h->__value_),
2123 _VSTD::forward<_A0>(__a0), _VSTD::forward<_A1>(__a1),
2124 _VSTD::forward<_Args>(__args)...);
2125 __h.get_deleter().__first_constructed = true;
Howard Hinnantc51e1022010-05-11 19:42:16 +00002126 __h.get_deleter().__second_constructed = true;
2127 return __h;
2128}
2129
Howard Hinnant74279a52010-09-04 23:28:19 +00002130#endif // _LIBCPP_HAS_NO_VARIADICS
2131#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +00002132
Howard Hinnant74279a52010-09-04 23:28:19 +00002133#if !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
Howard Hinnantc51e1022010-05-11 19:42:16 +00002134
2135template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant29eb9b82012-05-25 22:04:21 +00002136template <class ..._Args>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002137typename multimap<_Key, _Tp, _Compare, _Allocator>::iterator
Howard Hinnant29eb9b82012-05-25 22:04:21 +00002138multimap<_Key, _Tp, _Compare, _Allocator>::emplace(_Args&& ...__args)
Howard Hinnantc51e1022010-05-11 19:42:16 +00002139{
Howard Hinnant29eb9b82012-05-25 22:04:21 +00002140 __node_holder __h = __construct_node(_VSTD::forward<_Args>(__args)...);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002141 iterator __r = __tree_.__node_insert_multi(__h.get());
2142 __h.release();
2143 return __r;
2144}
2145
2146template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant29eb9b82012-05-25 22:04:21 +00002147template <class ..._Args>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002148typename multimap<_Key, _Tp, _Compare, _Allocator>::iterator
2149multimap<_Key, _Tp, _Compare, _Allocator>::emplace_hint(const_iterator __p,
Howard Hinnantc51e1022010-05-11 19:42:16 +00002150 _Args&& ...__args)
2151{
Howard Hinnant29eb9b82012-05-25 22:04:21 +00002152 __node_holder __h = __construct_node(_VSTD::forward<_Args>(__args)...);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002153 iterator __r = __tree_.__node_insert_multi(__p.__i_, __h.get());
2154 __h.release();
2155 return __r;
2156}
2157
Howard Hinnant74279a52010-09-04 23:28:19 +00002158#endif // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
Howard Hinnantc51e1022010-05-11 19:42:16 +00002159
2160template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00002161inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002162bool
2163operator==(const multimap<_Key, _Tp, _Compare, _Allocator>& __x,
2164 const multimap<_Key, _Tp, _Compare, _Allocator>& __y)
2165{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00002166 return __x.size() == __y.size() && _VSTD::equal(__x.begin(), __x.end(), __y.begin());
Howard Hinnantc51e1022010-05-11 19:42:16 +00002167}
2168
2169template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00002170inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002171bool
2172operator< (const multimap<_Key, _Tp, _Compare, _Allocator>& __x,
2173 const multimap<_Key, _Tp, _Compare, _Allocator>& __y)
2174{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00002175 return _VSTD::lexicographical_compare(__x.begin(), __x.end(), __y.begin(), __y.end());
Howard Hinnantc51e1022010-05-11 19:42:16 +00002176}
2177
2178template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00002179inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002180bool
2181operator!=(const multimap<_Key, _Tp, _Compare, _Allocator>& __x,
2182 const multimap<_Key, _Tp, _Compare, _Allocator>& __y)
2183{
2184 return !(__x == __y);
2185}
2186
2187template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00002188inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002189bool
2190operator> (const multimap<_Key, _Tp, _Compare, _Allocator>& __x,
2191 const multimap<_Key, _Tp, _Compare, _Allocator>& __y)
2192{
2193 return __y < __x;
2194}
2195
2196template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00002197inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002198bool
2199operator>=(const multimap<_Key, _Tp, _Compare, _Allocator>& __x,
2200 const multimap<_Key, _Tp, _Compare, _Allocator>& __y)
2201{
2202 return !(__x < __y);
2203}
2204
2205template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00002206inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002207bool
2208operator<=(const multimap<_Key, _Tp, _Compare, _Allocator>& __x,
2209 const multimap<_Key, _Tp, _Compare, _Allocator>& __y)
2210{
2211 return !(__y < __x);
2212}
2213
2214template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00002215inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002216void
2217swap(multimap<_Key, _Tp, _Compare, _Allocator>& __x,
2218 multimap<_Key, _Tp, _Compare, _Allocator>& __y)
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00002219 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
Howard Hinnantc51e1022010-05-11 19:42:16 +00002220{
2221 __x.swap(__y);
2222}
2223
2224_LIBCPP_END_NAMESPACE_STD
2225
2226#endif // _LIBCPP_MAP