blob: 14eb4eb23d931f1b8c252d13e98c53af5c88eec2 [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
138 iterator erase(const_iterator position);
Marshall Clow22ea5b82015-05-10 13:35:00 +0000139 iterator erase(iterator position); // C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000140 size_type erase(const key_type& k);
141 iterator erase(const_iterator first, const_iterator last);
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000142 void clear() noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000143
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000144 void swap(map& m)
145 noexcept(
146 __is_nothrow_swappable<key_compare>::value &&
147 (!allocator_type::propagate_on_container_swap::value ||
148 __is_nothrow_swappable<allocator_type>::value));
Howard Hinnantc51e1022010-05-11 19:42:16 +0000149
150 // observers:
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000151 allocator_type get_allocator() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000152 key_compare key_comp() const;
153 value_compare value_comp() const;
154
155 // map operations:
156 iterator find(const key_type& k);
157 const_iterator find(const key_type& k) const;
Marshall Clowebb57322013-08-13 22:18:47 +0000158 template<typename K>
159 iterator find(const K& x); // C++14
160 template<typename K>
161 const_iterator find(const K& x) const; // C++14
162 template<typename K>
Marshall Clowe6a5f522014-08-24 23:54:16 +0000163 size_type count(const K& x) const; // C++14
Marshall Clowebb57322013-08-13 22:18:47 +0000164
Howard Hinnantc51e1022010-05-11 19:42:16 +0000165 size_type count(const key_type& k) const;
166 iterator lower_bound(const key_type& k);
167 const_iterator lower_bound(const key_type& k) const;
Marshall Clowebb57322013-08-13 22:18:47 +0000168 template<typename K>
169 iterator lower_bound(const K& x); // C++14
170 template<typename K>
171 const_iterator lower_bound(const K& x) const; // C++14
172
Howard Hinnantc51e1022010-05-11 19:42:16 +0000173 iterator upper_bound(const key_type& k);
174 const_iterator upper_bound(const key_type& k) const;
Marshall Clowebb57322013-08-13 22:18:47 +0000175 template<typename K>
176 iterator upper_bound(const K& x); // C++14
177 template<typename K>
178 const_iterator upper_bound(const K& x) const; // C++14
179
Howard Hinnantc51e1022010-05-11 19:42:16 +0000180 pair<iterator,iterator> equal_range(const key_type& k);
181 pair<const_iterator,const_iterator> equal_range(const key_type& k) const;
Marshall Clowebb57322013-08-13 22:18:47 +0000182 template<typename K>
183 pair<iterator,iterator> equal_range(const K& x); // C++14
184 template<typename K>
185 pair<const_iterator,const_iterator> equal_range(const K& x) const; // C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000186};
187
188template <class Key, class T, class Compare, class Allocator>
189bool
190operator==(const map<Key, T, Compare, Allocator>& x,
191 const map<Key, T, Compare, Allocator>& y);
192
193template <class Key, class T, class Compare, class Allocator>
194bool
195operator< (const map<Key, T, Compare, Allocator>& x,
196 const map<Key, T, Compare, Allocator>& y);
197
198template <class Key, class T, class Compare, class Allocator>
199bool
200operator!=(const map<Key, T, Compare, Allocator>& x,
201 const map<Key, T, Compare, Allocator>& y);
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
218// specialized algorithms:
219template <class Key, class T, class Compare, class Allocator>
220void
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000221swap(map<Key, T, Compare, Allocator>& x, map<Key, T, Compare, Allocator>& y)
222 noexcept(noexcept(x.swap(y)));
Howard Hinnantc51e1022010-05-11 19:42:16 +0000223
224template <class Key, class T, class Compare = less<Key>,
225 class Allocator = allocator<pair<const Key, T>>>
226class multimap
227{
228public:
229 // types:
230 typedef Key key_type;
231 typedef T mapped_type;
232 typedef pair<const key_type,mapped_type> value_type;
233 typedef Compare key_compare;
234 typedef Allocator allocator_type;
235 typedef typename allocator_type::reference reference;
236 typedef typename allocator_type::const_reference const_reference;
237 typedef typename allocator_type::size_type size_type;
238 typedef typename allocator_type::difference_type difference_type;
239 typedef typename allocator_type::pointer pointer;
240 typedef typename allocator_type::const_pointer const_pointer;
241
242 typedef implementation-defined iterator;
243 typedef implementation-defined const_iterator;
244 typedef std::reverse_iterator<iterator> reverse_iterator;
245 typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
246
247 class value_compare
248 : public binary_function<value_type,value_type,bool>
249 {
250 friend class multimap;
251 protected:
252 key_compare comp;
253 value_compare(key_compare c);
254 public:
255 bool operator()(const value_type& x, const value_type& y) const;
256 };
257
258 // construct/copy/destroy:
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000259 multimap()
260 noexcept(
261 is_nothrow_default_constructible<allocator_type>::value &&
262 is_nothrow_default_constructible<key_compare>::value &&
263 is_nothrow_copy_constructible<key_compare>::value);
264 explicit multimap(const key_compare& comp);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000265 multimap(const key_compare& comp, const allocator_type& a);
266 template <class InputIterator>
267 multimap(InputIterator first, InputIterator last, const key_compare& comp);
268 template <class InputIterator>
269 multimap(InputIterator first, InputIterator last, const key_compare& comp,
270 const allocator_type& a);
271 multimap(const multimap& m);
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000272 multimap(multimap&& m)
273 noexcept(
274 is_nothrow_move_constructible<allocator_type>::value &&
275 is_nothrow_move_constructible<key_compare>::value);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000276 explicit multimap(const allocator_type& a);
277 multimap(const multimap& m, const allocator_type& a);
278 multimap(multimap&& m, const allocator_type& a);
279 multimap(initializer_list<value_type> il, const key_compare& comp = key_compare());
280 multimap(initializer_list<value_type> il, const key_compare& comp,
281 const allocator_type& a);
Marshall Clow300abfb2013-09-11 01:15:47 +0000282 template <class InputIterator>
283 multimap(InputIterator first, InputIterator last, const allocator_type& a)
284 : multimap(first, last, Compare(), a) {} // C++14
285 multimap(initializer_list<value_type> il, const allocator_type& a)
286 : multimap(il, Compare(), a) {} // C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000287 ~multimap();
288
289 multimap& operator=(const multimap& m);
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000290 multimap& operator=(multimap&& m)
291 noexcept(
292 allocator_type::propagate_on_container_move_assignment::value &&
293 is_nothrow_move_assignable<allocator_type>::value &&
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000294 is_nothrow_move_assignable<key_compare>::value);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000295 multimap& operator=(initializer_list<value_type> il);
296
297 // iterators:
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000298 iterator begin() noexcept;
299 const_iterator begin() const noexcept;
300 iterator end() noexcept;
301 const_iterator end() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000302
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000303 reverse_iterator rbegin() noexcept;
304 const_reverse_iterator rbegin() const noexcept;
305 reverse_iterator rend() noexcept;
306 const_reverse_iterator rend() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000307
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000308 const_iterator cbegin() const noexcept;
309 const_iterator cend() const noexcept;
310 const_reverse_iterator crbegin() const noexcept;
311 const_reverse_iterator crend() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000312
313 // capacity:
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000314 bool empty() const noexcept;
315 size_type size() const noexcept;
316 size_type max_size() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000317
318 // modifiers:
319 template <class... Args>
320 iterator emplace(Args&&... args);
321 template <class... Args>
322 iterator emplace_hint(const_iterator position, Args&&... args);
323 iterator insert(const value_type& v);
324 template <class P>
325 iterator insert(P&& p);
326 iterator insert(const_iterator position, const value_type& v);
327 template <class P>
328 iterator insert(const_iterator position, P&& p);
329 template <class InputIterator>
330 void insert(InputIterator first, InputIterator last);
331 void insert(initializer_list<value_type> il);
332
333 iterator erase(const_iterator position);
Marshall Clow22ea5b82015-05-10 13:35:00 +0000334 iterator erase(iterator position); // C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000335 size_type erase(const key_type& k);
336 iterator erase(const_iterator first, const_iterator last);
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000337 void clear() noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000338
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000339 void swap(multimap& m)
340 noexcept(
341 __is_nothrow_swappable<key_compare>::value &&
342 (!allocator_type::propagate_on_container_swap::value ||
343 __is_nothrow_swappable<allocator_type>::value));
Howard Hinnantc51e1022010-05-11 19:42:16 +0000344
345 // observers:
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000346 allocator_type get_allocator() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000347 key_compare key_comp() const;
348 value_compare value_comp() const;
349
350 // map operations:
351 iterator find(const key_type& k);
352 const_iterator find(const key_type& k) const;
Marshall Clowebb57322013-08-13 22:18:47 +0000353 template<typename K>
354 iterator find(const K& x); // C++14
355 template<typename K>
356 const_iterator find(const K& x) const; // C++14
357 template<typename K>
Marshall Clowe6a5f522014-08-24 23:54:16 +0000358 size_type count(const K& x) const; // C++14
Marshall Clowebb57322013-08-13 22:18:47 +0000359
Howard Hinnantc51e1022010-05-11 19:42:16 +0000360 size_type count(const key_type& k) const;
361 iterator lower_bound(const key_type& k);
362 const_iterator lower_bound(const key_type& k) const;
Marshall Clowebb57322013-08-13 22:18:47 +0000363 template<typename K>
364 iterator lower_bound(const K& x); // C++14
365 template<typename K>
366 const_iterator lower_bound(const K& x) const; // C++14
367
Howard Hinnantc51e1022010-05-11 19:42:16 +0000368 iterator upper_bound(const key_type& k);
369 const_iterator upper_bound(const key_type& k) const;
Marshall Clowebb57322013-08-13 22:18:47 +0000370 template<typename K>
371 iterator upper_bound(const K& x); // C++14
372 template<typename K>
373 const_iterator upper_bound(const K& x) const; // C++14
374
Howard Hinnantc51e1022010-05-11 19:42:16 +0000375 pair<iterator,iterator> equal_range(const key_type& k);
376 pair<const_iterator,const_iterator> equal_range(const key_type& k) const;
Marshall Clowebb57322013-08-13 22:18:47 +0000377 template<typename K>
378 pair<iterator,iterator> equal_range(const K& x); // C++14
379 template<typename K>
380 pair<const_iterator,const_iterator> equal_range(const K& x) const; // C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000381};
382
383template <class Key, class T, class Compare, class Allocator>
384bool
385operator==(const multimap<Key, T, Compare, Allocator>& x,
386 const multimap<Key, T, Compare, Allocator>& y);
387
388template <class Key, class T, class Compare, class Allocator>
389bool
390operator< (const multimap<Key, T, Compare, Allocator>& x,
391 const multimap<Key, T, Compare, Allocator>& y);
392
393template <class Key, class T, class Compare, class Allocator>
394bool
395operator!=(const multimap<Key, T, Compare, Allocator>& x,
396 const multimap<Key, T, Compare, Allocator>& y);
397
398template <class Key, class T, class Compare, class Allocator>
399bool
400operator> (const multimap<Key, T, Compare, Allocator>& x,
401 const multimap<Key, T, Compare, Allocator>& y);
402
403template <class Key, class T, class Compare, class Allocator>
404bool
405operator>=(const multimap<Key, T, Compare, Allocator>& x,
406 const multimap<Key, T, Compare, Allocator>& y);
407
408template <class Key, class T, class Compare, class Allocator>
409bool
410operator<=(const multimap<Key, T, Compare, Allocator>& x,
411 const multimap<Key, T, Compare, Allocator>& y);
412
413// specialized algorithms:
414template <class Key, class T, class Compare, class Allocator>
415void
416swap(multimap<Key, T, Compare, Allocator>& x,
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000417 multimap<Key, T, Compare, Allocator>& y)
418 noexcept(noexcept(x.swap(y)));
Howard Hinnantc51e1022010-05-11 19:42:16 +0000419
420} // std
421
422*/
423
424#include <__config>
425#include <__tree>
426#include <iterator>
427#include <memory>
428#include <utility>
429#include <functional>
430#include <initializer_list>
Eric Fiselierf7394302015-06-13 07:08:02 +0000431#include <type_traits>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000432
Howard Hinnantaaaa52b2011-10-17 20:05:10 +0000433#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000434#pragma GCC system_header
Howard Hinnantaaaa52b2011-10-17 20:05:10 +0000435#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000436
437_LIBCPP_BEGIN_NAMESPACE_STD
438
Eric Fiselierf7394302015-06-13 07:08:02 +0000439template <class _Key, class _CP, class _Compare,
440 bool = is_empty<_Compare>::value && !__libcpp_is_final<_Compare>::value
Howard Hinnantd0aabf82011-12-11 20:31:33 +0000441 >
Howard Hinnantc51e1022010-05-11 19:42:16 +0000442class __map_value_compare
443 : private _Compare
444{
Howard Hinnantc51e1022010-05-11 19:42:16 +0000445public:
Howard Hinnant756c69b2010-09-22 16:48:34 +0000446 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000447 __map_value_compare()
448 _NOEXCEPT_(is_nothrow_default_constructible<_Compare>::value)
449 : _Compare() {}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000450 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000451 __map_value_compare(_Compare c)
452 _NOEXCEPT_(is_nothrow_copy_constructible<_Compare>::value)
453 : _Compare(c) {}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000454 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000455 const _Compare& key_comp() const _NOEXCEPT {return *this;}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000456 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000457 bool operator()(const _CP& __x, const _CP& __y) const
Howard Hinnant90b91592013-07-05 18:06:00 +0000458 {return static_cast<const _Compare&>(*this)(__x.__cc.first, __y.__cc.first);}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000459 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000460 bool operator()(const _CP& __x, const _Key& __y) const
Howard Hinnant90b91592013-07-05 18:06:00 +0000461 {return static_cast<const _Compare&>(*this)(__x.__cc.first, __y);}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000462 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000463 bool operator()(const _Key& __x, const _CP& __y) const
Howard Hinnant90b91592013-07-05 18:06:00 +0000464 {return static_cast<const _Compare&>(*this)(__x, __y.__cc.first);}
Marshall Clowebb57322013-08-13 22:18:47 +0000465
466#if _LIBCPP_STD_VER > 11
467 template <typename _K2>
468 _LIBCPP_INLINE_VISIBILITY
469 typename enable_if<__is_transparent<_Compare, _K2>::value, bool>::type
470 operator () ( const _K2& __x, const _CP& __y ) const
471 {return static_cast<const _Compare&>(*this) (__x, __y.__cc.first);}
472
473 template <typename _K2>
474 _LIBCPP_INLINE_VISIBILITY
475 typename enable_if<__is_transparent<_Compare, _K2>::value, bool>::type
476 operator () (const _CP& __x, const _K2& __y) const
477 {return static_cast<const _Compare&>(*this) (__x.__cc.first, __y);}
478#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000479};
480
Howard Hinnant90b91592013-07-05 18:06:00 +0000481template <class _Key, class _CP, class _Compare>
482class __map_value_compare<_Key, _CP, _Compare, false>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000483{
484 _Compare comp;
485
Howard Hinnantc51e1022010-05-11 19:42:16 +0000486public:
Howard Hinnant756c69b2010-09-22 16:48:34 +0000487 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000488 __map_value_compare()
489 _NOEXCEPT_(is_nothrow_default_constructible<_Compare>::value)
490 : comp() {}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000491 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000492 __map_value_compare(_Compare c)
493 _NOEXCEPT_(is_nothrow_copy_constructible<_Compare>::value)
494 : comp(c) {}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000495 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000496 const _Compare& key_comp() const _NOEXCEPT {return comp;}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000497
Howard Hinnant756c69b2010-09-22 16:48:34 +0000498 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000499 bool operator()(const _CP& __x, const _CP& __y) const
Howard Hinnant90b91592013-07-05 18:06:00 +0000500 {return comp(__x.__cc.first, __y.__cc.first);}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000501 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000502 bool operator()(const _CP& __x, const _Key& __y) const
Howard Hinnant90b91592013-07-05 18:06:00 +0000503 {return comp(__x.__cc.first, __y);}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000504 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000505 bool operator()(const _Key& __x, const _CP& __y) const
Howard Hinnant90b91592013-07-05 18:06:00 +0000506 {return comp(__x, __y.__cc.first);}
Marshall Clowebb57322013-08-13 22:18:47 +0000507
508#if _LIBCPP_STD_VER > 11
509 template <typename _K2>
510 _LIBCPP_INLINE_VISIBILITY
511 typename enable_if<__is_transparent<_Compare, _K2>::value, bool>::type
512 operator () ( const _K2& __x, const _CP& __y ) const
513 {return comp (__x, __y.__cc.first);}
514
515 template <typename _K2>
516 _LIBCPP_INLINE_VISIBILITY
517 typename enable_if<__is_transparent<_Compare, _K2>::value, bool>::type
518 operator () (const _CP& __x, const _K2& __y) const
519 {return comp (__x.__cc.first, __y);}
520#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000521};
522
523template <class _Allocator>
524class __map_node_destructor
525{
526 typedef _Allocator allocator_type;
527 typedef allocator_traits<allocator_type> __alloc_traits;
528 typedef typename __alloc_traits::value_type::value_type value_type;
529public:
530 typedef typename __alloc_traits::pointer pointer;
531private:
Howard Hinnant2d0046b2013-06-19 21:29:40 +0000532 typedef typename value_type::value_type::first_type first_type;
533 typedef typename value_type::value_type::second_type second_type;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000534
535 allocator_type& __na_;
536
537 __map_node_destructor& operator=(const __map_node_destructor&);
538
539public:
540 bool __first_constructed;
541 bool __second_constructed;
542
Howard Hinnant756c69b2010-09-22 16:48:34 +0000543 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000544 explicit __map_node_destructor(allocator_type& __na) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +0000545 : __na_(__na),
546 __first_constructed(false),
547 __second_constructed(false)
548 {}
549
Howard Hinnant74279a52010-09-04 23:28:19 +0000550#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant756c69b2010-09-22 16:48:34 +0000551 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000552 __map_node_destructor(__tree_node_destructor<allocator_type>&& __x) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +0000553 : __na_(__x.__na_),
554 __first_constructed(__x.__value_constructed),
555 __second_constructed(__x.__value_constructed)
556 {
557 __x.__value_constructed = false;
558 }
Howard Hinnant5dc89112010-09-04 23:46:48 +0000559#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +0000560
Howard Hinnant756c69b2010-09-22 16:48:34 +0000561 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000562 void operator()(pointer __p) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +0000563 {
564 if (__second_constructed)
Howard Hinnant2d0046b2013-06-19 21:29:40 +0000565 __alloc_traits::destroy(__na_, _VSTD::addressof(__p->__value_.__cc.second));
Howard Hinnantc51e1022010-05-11 19:42:16 +0000566 if (__first_constructed)
Howard Hinnant2d0046b2013-06-19 21:29:40 +0000567 __alloc_traits::destroy(__na_, _VSTD::addressof(__p->__value_.__cc.first));
Howard Hinnantc51e1022010-05-11 19:42:16 +0000568 if (__p)
569 __alloc_traits::deallocate(__na_, __p, 1);
570 }
571};
572
Howard Hinnant944510a2011-06-14 19:58:17 +0000573template <class _Key, class _Tp, class _Compare, class _Allocator>
574 class map;
575template <class _Key, class _Tp, class _Compare, class _Allocator>
576 class multimap;
577template <class _TreeIterator> class __map_const_iterator;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000578
Howard Hinnant89f8b792013-09-30 19:08:22 +0000579#if __cplusplus >= 201103L
580
581template <class _Key, class _Tp>
582union __value_type
583{
584 typedef _Key key_type;
585 typedef _Tp mapped_type;
586 typedef pair<const key_type, mapped_type> value_type;
587 typedef pair<key_type, mapped_type> __nc_value_type;
588
589 value_type __cc;
590 __nc_value_type __nc;
591
592 template <class ..._Args>
593 _LIBCPP_INLINE_VISIBILITY
594 __value_type(_Args&& ...__args)
595 : __cc(std::forward<_Args>(__args)...) {}
596
597 _LIBCPP_INLINE_VISIBILITY
598 __value_type(const __value_type& __v)
599 : __cc(__v.__cc) {}
600
601 _LIBCPP_INLINE_VISIBILITY
602 __value_type(__value_type& __v)
603 : __cc(__v.__cc) {}
604
605 _LIBCPP_INLINE_VISIBILITY
606 __value_type(__value_type&& __v)
607 : __nc(std::move(__v.__nc)) {}
608
609 _LIBCPP_INLINE_VISIBILITY
610 __value_type& operator=(const __value_type& __v)
611 {__nc = __v.__cc; return *this;}
612
613 _LIBCPP_INLINE_VISIBILITY
614 __value_type& operator=(__value_type&& __v)
615 {__nc = std::move(__v.__nc); return *this;}
616
617 _LIBCPP_INLINE_VISIBILITY
618 ~__value_type() {__cc.~value_type();}
619};
620
621#else
622
623template <class _Key, class _Tp>
624struct __value_type
625{
626 typedef _Key key_type;
627 typedef _Tp mapped_type;
628 typedef pair<const key_type, mapped_type> value_type;
629
630 value_type __cc;
631
632 _LIBCPP_INLINE_VISIBILITY
633 __value_type() {}
634
635 template <class _A0>
636 _LIBCPP_INLINE_VISIBILITY
637 __value_type(const _A0& __a0)
638 : __cc(__a0) {}
639
640 template <class _A0, class _A1>
641 _LIBCPP_INLINE_VISIBILITY
642 __value_type(const _A0& __a0, const _A1& __a1)
643 : __cc(__a0, __a1) {}
644};
645
646#endif
647
Eric Fiselier44f9fd02015-03-03 20:10:01 +0000648template <class _Tp>
649struct __extract_key_value_types;
650
651template <class _Key, class _Tp>
652struct __extract_key_value_types<__value_type<_Key, _Tp> >
653{
654 typedef _Key const __key_type;
655 typedef _Tp __mapped_type;
656};
657
Howard Hinnantc51e1022010-05-11 19:42:16 +0000658template <class _TreeIterator>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +0000659class _LIBCPP_TYPE_VIS_ONLY __map_iterator
Howard Hinnantc51e1022010-05-11 19:42:16 +0000660{
661 _TreeIterator __i_;
662
663 typedef typename _TreeIterator::__pointer_traits __pointer_traits;
Eric Fiselier44f9fd02015-03-03 20:10:01 +0000664 typedef typename _TreeIterator::value_type __value_type;
665 typedef typename __extract_key_value_types<__value_type>::__key_type __key_type;
666 typedef typename __extract_key_value_types<__value_type>::__mapped_type __mapped_type;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000667public:
668 typedef bidirectional_iterator_tag iterator_category;
Howard Hinnantb2e8a422011-02-27 18:02:02 +0000669 typedef pair<__key_type, __mapped_type> value_type;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000670 typedef typename _TreeIterator::difference_type difference_type;
671 typedef value_type& reference;
672 typedef typename __pointer_traits::template
673#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
674 rebind<value_type>
675#else
676 rebind<value_type>::other
677#endif
678 pointer;
679
Howard Hinnant756c69b2010-09-22 16:48:34 +0000680 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000681 __map_iterator() _NOEXCEPT {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000682
Howard Hinnant756c69b2010-09-22 16:48:34 +0000683 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000684 __map_iterator(_TreeIterator __i) _NOEXCEPT : __i_(__i) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000685
Howard Hinnant756c69b2010-09-22 16:48:34 +0000686 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2d0046b2013-06-19 21:29:40 +0000687 reference operator*() const {return __i_->__cc;}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000688 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2d0046b2013-06-19 21:29:40 +0000689 pointer operator->() const {return pointer_traits<pointer>::pointer_to(__i_->__cc);}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000690
Howard Hinnant756c69b2010-09-22 16:48:34 +0000691 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000692 __map_iterator& operator++() {++__i_; return *this;}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000693 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000694 __map_iterator operator++(int)
695 {
696 __map_iterator __t(*this);
697 ++(*this);
698 return __t;
699 }
700
Howard Hinnant756c69b2010-09-22 16:48:34 +0000701 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000702 __map_iterator& operator--() {--__i_; return *this;}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000703 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000704 __map_iterator operator--(int)
705 {
706 __map_iterator __t(*this);
707 --(*this);
708 return __t;
709 }
710
Howard Hinnant756c69b2010-09-22 16:48:34 +0000711 friend _LIBCPP_INLINE_VISIBILITY
712 bool operator==(const __map_iterator& __x, const __map_iterator& __y)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000713 {return __x.__i_ == __y.__i_;}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000714 friend
715 _LIBCPP_INLINE_VISIBILITY
716 bool operator!=(const __map_iterator& __x, const __map_iterator& __y)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000717 {return __x.__i_ != __y.__i_;}
718
Howard Hinnanta37d3cf2013-08-12 18:38:34 +0000719 template <class, class, class, class> friend class _LIBCPP_TYPE_VIS_ONLY map;
720 template <class, class, class, class> friend class _LIBCPP_TYPE_VIS_ONLY multimap;
721 template <class> friend class _LIBCPP_TYPE_VIS_ONLY __map_const_iterator;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000722};
723
724template <class _TreeIterator>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +0000725class _LIBCPP_TYPE_VIS_ONLY __map_const_iterator
Howard Hinnantc51e1022010-05-11 19:42:16 +0000726{
727 _TreeIterator __i_;
728
729 typedef typename _TreeIterator::__pointer_traits __pointer_traits;
Eric Fiselier44f9fd02015-03-03 20:10:01 +0000730 typedef typename _TreeIterator::value_type __value_type;
731 typedef typename __extract_key_value_types<__value_type>::__key_type __key_type;
732 typedef typename __extract_key_value_types<__value_type>::__mapped_type __mapped_type;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000733public:
734 typedef bidirectional_iterator_tag iterator_category;
Howard Hinnantb2e8a422011-02-27 18:02:02 +0000735 typedef pair<__key_type, __mapped_type> value_type;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000736 typedef typename _TreeIterator::difference_type difference_type;
737 typedef const value_type& reference;
738 typedef typename __pointer_traits::template
739#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
Howard Hinnant73f3c8a2011-04-11 02:18:41 +0000740 rebind<const value_type>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000741#else
Howard Hinnant73f3c8a2011-04-11 02:18:41 +0000742 rebind<const value_type>::other
Howard Hinnantc51e1022010-05-11 19:42:16 +0000743#endif
744 pointer;
745
Howard Hinnant756c69b2010-09-22 16:48:34 +0000746 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000747 __map_const_iterator() _NOEXCEPT {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000748
Howard Hinnant756c69b2010-09-22 16:48:34 +0000749 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000750 __map_const_iterator(_TreeIterator __i) _NOEXCEPT : __i_(__i) {}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000751 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier44f9fd02015-03-03 20:10:01 +0000752 __map_const_iterator(__map_iterator<
753 typename _TreeIterator::__non_const_iterator> __i) _NOEXCEPT
754 : __i_(__i.__i_) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000755
Howard Hinnant756c69b2010-09-22 16:48:34 +0000756 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2d0046b2013-06-19 21:29:40 +0000757 reference operator*() const {return __i_->__cc;}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000758 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2d0046b2013-06-19 21:29:40 +0000759 pointer operator->() const {return pointer_traits<pointer>::pointer_to(__i_->__cc);}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000760
Howard Hinnant756c69b2010-09-22 16:48:34 +0000761 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000762 __map_const_iterator& operator++() {++__i_; return *this;}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000763 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000764 __map_const_iterator operator++(int)
765 {
766 __map_const_iterator __t(*this);
767 ++(*this);
768 return __t;
769 }
770
Howard Hinnant756c69b2010-09-22 16:48:34 +0000771 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000772 __map_const_iterator& operator--() {--__i_; return *this;}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000773 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000774 __map_const_iterator operator--(int)
775 {
776 __map_const_iterator __t(*this);
777 --(*this);
778 return __t;
779 }
780
Howard Hinnant756c69b2010-09-22 16:48:34 +0000781 friend _LIBCPP_INLINE_VISIBILITY
782 bool operator==(const __map_const_iterator& __x, const __map_const_iterator& __y)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000783 {return __x.__i_ == __y.__i_;}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000784 friend _LIBCPP_INLINE_VISIBILITY
785 bool operator!=(const __map_const_iterator& __x, const __map_const_iterator& __y)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000786 {return __x.__i_ != __y.__i_;}
787
Howard Hinnanta37d3cf2013-08-12 18:38:34 +0000788 template <class, class, class, class> friend class _LIBCPP_TYPE_VIS_ONLY map;
789 template <class, class, class, class> friend class _LIBCPP_TYPE_VIS_ONLY multimap;
790 template <class, class, class> friend class _LIBCPP_TYPE_VIS_ONLY __tree_const_iterator;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000791};
792
793template <class _Key, class _Tp, class _Compare = less<_Key>,
794 class _Allocator = allocator<pair<const _Key, _Tp> > >
Howard Hinnanta37d3cf2013-08-12 18:38:34 +0000795class _LIBCPP_TYPE_VIS_ONLY map
Howard Hinnantc51e1022010-05-11 19:42:16 +0000796{
797public:
798 // types:
799 typedef _Key key_type;
800 typedef _Tp mapped_type;
801 typedef pair<const key_type, mapped_type> value_type;
Howard Hinnant2d0046b2013-06-19 21:29:40 +0000802 typedef pair<key_type, mapped_type> __nc_value_type;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000803 typedef _Compare key_compare;
804 typedef _Allocator allocator_type;
805 typedef value_type& reference;
806 typedef const value_type& const_reference;
807
Howard Hinnanta37d3cf2013-08-12 18:38:34 +0000808 class _LIBCPP_TYPE_VIS_ONLY value_compare
Howard Hinnantc51e1022010-05-11 19:42:16 +0000809 : public binary_function<value_type, value_type, bool>
810 {
811 friend class map;
812 protected:
813 key_compare comp;
814
Howard Hinnant756c69b2010-09-22 16:48:34 +0000815 _LIBCPP_INLINE_VISIBILITY value_compare(key_compare c) : comp(c) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000816 public:
Howard Hinnant756c69b2010-09-22 16:48:34 +0000817 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000818 bool operator()(const value_type& __x, const value_type& __y) const
819 {return comp(__x.first, __y.first);}
820 };
821
822private:
Howard Hinnant2d0046b2013-06-19 21:29:40 +0000823
Howard Hinnant89f8b792013-09-30 19:08:22 +0000824 typedef _VSTD::__value_type<key_type, mapped_type> __value_type;
Howard Hinnant90b91592013-07-05 18:06:00 +0000825 typedef __map_value_compare<key_type, __value_type, key_compare> __vc;
Marshall Clow940e01c2015-04-07 05:21:38 +0000826 typedef typename __rebind_alloc_helper<allocator_traits<allocator_type>,
827 __value_type>::type __allocator_type;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000828 typedef __tree<__value_type, __vc, __allocator_type> __base;
829 typedef typename __base::__node_traits __node_traits;
830 typedef allocator_traits<allocator_type> __alloc_traits;
831
832 __base __tree_;
833
834public:
835 typedef typename __alloc_traits::pointer pointer;
836 typedef typename __alloc_traits::const_pointer const_pointer;
837 typedef typename __alloc_traits::size_type size_type;
838 typedef typename __alloc_traits::difference_type difference_type;
Eric Fiselier44f9fd02015-03-03 20:10:01 +0000839 typedef __map_iterator<typename __base::iterator> iterator;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000840 typedef __map_const_iterator<typename __base::const_iterator> const_iterator;
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000841 typedef _VSTD::reverse_iterator<iterator> reverse_iterator;
842 typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000843
Howard Hinnant756c69b2010-09-22 16:48:34 +0000844 _LIBCPP_INLINE_VISIBILITY
Marshall Clow7086a5a2014-03-10 04:50:10 +0000845 map()
846 _NOEXCEPT_(
847 is_nothrow_default_constructible<allocator_type>::value &&
848 is_nothrow_default_constructible<key_compare>::value &&
849 is_nothrow_copy_constructible<key_compare>::value)
850 : __tree_(__vc(key_compare())) {}
851
852 _LIBCPP_INLINE_VISIBILITY
853 explicit map(const key_compare& __comp)
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000854 _NOEXCEPT_(
855 is_nothrow_default_constructible<allocator_type>::value &&
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000856 is_nothrow_copy_constructible<key_compare>::value)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000857 : __tree_(__vc(__comp)) {}
858
Howard Hinnant756c69b2010-09-22 16:48:34 +0000859 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000860 explicit map(const key_compare& __comp, const allocator_type& __a)
861 : __tree_(__vc(__comp), __a) {}
862
863 template <class _InputIterator>
Howard Hinnant756c69b2010-09-22 16:48:34 +0000864 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000865 map(_InputIterator __f, _InputIterator __l,
866 const key_compare& __comp = key_compare())
867 : __tree_(__vc(__comp))
868 {
869 insert(__f, __l);
870 }
871
872 template <class _InputIterator>
Howard Hinnant756c69b2010-09-22 16:48:34 +0000873 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000874 map(_InputIterator __f, _InputIterator __l,
875 const key_compare& __comp, const allocator_type& __a)
876 : __tree_(__vc(__comp), __a)
877 {
878 insert(__f, __l);
879 }
880
Marshall Clow300abfb2013-09-11 01:15:47 +0000881#if _LIBCPP_STD_VER > 11
882 template <class _InputIterator>
883 _LIBCPP_INLINE_VISIBILITY
884 map(_InputIterator __f, _InputIterator __l, const allocator_type& __a)
885 : map(__f, __l, key_compare(), __a) {}
886#endif
887
Howard Hinnant756c69b2010-09-22 16:48:34 +0000888 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000889 map(const map& __m)
890 : __tree_(__m.__tree_)
891 {
892 insert(__m.begin(), __m.end());
893 }
894
Howard Hinnantd3a657f2011-07-01 19:24:36 +0000895 _LIBCPP_INLINE_VISIBILITY
896 map& operator=(const map& __m)
897 {
Howard Hinnant2d0046b2013-06-19 21:29:40 +0000898#if __cplusplus >= 201103L
Howard Hinnantd3a657f2011-07-01 19:24:36 +0000899 __tree_ = __m.__tree_;
Howard Hinnant2d0046b2013-06-19 21:29:40 +0000900#else
Marshall Clowdb3cfcb2014-02-08 04:03:14 +0000901 if (this != &__m) {
902 __tree_.clear();
903 __tree_.value_comp() = __m.__tree_.value_comp();
904 __tree_.__copy_assign_alloc(__m.__tree_);
905 insert(__m.begin(), __m.end());
906 }
Howard Hinnant2d0046b2013-06-19 21:29:40 +0000907#endif
Howard Hinnantd3a657f2011-07-01 19:24:36 +0000908 return *this;
909 }
910
Howard Hinnant74279a52010-09-04 23:28:19 +0000911#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +0000912
Howard Hinnant756c69b2010-09-22 16:48:34 +0000913 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000914 map(map&& __m)
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000915 _NOEXCEPT_(is_nothrow_move_constructible<__base>::value)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000916 : __tree_(_VSTD::move(__m.__tree_))
Howard Hinnantc51e1022010-05-11 19:42:16 +0000917 {
918 }
919
920 map(map&& __m, const allocator_type& __a);
921
Howard Hinnant756c69b2010-09-22 16:48:34 +0000922 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant33711792011-08-12 21:56:02 +0000923 map& operator=(map&& __m)
924 _NOEXCEPT_(is_nothrow_move_assignable<__base>::value)
925 {
926 __tree_ = _VSTD::move(__m.__tree_);
927 return *this;
928 }
929
930#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
931
932#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
933
934 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000935 map(initializer_list<value_type> __il, const key_compare& __comp = key_compare())
936 : __tree_(__vc(__comp))
937 {
938 insert(__il.begin(), __il.end());
939 }
940
Howard Hinnant756c69b2010-09-22 16:48:34 +0000941 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000942 map(initializer_list<value_type> __il, const key_compare& __comp, const allocator_type& __a)
943 : __tree_(__vc(__comp), __a)
944 {
945 insert(__il.begin(), __il.end());
946 }
947
Marshall Clow300abfb2013-09-11 01:15:47 +0000948#if _LIBCPP_STD_VER > 11
949 _LIBCPP_INLINE_VISIBILITY
950 map(initializer_list<value_type> __il, const allocator_type& __a)
951 : map(__il, key_compare(), __a) {}
952#endif
953
Howard Hinnant756c69b2010-09-22 16:48:34 +0000954 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000955 map& operator=(initializer_list<value_type> __il)
956 {
957 __tree_.__assign_unique(__il.begin(), __il.end());
958 return *this;
959 }
960
Howard Hinnant33711792011-08-12 21:56:02 +0000961#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000962
Howard Hinnant756c69b2010-09-22 16:48:34 +0000963 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000964 explicit map(const allocator_type& __a)
965 : __tree_(__a)
966 {
967 }
968
Howard Hinnant756c69b2010-09-22 16:48:34 +0000969 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000970 map(const map& __m, const allocator_type& __a)
971 : __tree_(__m.__tree_.value_comp(), __a)
972 {
973 insert(__m.begin(), __m.end());
974 }
975
Howard Hinnant756c69b2010-09-22 16:48:34 +0000976 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000977 iterator begin() _NOEXCEPT {return __tree_.begin();}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000978 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000979 const_iterator begin() const _NOEXCEPT {return __tree_.begin();}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000980 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000981 iterator end() _NOEXCEPT {return __tree_.end();}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000982 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000983 const_iterator end() const _NOEXCEPT {return __tree_.end();}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000984
Howard Hinnant756c69b2010-09-22 16:48:34 +0000985 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000986 reverse_iterator rbegin() _NOEXCEPT {return reverse_iterator(end());}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000987 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000988 const_reverse_iterator rbegin() const _NOEXCEPT
989 {return const_reverse_iterator(end());}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000990 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000991 reverse_iterator rend() _NOEXCEPT
992 {return reverse_iterator(begin());}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000993 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000994 const_reverse_iterator rend() const _NOEXCEPT
995 {return const_reverse_iterator(begin());}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000996
Howard Hinnant756c69b2010-09-22 16:48:34 +0000997 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000998 const_iterator cbegin() const _NOEXCEPT {return begin();}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000999 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001000 const_iterator cend() const _NOEXCEPT {return end();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001001 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001002 const_reverse_iterator crbegin() const _NOEXCEPT {return rbegin();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001003 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001004 const_reverse_iterator crend() const _NOEXCEPT {return rend();}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001005
Howard Hinnant756c69b2010-09-22 16:48:34 +00001006 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001007 bool empty() const _NOEXCEPT {return __tree_.size() == 0;}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001008 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001009 size_type size() const _NOEXCEPT {return __tree_.size();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001010 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001011 size_type max_size() const _NOEXCEPT {return __tree_.max_size();}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001012
1013 mapped_type& operator[](const key_type& __k);
Howard Hinnant74279a52010-09-04 23:28:19 +00001014#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +00001015 mapped_type& operator[](key_type&& __k);
1016#endif
1017
1018 mapped_type& at(const key_type& __k);
1019 const mapped_type& at(const key_type& __k) const;
1020
Howard Hinnant756c69b2010-09-22 16:48:34 +00001021 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001022 allocator_type get_allocator() const _NOEXCEPT {return __tree_.__alloc();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001023 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001024 key_compare key_comp() const {return __tree_.value_comp().key_comp();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001025 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001026 value_compare value_comp() const {return value_compare(__tree_.value_comp().key_comp());}
1027
Howard Hinnant74279a52010-09-04 23:28:19 +00001028#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant74279a52010-09-04 23:28:19 +00001029#ifndef _LIBCPP_HAS_NO_VARIADICS
1030
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001031 template <class ..._Args>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001032 pair<iterator, bool>
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001033 emplace(_Args&& ...__args);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001034
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001035 template <class ..._Args>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001036 iterator
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001037 emplace_hint(const_iterator __p, _Args&& ...__args);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001038
Howard Hinnant74279a52010-09-04 23:28:19 +00001039#endif // _LIBCPP_HAS_NO_VARIADICS
1040
Howard Hinnantc834c512011-11-29 18:15:50 +00001041 template <class _Pp,
1042 class = typename enable_if<is_constructible<value_type, _Pp>::value>::type>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001043 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc834c512011-11-29 18:15:50 +00001044 pair<iterator, bool> insert(_Pp&& __p)
1045 {return __tree_.__insert_unique(_VSTD::forward<_Pp>(__p));}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001046
Howard Hinnantc834c512011-11-29 18:15:50 +00001047 template <class _Pp,
1048 class = typename enable_if<is_constructible<value_type, _Pp>::value>::type>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001049 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc834c512011-11-29 18:15:50 +00001050 iterator insert(const_iterator __pos, _Pp&& __p)
1051 {return __tree_.__insert_unique(__pos.__i_, _VSTD::forward<_Pp>(__p));}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001052
Howard Hinnant74279a52010-09-04 23:28:19 +00001053#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +00001054
Howard Hinnant756c69b2010-09-22 16:48:34 +00001055 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001056 pair<iterator, bool>
1057 insert(const value_type& __v) {return __tree_.__insert_unique(__v);}
1058
Howard Hinnant756c69b2010-09-22 16:48:34 +00001059 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001060 iterator
1061 insert(const_iterator __p, const value_type& __v)
1062 {return __tree_.__insert_unique(__p.__i_, __v);}
1063
1064 template <class _InputIterator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001065 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001066 void insert(_InputIterator __f, _InputIterator __l)
1067 {
1068 for (const_iterator __e = cend(); __f != __l; ++__f)
1069 insert(__e.__i_, *__f);
1070 }
1071
Howard Hinnant33711792011-08-12 21:56:02 +00001072#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1073
Howard Hinnant756c69b2010-09-22 16:48:34 +00001074 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001075 void insert(initializer_list<value_type> __il)
1076 {insert(__il.begin(), __il.end());}
1077
Howard Hinnant33711792011-08-12 21:56:02 +00001078#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1079
Howard Hinnant756c69b2010-09-22 16:48:34 +00001080 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001081 iterator erase(const_iterator __p) {return __tree_.erase(__p.__i_);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001082 _LIBCPP_INLINE_VISIBILITY
Marshall Clow22ea5b82015-05-10 13:35:00 +00001083 iterator erase(iterator __p) {return __tree_.erase(__p.__i_);}
1084 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001085 size_type erase(const key_type& __k)
1086 {return __tree_.__erase_unique(__k);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001087 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001088 iterator erase(const_iterator __f, const_iterator __l)
1089 {return __tree_.erase(__f.__i_, __l.__i_);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001090 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001091 void clear() _NOEXCEPT {__tree_.clear();}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001092
Howard Hinnant756c69b2010-09-22 16:48:34 +00001093 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001094 void swap(map& __m)
1095 _NOEXCEPT_(__is_nothrow_swappable<__base>::value)
1096 {__tree_.swap(__m.__tree_);}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001097
Howard Hinnant756c69b2010-09-22 16:48:34 +00001098 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001099 iterator find(const key_type& __k) {return __tree_.find(__k);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001100 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001101 const_iterator find(const key_type& __k) const {return __tree_.find(__k);}
Marshall Clowebb57322013-08-13 22:18:47 +00001102#if _LIBCPP_STD_VER > 11
1103 template <typename _K2>
1104 _LIBCPP_INLINE_VISIBILITY
1105 typename enable_if<__is_transparent<_Compare, _K2>::value,iterator>::type
1106 find(const _K2& __k) {return __tree_.find(__k);}
1107 template <typename _K2>
1108 _LIBCPP_INLINE_VISIBILITY
1109 typename enable_if<__is_transparent<_Compare, _K2>::value,const_iterator>::type
1110 find(const _K2& __k) const {return __tree_.find(__k);}
1111#endif
1112
Howard Hinnant756c69b2010-09-22 16:48:34 +00001113 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001114 size_type count(const key_type& __k) const
1115 {return __tree_.__count_unique(__k);}
Marshall Clowe6a5f522014-08-24 23:54:16 +00001116#if _LIBCPP_STD_VER > 11
1117 template <typename _K2>
1118 _LIBCPP_INLINE_VISIBILITY
1119 typename enable_if<__is_transparent<_Compare, _K2>::value,size_type>::type
1120 count(const _K2& __k) {return __tree_.__count_unique(__k);}
1121#endif
Howard Hinnant756c69b2010-09-22 16:48:34 +00001122 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001123 iterator lower_bound(const key_type& __k)
1124 {return __tree_.lower_bound(__k);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001125 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001126 const_iterator lower_bound(const key_type& __k) const
1127 {return __tree_.lower_bound(__k);}
Marshall Clowebb57322013-08-13 22:18:47 +00001128#if _LIBCPP_STD_VER > 11
1129 template <typename _K2>
1130 _LIBCPP_INLINE_VISIBILITY
1131 typename enable_if<__is_transparent<_Compare, _K2>::value,iterator>::type
1132 lower_bound(const _K2& __k) {return __tree_.lower_bound(__k);}
1133
1134 template <typename _K2>
1135 _LIBCPP_INLINE_VISIBILITY
1136 typename enable_if<__is_transparent<_Compare, _K2>::value,const_iterator>::type
1137 lower_bound(const _K2& __k) const {return __tree_.lower_bound(__k);}
1138#endif
1139
Howard Hinnant756c69b2010-09-22 16:48:34 +00001140 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001141 iterator upper_bound(const key_type& __k)
1142 {return __tree_.upper_bound(__k);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001143 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001144 const_iterator upper_bound(const key_type& __k) const
1145 {return __tree_.upper_bound(__k);}
Marshall Clowebb57322013-08-13 22:18:47 +00001146#if _LIBCPP_STD_VER > 11
1147 template <typename _K2>
1148 _LIBCPP_INLINE_VISIBILITY
1149 typename enable_if<__is_transparent<_Compare, _K2>::value,iterator>::type
1150 upper_bound(const _K2& __k) {return __tree_.upper_bound(__k);}
1151 template <typename _K2>
1152 _LIBCPP_INLINE_VISIBILITY
1153 typename enable_if<__is_transparent<_Compare, _K2>::value,const_iterator>::type
1154 upper_bound(const _K2& __k) const {return __tree_.upper_bound(__k);}
1155#endif
1156
Howard Hinnant756c69b2010-09-22 16:48:34 +00001157 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001158 pair<iterator,iterator> equal_range(const key_type& __k)
1159 {return __tree_.__equal_range_unique(__k);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001160 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001161 pair<const_iterator,const_iterator> equal_range(const key_type& __k) const
1162 {return __tree_.__equal_range_unique(__k);}
Marshall Clowebb57322013-08-13 22:18:47 +00001163#if _LIBCPP_STD_VER > 11
1164 template <typename _K2>
1165 _LIBCPP_INLINE_VISIBILITY
1166 typename enable_if<__is_transparent<_Compare, _K2>::value,pair<iterator,iterator>>::type
1167 equal_range(const _K2& __k) {return __tree_.__equal_range_unique(__k);}
1168 template <typename _K2>
1169 _LIBCPP_INLINE_VISIBILITY
1170 typename enable_if<__is_transparent<_Compare, _K2>::value,pair<const_iterator,const_iterator>>::type
1171 equal_range(const _K2& __k) const {return __tree_.__equal_range_unique(__k);}
1172#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001173
1174private:
1175 typedef typename __base::__node __node;
1176 typedef typename __base::__node_allocator __node_allocator;
1177 typedef typename __base::__node_pointer __node_pointer;
1178 typedef typename __base::__node_const_pointer __node_const_pointer;
1179 typedef typename __base::__node_base_pointer __node_base_pointer;
1180 typedef typename __base::__node_base_const_pointer __node_base_const_pointer;
Howard Hinnantc834c512011-11-29 18:15:50 +00001181 typedef __map_node_destructor<__node_allocator> _Dp;
1182 typedef unique_ptr<__node, _Dp> __node_holder;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001183
Howard Hinnant74279a52010-09-04 23:28:19 +00001184#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +00001185 __node_holder __construct_node();
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001186 template <class _A0>
Howard Hinnantac7e7482013-07-04 20:59:16 +00001187 __node_holder __construct_node(_A0&& __a0);
1188 __node_holder __construct_node_with_key(key_type&& __k);
Howard Hinnant74279a52010-09-04 23:28:19 +00001189#ifndef _LIBCPP_HAS_NO_VARIADICS
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001190 template <class _A0, class _A1, class ..._Args>
1191 __node_holder __construct_node(_A0&& __a0, _A1&& __a1, _Args&& ...__args);
Howard Hinnant74279a52010-09-04 23:28:19 +00001192#endif // _LIBCPP_HAS_NO_VARIADICS
Howard Hinnantc51e1022010-05-11 19:42:16 +00001193#endif
Howard Hinnantac7e7482013-07-04 20:59:16 +00001194 __node_holder __construct_node_with_key(const key_type& __k);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001195
1196 __node_base_pointer&
1197 __find_equal_key(__node_base_pointer& __parent, const key_type& __k);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001198 __node_base_const_pointer
1199 __find_equal_key(__node_base_const_pointer& __parent, const key_type& __k) const;
1200};
1201
1202// Find place to insert if __k doesn't exist
1203// Set __parent to parent of null leaf
1204// Return reference to null leaf
1205// If __k exists, set parent to node of __k and return reference to node of __k
1206template <class _Key, class _Tp, class _Compare, class _Allocator>
1207typename map<_Key, _Tp, _Compare, _Allocator>::__node_base_pointer&
1208map<_Key, _Tp, _Compare, _Allocator>::__find_equal_key(__node_base_pointer& __parent,
1209 const key_type& __k)
1210{
1211 __node_pointer __nd = __tree_.__root();
1212 if (__nd != nullptr)
1213 {
1214 while (true)
1215 {
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001216 if (__tree_.value_comp().key_comp()(__k, __nd->__value_.__cc.first))
Howard Hinnantc51e1022010-05-11 19:42:16 +00001217 {
1218 if (__nd->__left_ != nullptr)
1219 __nd = static_cast<__node_pointer>(__nd->__left_);
1220 else
1221 {
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001222 __parent = static_cast<__node_base_pointer>(__nd);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001223 return __parent->__left_;
1224 }
1225 }
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001226 else if (__tree_.value_comp().key_comp()(__nd->__value_.__cc.first, __k))
Howard Hinnantc51e1022010-05-11 19:42:16 +00001227 {
1228 if (__nd->__right_ != nullptr)
1229 __nd = static_cast<__node_pointer>(__nd->__right_);
1230 else
1231 {
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001232 __parent = static_cast<__node_base_pointer>(__nd);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001233 return __parent->__right_;
1234 }
1235 }
1236 else
1237 {
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001238 __parent = static_cast<__node_base_pointer>(__nd);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001239 return __parent;
1240 }
1241 }
1242 }
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001243 __parent = static_cast<__node_base_pointer>(__tree_.__end_node());
Howard Hinnantc51e1022010-05-11 19:42:16 +00001244 return __parent->__left_;
1245}
1246
Howard Hinnantc51e1022010-05-11 19:42:16 +00001247// Find __k
1248// Set __parent to parent of null leaf and
1249// return reference to null leaf iv __k does not exist.
1250// If __k exists, set parent to node of __k and return reference to node of __k
1251template <class _Key, class _Tp, class _Compare, class _Allocator>
1252typename map<_Key, _Tp, _Compare, _Allocator>::__node_base_const_pointer
1253map<_Key, _Tp, _Compare, _Allocator>::__find_equal_key(__node_base_const_pointer& __parent,
1254 const key_type& __k) const
1255{
1256 __node_const_pointer __nd = __tree_.__root();
1257 if (__nd != nullptr)
1258 {
1259 while (true)
1260 {
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001261 if (__tree_.value_comp().key_comp()(__k, __nd->__value_.__cc.first))
Howard Hinnantc51e1022010-05-11 19:42:16 +00001262 {
1263 if (__nd->__left_ != nullptr)
1264 __nd = static_cast<__node_pointer>(__nd->__left_);
1265 else
1266 {
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001267 __parent = static_cast<__node_base_pointer>(__nd);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001268 return const_cast<const __node_base_const_pointer&>(__parent->__left_);
1269 }
1270 }
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001271 else if (__tree_.value_comp().key_comp()(__nd->__value_.__cc.first, __k))
Howard Hinnantc51e1022010-05-11 19:42:16 +00001272 {
1273 if (__nd->__right_ != nullptr)
1274 __nd = static_cast<__node_pointer>(__nd->__right_);
1275 else
1276 {
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001277 __parent = static_cast<__node_base_pointer>(__nd);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001278 return const_cast<const __node_base_const_pointer&>(__parent->__right_);
1279 }
1280 }
1281 else
1282 {
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001283 __parent = static_cast<__node_base_pointer>(__nd);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001284 return __parent;
1285 }
1286 }
1287 }
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001288 __parent = static_cast<__node_base_pointer>(__tree_.__end_node());
Howard Hinnantc51e1022010-05-11 19:42:16 +00001289 return const_cast<const __node_base_const_pointer&>(__parent->__left_);
1290}
1291
Howard Hinnant74279a52010-09-04 23:28:19 +00001292#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +00001293
1294template <class _Key, class _Tp, class _Compare, class _Allocator>
1295map<_Key, _Tp, _Compare, _Allocator>::map(map&& __m, const allocator_type& __a)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001296 : __tree_(_VSTD::move(__m.__tree_), __a)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001297{
1298 if (__a != __m.get_allocator())
1299 {
1300 const_iterator __e = cend();
1301 while (!__m.empty())
1302 __tree_.__insert_unique(__e.__i_,
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001303 _VSTD::move(__m.__tree_.remove(__m.begin().__i_)->__value_));
Howard Hinnantc51e1022010-05-11 19:42:16 +00001304 }
1305}
1306
1307template <class _Key, class _Tp, class _Compare, class _Allocator>
1308typename map<_Key, _Tp, _Compare, _Allocator>::__node_holder
1309map<_Key, _Tp, _Compare, _Allocator>::__construct_node()
1310{
1311 __node_allocator& __na = __tree_.__node_alloc();
Howard Hinnantc834c512011-11-29 18:15:50 +00001312 __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001313 __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__cc.first));
Howard Hinnantc51e1022010-05-11 19:42:16 +00001314 __h.get_deleter().__first_constructed = true;
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001315 __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__cc.second));
Howard Hinnantc51e1022010-05-11 19:42:16 +00001316 __h.get_deleter().__second_constructed = true;
1317 return __h;
1318}
1319
1320template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001321template <class _A0>
Howard Hinnantac7e7482013-07-04 20:59:16 +00001322typename map<_Key, _Tp, _Compare, _Allocator>::__node_holder
Howard Hinnantc51e1022010-05-11 19:42:16 +00001323map<_Key, _Tp, _Compare, _Allocator>::__construct_node(_A0&& __a0)
1324{
1325 __node_allocator& __na = __tree_.__node_alloc();
Howard Hinnantc834c512011-11-29 18:15:50 +00001326 __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001327 __node_traits::construct(__na, _VSTD::addressof(__h->__value_), _VSTD::forward<_A0>(__a0));
Howard Hinnantc51e1022010-05-11 19:42:16 +00001328 __h.get_deleter().__first_constructed = true;
1329 __h.get_deleter().__second_constructed = true;
1330 return __h;
1331}
1332
1333template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnantac7e7482013-07-04 20:59:16 +00001334typename map<_Key, _Tp, _Compare, _Allocator>::__node_holder
1335map<_Key, _Tp, _Compare, _Allocator>::__construct_node_with_key(key_type&& __k)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001336{
1337 __node_allocator& __na = __tree_.__node_alloc();
Howard Hinnantc834c512011-11-29 18:15:50 +00001338 __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
Howard Hinnantac7e7482013-07-04 20:59:16 +00001339 __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__cc.first), _VSTD::move(__k));
Howard Hinnantc51e1022010-05-11 19:42:16 +00001340 __h.get_deleter().__first_constructed = true;
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001341 __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__cc.second));
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001342 __h.get_deleter().__second_constructed = true;
Howard Hinnanta31e9682013-08-22 18:29:50 +00001343 return __h;
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001344}
1345
1346#ifndef _LIBCPP_HAS_NO_VARIADICS
1347
1348template <class _Key, class _Tp, class _Compare, class _Allocator>
1349template <class _A0, class _A1, class ..._Args>
1350typename map<_Key, _Tp, _Compare, _Allocator>::__node_holder
1351map<_Key, _Tp, _Compare, _Allocator>::__construct_node(_A0&& __a0, _A1&& __a1, _Args&& ...__args)
1352{
1353 __node_allocator& __na = __tree_.__node_alloc();
1354 __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
1355 __node_traits::construct(__na, _VSTD::addressof(__h->__value_),
1356 _VSTD::forward<_A0>(__a0), _VSTD::forward<_A1>(__a1),
1357 _VSTD::forward<_Args>(__args)...);
1358 __h.get_deleter().__first_constructed = true;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001359 __h.get_deleter().__second_constructed = true;
1360 return __h;
1361}
1362
Howard Hinnant74279a52010-09-04 23:28:19 +00001363#endif // _LIBCPP_HAS_NO_VARIADICS
1364
Howard Hinnantac7e7482013-07-04 20:59:16 +00001365#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +00001366
1367template <class _Key, class _Tp, class _Compare, class _Allocator>
1368typename map<_Key, _Tp, _Compare, _Allocator>::__node_holder
Howard Hinnantac7e7482013-07-04 20:59:16 +00001369map<_Key, _Tp, _Compare, _Allocator>::__construct_node_with_key(const key_type& __k)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001370{
1371 __node_allocator& __na = __tree_.__node_alloc();
Howard Hinnantc834c512011-11-29 18:15:50 +00001372 __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001373 __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__cc.first), __k);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001374 __h.get_deleter().__first_constructed = true;
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001375 __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__cc.second));
Howard Hinnantc51e1022010-05-11 19:42:16 +00001376 __h.get_deleter().__second_constructed = true;
Howard Hinnanta31e9682013-08-22 18:29:50 +00001377 return _VSTD::move(__h); // explicitly moved for C++03
Howard Hinnantc51e1022010-05-11 19:42:16 +00001378}
1379
Howard Hinnantc51e1022010-05-11 19:42:16 +00001380template <class _Key, class _Tp, class _Compare, class _Allocator>
1381_Tp&
1382map<_Key, _Tp, _Compare, _Allocator>::operator[](const key_type& __k)
1383{
1384 __node_base_pointer __parent;
1385 __node_base_pointer& __child = __find_equal_key(__parent, __k);
1386 __node_pointer __r = static_cast<__node_pointer>(__child);
1387 if (__child == nullptr)
1388 {
Howard Hinnantac7e7482013-07-04 20:59:16 +00001389 __node_holder __h = __construct_node_with_key(__k);
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001390 __tree_.__insert_node_at(__parent, __child, static_cast<__node_base_pointer>(__h.get()));
Howard Hinnantc51e1022010-05-11 19:42:16 +00001391 __r = __h.release();
1392 }
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001393 return __r->__value_.__cc.second;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001394}
1395
Howard Hinnant74279a52010-09-04 23:28:19 +00001396#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +00001397
1398template <class _Key, class _Tp, class _Compare, class _Allocator>
1399_Tp&
1400map<_Key, _Tp, _Compare, _Allocator>::operator[](key_type&& __k)
1401{
1402 __node_base_pointer __parent;
1403 __node_base_pointer& __child = __find_equal_key(__parent, __k);
1404 __node_pointer __r = static_cast<__node_pointer>(__child);
1405 if (__child == nullptr)
1406 {
Howard Hinnantac7e7482013-07-04 20:59:16 +00001407 __node_holder __h = __construct_node_with_key(_VSTD::move(__k));
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001408 __tree_.__insert_node_at(__parent, __child, static_cast<__node_base_pointer>(__h.get()));
Howard Hinnantc51e1022010-05-11 19:42:16 +00001409 __r = __h.release();
1410 }
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001411 return __r->__value_.__cc.second;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001412}
1413
Howard Hinnant74279a52010-09-04 23:28:19 +00001414#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +00001415
1416template <class _Key, class _Tp, class _Compare, class _Allocator>
1417_Tp&
1418map<_Key, _Tp, _Compare, _Allocator>::at(const key_type& __k)
1419{
1420 __node_base_pointer __parent;
1421 __node_base_pointer& __child = __find_equal_key(__parent, __k);
Howard Hinnant72f73582010-08-11 17:04:31 +00001422#ifndef _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +00001423 if (__child == nullptr)
1424 throw out_of_range("map::at: key not found");
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001425#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001426 return static_cast<__node_pointer>(__child)->__value_.__cc.second;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001427}
1428
1429template <class _Key, class _Tp, class _Compare, class _Allocator>
1430const _Tp&
1431map<_Key, _Tp, _Compare, _Allocator>::at(const key_type& __k) const
1432{
1433 __node_base_const_pointer __parent;
1434 __node_base_const_pointer __child = __find_equal_key(__parent, __k);
Howard Hinnant72f73582010-08-11 17:04:31 +00001435#ifndef _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +00001436 if (__child == nullptr)
1437 throw out_of_range("map::at: key not found");
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001438#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001439 return static_cast<__node_const_pointer>(__child)->__value_.__cc.second;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001440}
1441
Howard Hinnant74279a52010-09-04 23:28:19 +00001442#if !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001443
1444template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001445template <class ..._Args>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001446pair<typename map<_Key, _Tp, _Compare, _Allocator>::iterator, bool>
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001447map<_Key, _Tp, _Compare, _Allocator>::emplace(_Args&& ...__args)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001448{
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001449 __node_holder __h = __construct_node(_VSTD::forward<_Args>(__args)...);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001450 pair<iterator, bool> __r = __tree_.__node_insert_unique(__h.get());
1451 if (__r.second)
1452 __h.release();
1453 return __r;
1454}
1455
1456template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001457template <class ..._Args>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001458typename map<_Key, _Tp, _Compare, _Allocator>::iterator
1459map<_Key, _Tp, _Compare, _Allocator>::emplace_hint(const_iterator __p,
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001460 _Args&& ...__args)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001461{
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001462 __node_holder __h = __construct_node(_VSTD::forward<_Args>(__args)...);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001463 iterator __r = __tree_.__node_insert_unique(__p.__i_, __h.get());
1464 if (__r.__i_.__ptr_ == __h.get())
1465 __h.release();
1466 return __r;
1467}
1468
Howard Hinnant74279a52010-09-04 23:28:19 +00001469#endif // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001470
1471template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001472inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001473bool
1474operator==(const map<_Key, _Tp, _Compare, _Allocator>& __x,
1475 const map<_Key, _Tp, _Compare, _Allocator>& __y)
1476{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001477 return __x.size() == __y.size() && _VSTD::equal(__x.begin(), __x.end(), __y.begin());
Howard Hinnantc51e1022010-05-11 19:42:16 +00001478}
1479
1480template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001481inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001482bool
1483operator< (const map<_Key, _Tp, _Compare, _Allocator>& __x,
1484 const map<_Key, _Tp, _Compare, _Allocator>& __y)
1485{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001486 return _VSTD::lexicographical_compare(__x.begin(), __x.end(), __y.begin(), __y.end());
Howard Hinnantc51e1022010-05-11 19:42:16 +00001487}
1488
1489template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001490inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001491bool
1492operator!=(const map<_Key, _Tp, _Compare, _Allocator>& __x,
1493 const map<_Key, _Tp, _Compare, _Allocator>& __y)
1494{
1495 return !(__x == __y);
1496}
1497
1498template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001499inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001500bool
1501operator> (const map<_Key, _Tp, _Compare, _Allocator>& __x,
1502 const map<_Key, _Tp, _Compare, _Allocator>& __y)
1503{
1504 return __y < __x;
1505}
1506
1507template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001508inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001509bool
1510operator>=(const map<_Key, _Tp, _Compare, _Allocator>& __x,
1511 const map<_Key, _Tp, _Compare, _Allocator>& __y)
1512{
1513 return !(__x < __y);
1514}
1515
1516template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001517inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001518bool
1519operator<=(const map<_Key, _Tp, _Compare, _Allocator>& __x,
1520 const map<_Key, _Tp, _Compare, _Allocator>& __y)
1521{
1522 return !(__y < __x);
1523}
1524
1525template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001526inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001527void
1528swap(map<_Key, _Tp, _Compare, _Allocator>& __x,
1529 map<_Key, _Tp, _Compare, _Allocator>& __y)
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001530 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
Howard Hinnantc51e1022010-05-11 19:42:16 +00001531{
1532 __x.swap(__y);
1533}
1534
1535template <class _Key, class _Tp, class _Compare = less<_Key>,
1536 class _Allocator = allocator<pair<const _Key, _Tp> > >
Howard Hinnanta37d3cf2013-08-12 18:38:34 +00001537class _LIBCPP_TYPE_VIS_ONLY multimap
Howard Hinnantc51e1022010-05-11 19:42:16 +00001538{
1539public:
1540 // types:
1541 typedef _Key key_type;
1542 typedef _Tp mapped_type;
1543 typedef pair<const key_type, mapped_type> value_type;
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001544 typedef pair<key_type, mapped_type> __nc_value_type;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001545 typedef _Compare key_compare;
1546 typedef _Allocator allocator_type;
1547 typedef value_type& reference;
1548 typedef const value_type& const_reference;
1549
Howard Hinnanta37d3cf2013-08-12 18:38:34 +00001550 class _LIBCPP_TYPE_VIS_ONLY value_compare
Howard Hinnantc51e1022010-05-11 19:42:16 +00001551 : public binary_function<value_type, value_type, bool>
1552 {
1553 friend class multimap;
1554 protected:
1555 key_compare comp;
1556
Howard Hinnant756c69b2010-09-22 16:48:34 +00001557 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001558 value_compare(key_compare c) : comp(c) {}
1559 public:
Howard Hinnant756c69b2010-09-22 16:48:34 +00001560 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001561 bool operator()(const value_type& __x, const value_type& __y) const
1562 {return comp(__x.first, __y.first);}
1563 };
1564
1565private:
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001566
Howard Hinnant89f8b792013-09-30 19:08:22 +00001567 typedef _VSTD::__value_type<key_type, mapped_type> __value_type;
Howard Hinnant90b91592013-07-05 18:06:00 +00001568 typedef __map_value_compare<key_type, __value_type, key_compare> __vc;
Marshall Clow940e01c2015-04-07 05:21:38 +00001569 typedef typename __rebind_alloc_helper<allocator_traits<allocator_type>,
1570 __value_type>::type __allocator_type;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001571 typedef __tree<__value_type, __vc, __allocator_type> __base;
1572 typedef typename __base::__node_traits __node_traits;
1573 typedef allocator_traits<allocator_type> __alloc_traits;
1574
1575 __base __tree_;
1576
1577public:
1578 typedef typename __alloc_traits::pointer pointer;
1579 typedef typename __alloc_traits::const_pointer const_pointer;
1580 typedef typename __alloc_traits::size_type size_type;
1581 typedef typename __alloc_traits::difference_type difference_type;
1582 typedef __map_iterator<typename __base::iterator> iterator;
1583 typedef __map_const_iterator<typename __base::const_iterator> const_iterator;
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001584 typedef _VSTD::reverse_iterator<iterator> reverse_iterator;
1585 typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001586
Howard Hinnant756c69b2010-09-22 16:48:34 +00001587 _LIBCPP_INLINE_VISIBILITY
Marshall Clow7086a5a2014-03-10 04:50:10 +00001588 multimap()
1589 _NOEXCEPT_(
1590 is_nothrow_default_constructible<allocator_type>::value &&
1591 is_nothrow_default_constructible<key_compare>::value &&
1592 is_nothrow_copy_constructible<key_compare>::value)
1593 : __tree_(__vc(key_compare())) {}
1594
1595 _LIBCPP_INLINE_VISIBILITY
1596 explicit multimap(const key_compare& __comp)
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001597 _NOEXCEPT_(
1598 is_nothrow_default_constructible<allocator_type>::value &&
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001599 is_nothrow_copy_constructible<key_compare>::value)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001600 : __tree_(__vc(__comp)) {}
1601
Howard Hinnant756c69b2010-09-22 16:48:34 +00001602 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001603 explicit multimap(const key_compare& __comp, const allocator_type& __a)
1604 : __tree_(__vc(__comp), __a) {}
1605
1606 template <class _InputIterator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001607 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001608 multimap(_InputIterator __f, _InputIterator __l,
1609 const key_compare& __comp = key_compare())
1610 : __tree_(__vc(__comp))
1611 {
1612 insert(__f, __l);
1613 }
1614
1615 template <class _InputIterator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001616 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001617 multimap(_InputIterator __f, _InputIterator __l,
1618 const key_compare& __comp, const allocator_type& __a)
1619 : __tree_(__vc(__comp), __a)
1620 {
1621 insert(__f, __l);
1622 }
1623
Marshall Clow300abfb2013-09-11 01:15:47 +00001624#if _LIBCPP_STD_VER > 11
1625 template <class _InputIterator>
1626 _LIBCPP_INLINE_VISIBILITY
1627 multimap(_InputIterator __f, _InputIterator __l, const allocator_type& __a)
1628 : multimap(__f, __l, key_compare(), __a) {}
1629#endif
1630
Howard Hinnant756c69b2010-09-22 16:48:34 +00001631 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001632 multimap(const multimap& __m)
1633 : __tree_(__m.__tree_.value_comp(),
1634 __alloc_traits::select_on_container_copy_construction(__m.__tree_.__alloc()))
1635 {
1636 insert(__m.begin(), __m.end());
1637 }
1638
Howard Hinnantd3a657f2011-07-01 19:24:36 +00001639 _LIBCPP_INLINE_VISIBILITY
1640 multimap& operator=(const multimap& __m)
1641 {
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001642#if __cplusplus >= 201103L
Howard Hinnantd3a657f2011-07-01 19:24:36 +00001643 __tree_ = __m.__tree_;
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001644#else
Marshall Clowdb3cfcb2014-02-08 04:03:14 +00001645 if (this != &__m) {
1646 __tree_.clear();
1647 __tree_.value_comp() = __m.__tree_.value_comp();
1648 __tree_.__copy_assign_alloc(__m.__tree_);
1649 insert(__m.begin(), __m.end());
1650 }
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001651#endif
Howard Hinnantd3a657f2011-07-01 19:24:36 +00001652 return *this;
1653 }
1654
Howard Hinnant74279a52010-09-04 23:28:19 +00001655#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +00001656
Howard Hinnant756c69b2010-09-22 16:48:34 +00001657 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001658 multimap(multimap&& __m)
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001659 _NOEXCEPT_(is_nothrow_move_constructible<__base>::value)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001660 : __tree_(_VSTD::move(__m.__tree_))
Howard Hinnantc51e1022010-05-11 19:42:16 +00001661 {
1662 }
1663
1664 multimap(multimap&& __m, const allocator_type& __a);
1665
Howard Hinnant756c69b2010-09-22 16:48:34 +00001666 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant33711792011-08-12 21:56:02 +00001667 multimap& operator=(multimap&& __m)
1668 _NOEXCEPT_(is_nothrow_move_assignable<__base>::value)
1669 {
1670 __tree_ = _VSTD::move(__m.__tree_);
1671 return *this;
1672 }
1673
1674#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
1675
1676#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1677
1678 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001679 multimap(initializer_list<value_type> __il, const key_compare& __comp = key_compare())
1680 : __tree_(__vc(__comp))
1681 {
1682 insert(__il.begin(), __il.end());
1683 }
1684
Howard Hinnant756c69b2010-09-22 16:48:34 +00001685 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001686 multimap(initializer_list<value_type> __il, const key_compare& __comp, const allocator_type& __a)
1687 : __tree_(__vc(__comp), __a)
1688 {
1689 insert(__il.begin(), __il.end());
1690 }
1691
Marshall Clow300abfb2013-09-11 01:15:47 +00001692#if _LIBCPP_STD_VER > 11
1693 _LIBCPP_INLINE_VISIBILITY
1694 multimap(initializer_list<value_type> __il, const allocator_type& __a)
1695 : multimap(__il, key_compare(), __a) {}
1696#endif
1697
Howard Hinnant756c69b2010-09-22 16:48:34 +00001698 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001699 multimap& operator=(initializer_list<value_type> __il)
1700 {
1701 __tree_.__assign_multi(__il.begin(), __il.end());
1702 return *this;
1703 }
Howard Hinnant33711792011-08-12 21:56:02 +00001704
1705#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantc51e1022010-05-11 19:42:16 +00001706
Howard Hinnant756c69b2010-09-22 16:48:34 +00001707 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001708 explicit multimap(const allocator_type& __a)
1709 : __tree_(__a)
1710 {
1711 }
1712
Howard Hinnant756c69b2010-09-22 16:48:34 +00001713 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001714 multimap(const multimap& __m, const allocator_type& __a)
1715 : __tree_(__m.__tree_.value_comp(), __a)
1716 {
1717 insert(__m.begin(), __m.end());
1718 }
1719
Howard Hinnant756c69b2010-09-22 16:48:34 +00001720 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001721 iterator begin() _NOEXCEPT {return __tree_.begin();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001722 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001723 const_iterator begin() const _NOEXCEPT {return __tree_.begin();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001724 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001725 iterator end() _NOEXCEPT {return __tree_.end();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001726 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001727 const_iterator end() const _NOEXCEPT {return __tree_.end();}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001728
Howard Hinnant756c69b2010-09-22 16:48:34 +00001729 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001730 reverse_iterator rbegin() _NOEXCEPT {return reverse_iterator(end());}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001731 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001732 const_reverse_iterator rbegin() const _NOEXCEPT
1733 {return const_reverse_iterator(end());}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001734 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001735 reverse_iterator rend() _NOEXCEPT {return reverse_iterator(begin());}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001736 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001737 const_reverse_iterator rend() const _NOEXCEPT
1738 {return const_reverse_iterator(begin());}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001739
Howard Hinnant756c69b2010-09-22 16:48:34 +00001740 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001741 const_iterator cbegin() const _NOEXCEPT {return begin();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001742 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001743 const_iterator cend() const _NOEXCEPT {return end();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001744 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001745 const_reverse_iterator crbegin() const _NOEXCEPT {return rbegin();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001746 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001747 const_reverse_iterator crend() const _NOEXCEPT {return rend();}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001748
Howard Hinnant756c69b2010-09-22 16:48:34 +00001749 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001750 bool empty() const _NOEXCEPT {return __tree_.size() == 0;}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001751 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001752 size_type size() const _NOEXCEPT {return __tree_.size();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001753 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001754 size_type max_size() const _NOEXCEPT {return __tree_.max_size();}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001755
Howard Hinnant756c69b2010-09-22 16:48:34 +00001756 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001757 allocator_type get_allocator() const _NOEXCEPT {return __tree_.__alloc();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001758 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001759 key_compare key_comp() const {return __tree_.value_comp().key_comp();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001760 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001761 value_compare value_comp() const
1762 {return value_compare(__tree_.value_comp().key_comp());}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001763
Howard Hinnant74279a52010-09-04 23:28:19 +00001764#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant74279a52010-09-04 23:28:19 +00001765#ifndef _LIBCPP_HAS_NO_VARIADICS
1766
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001767 template <class ..._Args>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001768 iterator
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001769 emplace(_Args&& ...__args);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001770
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001771 template <class ..._Args>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001772 iterator
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001773 emplace_hint(const_iterator __p, _Args&& ...__args);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001774
Howard Hinnant74279a52010-09-04 23:28:19 +00001775#endif // _LIBCPP_HAS_NO_VARIADICS
1776
Howard Hinnantc834c512011-11-29 18:15:50 +00001777 template <class _Pp,
1778 class = typename enable_if<is_constructible<value_type, _Pp>::value>::type>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001779 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc834c512011-11-29 18:15:50 +00001780 iterator insert(_Pp&& __p)
1781 {return __tree_.__insert_multi(_VSTD::forward<_Pp>(__p));}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001782
Howard Hinnantc834c512011-11-29 18:15:50 +00001783 template <class _Pp,
1784 class = typename enable_if<is_constructible<value_type, _Pp>::value>::type>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001785 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc834c512011-11-29 18:15:50 +00001786 iterator insert(const_iterator __pos, _Pp&& __p)
1787 {return __tree_.__insert_multi(__pos.__i_, _VSTD::forward<_Pp>(__p));}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001788
Howard Hinnant74279a52010-09-04 23:28:19 +00001789#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +00001790
Howard Hinnant756c69b2010-09-22 16:48:34 +00001791 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001792 iterator insert(const value_type& __v) {return __tree_.__insert_multi(__v);}
1793
Howard Hinnant756c69b2010-09-22 16:48:34 +00001794 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001795 iterator insert(const_iterator __p, const value_type& __v)
1796 {return __tree_.__insert_multi(__p.__i_, __v);}
1797
1798 template <class _InputIterator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001799 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001800 void insert(_InputIterator __f, _InputIterator __l)
1801 {
1802 for (const_iterator __e = cend(); __f != __l; ++__f)
1803 __tree_.__insert_multi(__e.__i_, *__f);
1804 }
1805
Howard Hinnant33711792011-08-12 21:56:02 +00001806#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1807
Howard Hinnant756c69b2010-09-22 16:48:34 +00001808 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001809 void insert(initializer_list<value_type> __il)
1810 {insert(__il.begin(), __il.end());}
1811
Howard Hinnant33711792011-08-12 21:56:02 +00001812#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1813
Howard Hinnant756c69b2010-09-22 16:48:34 +00001814 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001815 iterator erase(const_iterator __p) {return __tree_.erase(__p.__i_);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001816 _LIBCPP_INLINE_VISIBILITY
Marshall Clow22ea5b82015-05-10 13:35:00 +00001817 iterator erase(iterator __p) {return __tree_.erase(__p.__i_);}
1818 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001819 size_type erase(const key_type& __k) {return __tree_.__erase_multi(__k);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001820 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001821 iterator erase(const_iterator __f, const_iterator __l)
1822 {return __tree_.erase(__f.__i_, __l.__i_);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001823 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001824 void clear() {__tree_.clear();}
1825
Howard Hinnant756c69b2010-09-22 16:48:34 +00001826 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001827 void swap(multimap& __m)
1828 _NOEXCEPT_(__is_nothrow_swappable<__base>::value)
1829 {__tree_.swap(__m.__tree_);}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001830
Howard Hinnant756c69b2010-09-22 16:48:34 +00001831 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001832 iterator find(const key_type& __k) {return __tree_.find(__k);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001833 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001834 const_iterator find(const key_type& __k) const {return __tree_.find(__k);}
Marshall Clowebb57322013-08-13 22:18:47 +00001835#if _LIBCPP_STD_VER > 11
1836 template <typename _K2>
1837 _LIBCPP_INLINE_VISIBILITY
1838 typename enable_if<__is_transparent<_Compare, _K2>::value,iterator>::type
1839 find(const _K2& __k) {return __tree_.find(__k);}
1840 template <typename _K2>
1841 _LIBCPP_INLINE_VISIBILITY
1842 typename enable_if<__is_transparent<_Compare, _K2>::value,const_iterator>::type
1843 find(const _K2& __k) const {return __tree_.find(__k);}
1844#endif
1845
Howard Hinnant756c69b2010-09-22 16:48:34 +00001846 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001847 size_type count(const key_type& __k) const
1848 {return __tree_.__count_multi(__k);}
Marshall Clowe6a5f522014-08-24 23:54:16 +00001849#if _LIBCPP_STD_VER > 11
1850 template <typename _K2>
1851 _LIBCPP_INLINE_VISIBILITY
1852 typename enable_if<__is_transparent<_Compare, _K2>::value,size_type>::type
1853 count(const _K2& __k) {return __tree_.__count_multi(__k);}
1854#endif
Howard Hinnant756c69b2010-09-22 16:48:34 +00001855 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001856 iterator lower_bound(const key_type& __k)
1857 {return __tree_.lower_bound(__k);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001858 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001859 const_iterator lower_bound(const key_type& __k) const
1860 {return __tree_.lower_bound(__k);}
Marshall Clowebb57322013-08-13 22:18:47 +00001861#if _LIBCPP_STD_VER > 11
1862 template <typename _K2>
1863 _LIBCPP_INLINE_VISIBILITY
1864 typename enable_if<__is_transparent<_Compare, _K2>::value,iterator>::type
1865 lower_bound(const _K2& __k) {return __tree_.lower_bound(__k);}
1866
1867 template <typename _K2>
1868 _LIBCPP_INLINE_VISIBILITY
1869 typename enable_if<__is_transparent<_Compare, _K2>::value,const_iterator>::type
1870 lower_bound(const _K2& __k) const {return __tree_.lower_bound(__k);}
1871#endif
1872
Howard Hinnant756c69b2010-09-22 16:48:34 +00001873 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001874 iterator upper_bound(const key_type& __k)
1875 {return __tree_.upper_bound(__k);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001876 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001877 const_iterator upper_bound(const key_type& __k) const
1878 {return __tree_.upper_bound(__k);}
Marshall Clowebb57322013-08-13 22:18:47 +00001879#if _LIBCPP_STD_VER > 11
1880 template <typename _K2>
1881 _LIBCPP_INLINE_VISIBILITY
1882 typename enable_if<__is_transparent<_Compare, _K2>::value,iterator>::type
1883 upper_bound(const _K2& __k) {return __tree_.upper_bound(__k);}
1884 template <typename _K2>
1885 _LIBCPP_INLINE_VISIBILITY
1886 typename enable_if<__is_transparent<_Compare, _K2>::value,const_iterator>::type
1887 upper_bound(const _K2& __k) const {return __tree_.upper_bound(__k);}
1888#endif
1889
Howard Hinnant756c69b2010-09-22 16:48:34 +00001890 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001891 pair<iterator,iterator> equal_range(const key_type& __k)
1892 {return __tree_.__equal_range_multi(__k);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001893 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001894 pair<const_iterator,const_iterator> equal_range(const key_type& __k) const
1895 {return __tree_.__equal_range_multi(__k);}
Marshall Clowebb57322013-08-13 22:18:47 +00001896#if _LIBCPP_STD_VER > 11
1897 template <typename _K2>
1898 _LIBCPP_INLINE_VISIBILITY
1899 typename enable_if<__is_transparent<_Compare, _K2>::value,pair<iterator,iterator>>::type
1900 equal_range(const _K2& __k) {return __tree_.__equal_range_multi(__k);}
1901 template <typename _K2>
1902 _LIBCPP_INLINE_VISIBILITY
1903 typename enable_if<__is_transparent<_Compare, _K2>::value,pair<const_iterator,const_iterator>>::type
1904 equal_range(const _K2& __k) const {return __tree_.__equal_range_multi(__k);}
1905#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001906
1907private:
1908 typedef typename __base::__node __node;
1909 typedef typename __base::__node_allocator __node_allocator;
1910 typedef typename __base::__node_pointer __node_pointer;
1911 typedef typename __base::__node_const_pointer __node_const_pointer;
Howard Hinnantc834c512011-11-29 18:15:50 +00001912 typedef __map_node_destructor<__node_allocator> _Dp;
1913 typedef unique_ptr<__node, _Dp> __node_holder;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001914
Howard Hinnant74279a52010-09-04 23:28:19 +00001915#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +00001916 __node_holder __construct_node();
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001917 template <class _A0>
Howard Hinnantac7e7482013-07-04 20:59:16 +00001918 __node_holder
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001919 __construct_node(_A0&& __a0);
Howard Hinnant74279a52010-09-04 23:28:19 +00001920#ifndef _LIBCPP_HAS_NO_VARIADICS
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001921 template <class _A0, class _A1, class ..._Args>
1922 __node_holder __construct_node(_A0&& __a0, _A1&& __a1, _Args&& ...__args);
Howard Hinnant74279a52010-09-04 23:28:19 +00001923#endif // _LIBCPP_HAS_NO_VARIADICS
1924#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +00001925};
1926
Howard Hinnant74279a52010-09-04 23:28:19 +00001927#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +00001928
1929template <class _Key, class _Tp, class _Compare, class _Allocator>
1930multimap<_Key, _Tp, _Compare, _Allocator>::multimap(multimap&& __m, const allocator_type& __a)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001931 : __tree_(_VSTD::move(__m.__tree_), __a)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001932{
1933 if (__a != __m.get_allocator())
1934 {
1935 const_iterator __e = cend();
1936 while (!__m.empty())
1937 __tree_.__insert_multi(__e.__i_,
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001938 _VSTD::move(__m.__tree_.remove(__m.begin().__i_)->__value_));
Howard Hinnantc51e1022010-05-11 19:42:16 +00001939 }
1940}
1941
1942template <class _Key, class _Tp, class _Compare, class _Allocator>
1943typename multimap<_Key, _Tp, _Compare, _Allocator>::__node_holder
1944multimap<_Key, _Tp, _Compare, _Allocator>::__construct_node()
1945{
1946 __node_allocator& __na = __tree_.__node_alloc();
Howard Hinnantc834c512011-11-29 18:15:50 +00001947 __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001948 __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__cc.first));
Howard Hinnantc51e1022010-05-11 19:42:16 +00001949 __h.get_deleter().__first_constructed = true;
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001950 __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__cc.second));
Howard Hinnantc51e1022010-05-11 19:42:16 +00001951 __h.get_deleter().__second_constructed = true;
1952 return __h;
1953}
1954
1955template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001956template <class _A0>
Howard Hinnantac7e7482013-07-04 20:59:16 +00001957typename multimap<_Key, _Tp, _Compare, _Allocator>::__node_holder
Howard Hinnantc51e1022010-05-11 19:42:16 +00001958multimap<_Key, _Tp, _Compare, _Allocator>::__construct_node(_A0&& __a0)
1959{
1960 __node_allocator& __na = __tree_.__node_alloc();
Howard Hinnantc834c512011-11-29 18:15:50 +00001961 __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001962 __node_traits::construct(__na, _VSTD::addressof(__h->__value_), _VSTD::forward<_A0>(__a0));
Howard Hinnantc51e1022010-05-11 19:42:16 +00001963 __h.get_deleter().__first_constructed = true;
1964 __h.get_deleter().__second_constructed = true;
1965 return __h;
1966}
1967
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001968#ifndef _LIBCPP_HAS_NO_VARIADICS
1969
1970template <class _Key, class _Tp, class _Compare, class _Allocator>
1971template <class _A0, class _A1, class ..._Args>
1972typename multimap<_Key, _Tp, _Compare, _Allocator>::__node_holder
1973multimap<_Key, _Tp, _Compare, _Allocator>::__construct_node(_A0&& __a0, _A1&& __a1, _Args&& ...__args)
1974{
1975 __node_allocator& __na = __tree_.__node_alloc();
1976 __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
1977 __node_traits::construct(__na, _VSTD::addressof(__h->__value_),
1978 _VSTD::forward<_A0>(__a0), _VSTD::forward<_A1>(__a1),
1979 _VSTD::forward<_Args>(__args)...);
1980 __h.get_deleter().__first_constructed = true;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001981 __h.get_deleter().__second_constructed = true;
1982 return __h;
1983}
1984
Howard Hinnant74279a52010-09-04 23:28:19 +00001985#endif // _LIBCPP_HAS_NO_VARIADICS
1986#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +00001987
Howard Hinnant74279a52010-09-04 23:28:19 +00001988#if !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001989
1990template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001991template <class ..._Args>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001992typename multimap<_Key, _Tp, _Compare, _Allocator>::iterator
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001993multimap<_Key, _Tp, _Compare, _Allocator>::emplace(_Args&& ...__args)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001994{
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001995 __node_holder __h = __construct_node(_VSTD::forward<_Args>(__args)...);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001996 iterator __r = __tree_.__node_insert_multi(__h.get());
1997 __h.release();
1998 return __r;
1999}
2000
2001template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant29eb9b82012-05-25 22:04:21 +00002002template <class ..._Args>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002003typename multimap<_Key, _Tp, _Compare, _Allocator>::iterator
2004multimap<_Key, _Tp, _Compare, _Allocator>::emplace_hint(const_iterator __p,
Howard Hinnantc51e1022010-05-11 19:42:16 +00002005 _Args&& ...__args)
2006{
Howard Hinnant29eb9b82012-05-25 22:04:21 +00002007 __node_holder __h = __construct_node(_VSTD::forward<_Args>(__args)...);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002008 iterator __r = __tree_.__node_insert_multi(__p.__i_, __h.get());
2009 __h.release();
2010 return __r;
2011}
2012
Howard Hinnant74279a52010-09-04 23:28:19 +00002013#endif // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
Howard Hinnantc51e1022010-05-11 19:42:16 +00002014
2015template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00002016inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002017bool
2018operator==(const multimap<_Key, _Tp, _Compare, _Allocator>& __x,
2019 const multimap<_Key, _Tp, _Compare, _Allocator>& __y)
2020{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00002021 return __x.size() == __y.size() && _VSTD::equal(__x.begin(), __x.end(), __y.begin());
Howard Hinnantc51e1022010-05-11 19:42:16 +00002022}
2023
2024template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00002025inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002026bool
2027operator< (const multimap<_Key, _Tp, _Compare, _Allocator>& __x,
2028 const multimap<_Key, _Tp, _Compare, _Allocator>& __y)
2029{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00002030 return _VSTD::lexicographical_compare(__x.begin(), __x.end(), __y.begin(), __y.end());
Howard Hinnantc51e1022010-05-11 19:42:16 +00002031}
2032
2033template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00002034inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002035bool
2036operator!=(const multimap<_Key, _Tp, _Compare, _Allocator>& __x,
2037 const multimap<_Key, _Tp, _Compare, _Allocator>& __y)
2038{
2039 return !(__x == __y);
2040}
2041
2042template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00002043inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002044bool
2045operator> (const multimap<_Key, _Tp, _Compare, _Allocator>& __x,
2046 const multimap<_Key, _Tp, _Compare, _Allocator>& __y)
2047{
2048 return __y < __x;
2049}
2050
2051template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00002052inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002053bool
2054operator>=(const multimap<_Key, _Tp, _Compare, _Allocator>& __x,
2055 const multimap<_Key, _Tp, _Compare, _Allocator>& __y)
2056{
2057 return !(__x < __y);
2058}
2059
2060template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00002061inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002062bool
2063operator<=(const multimap<_Key, _Tp, _Compare, _Allocator>& __x,
2064 const multimap<_Key, _Tp, _Compare, _Allocator>& __y)
2065{
2066 return !(__y < __x);
2067}
2068
2069template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00002070inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002071void
2072swap(multimap<_Key, _Tp, _Compare, _Allocator>& __x,
2073 multimap<_Key, _Tp, _Compare, _Allocator>& __y)
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00002074 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
Howard Hinnantc51e1022010-05-11 19:42:16 +00002075{
2076 __x.swap(__y);
2077}
2078
2079_LIBCPP_END_NAMESPACE_STD
2080
2081#endif // _LIBCPP_MAP