blob: 4c79662e1ba57461b08aee5c61b20992ee825cfa [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>
431
Howard Hinnantaaaa52b2011-10-17 20:05:10 +0000432#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000433#pragma GCC system_header
Howard Hinnantaaaa52b2011-10-17 20:05:10 +0000434#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000435
436_LIBCPP_BEGIN_NAMESPACE_STD
437
Howard Hinnant90b91592013-07-05 18:06:00 +0000438template <class _Key, class _CP, class _Compare, bool = is_empty<_Compare>::value
Howard Hinnantd0aabf82011-12-11 20:31:33 +0000439#if __has_feature(is_final)
440 && !__is_final(_Compare)
441#endif
442 >
Howard Hinnantc51e1022010-05-11 19:42:16 +0000443class __map_value_compare
444 : private _Compare
445{
Howard Hinnantc51e1022010-05-11 19:42:16 +0000446public:
Howard Hinnant756c69b2010-09-22 16:48:34 +0000447 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000448 __map_value_compare()
449 _NOEXCEPT_(is_nothrow_default_constructible<_Compare>::value)
450 : _Compare() {}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000451 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000452 __map_value_compare(_Compare c)
453 _NOEXCEPT_(is_nothrow_copy_constructible<_Compare>::value)
454 : _Compare(c) {}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000455 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000456 const _Compare& key_comp() const _NOEXCEPT {return *this;}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000457 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000458 bool operator()(const _CP& __x, const _CP& __y) const
Howard Hinnant90b91592013-07-05 18:06:00 +0000459 {return static_cast<const _Compare&>(*this)(__x.__cc.first, __y.__cc.first);}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000460 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000461 bool operator()(const _CP& __x, const _Key& __y) const
Howard Hinnant90b91592013-07-05 18:06:00 +0000462 {return static_cast<const _Compare&>(*this)(__x.__cc.first, __y);}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000463 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000464 bool operator()(const _Key& __x, const _CP& __y) const
Howard Hinnant90b91592013-07-05 18:06:00 +0000465 {return static_cast<const _Compare&>(*this)(__x, __y.__cc.first);}
Marshall Clowebb57322013-08-13 22:18:47 +0000466
467#if _LIBCPP_STD_VER > 11
468 template <typename _K2>
469 _LIBCPP_INLINE_VISIBILITY
470 typename enable_if<__is_transparent<_Compare, _K2>::value, bool>::type
471 operator () ( const _K2& __x, const _CP& __y ) const
472 {return static_cast<const _Compare&>(*this) (__x, __y.__cc.first);}
473
474 template <typename _K2>
475 _LIBCPP_INLINE_VISIBILITY
476 typename enable_if<__is_transparent<_Compare, _K2>::value, bool>::type
477 operator () (const _CP& __x, const _K2& __y) const
478 {return static_cast<const _Compare&>(*this) (__x.__cc.first, __y);}
479#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000480};
481
Howard Hinnant90b91592013-07-05 18:06:00 +0000482template <class _Key, class _CP, class _Compare>
483class __map_value_compare<_Key, _CP, _Compare, false>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000484{
485 _Compare comp;
486
Howard Hinnantc51e1022010-05-11 19:42:16 +0000487public:
Howard Hinnant756c69b2010-09-22 16:48:34 +0000488 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000489 __map_value_compare()
490 _NOEXCEPT_(is_nothrow_default_constructible<_Compare>::value)
491 : comp() {}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000492 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000493 __map_value_compare(_Compare c)
494 _NOEXCEPT_(is_nothrow_copy_constructible<_Compare>::value)
495 : comp(c) {}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000496 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000497 const _Compare& key_comp() const _NOEXCEPT {return comp;}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000498
Howard Hinnant756c69b2010-09-22 16:48:34 +0000499 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000500 bool operator()(const _CP& __x, const _CP& __y) const
Howard Hinnant90b91592013-07-05 18:06:00 +0000501 {return comp(__x.__cc.first, __y.__cc.first);}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000502 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000503 bool operator()(const _CP& __x, const _Key& __y) const
Howard Hinnant90b91592013-07-05 18:06:00 +0000504 {return comp(__x.__cc.first, __y);}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000505 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000506 bool operator()(const _Key& __x, const _CP& __y) const
Howard Hinnant90b91592013-07-05 18:06:00 +0000507 {return comp(__x, __y.__cc.first);}
Marshall Clowebb57322013-08-13 22:18:47 +0000508
509#if _LIBCPP_STD_VER > 11
510 template <typename _K2>
511 _LIBCPP_INLINE_VISIBILITY
512 typename enable_if<__is_transparent<_Compare, _K2>::value, bool>::type
513 operator () ( const _K2& __x, const _CP& __y ) const
514 {return comp (__x, __y.__cc.first);}
515
516 template <typename _K2>
517 _LIBCPP_INLINE_VISIBILITY
518 typename enable_if<__is_transparent<_Compare, _K2>::value, bool>::type
519 operator () (const _CP& __x, const _K2& __y) const
520 {return comp (__x.__cc.first, __y);}
521#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000522};
523
524template <class _Allocator>
525class __map_node_destructor
526{
527 typedef _Allocator allocator_type;
528 typedef allocator_traits<allocator_type> __alloc_traits;
529 typedef typename __alloc_traits::value_type::value_type value_type;
530public:
531 typedef typename __alloc_traits::pointer pointer;
532private:
Howard Hinnant2d0046b2013-06-19 21:29:40 +0000533 typedef typename value_type::value_type::first_type first_type;
534 typedef typename value_type::value_type::second_type second_type;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000535
536 allocator_type& __na_;
537
538 __map_node_destructor& operator=(const __map_node_destructor&);
539
540public:
541 bool __first_constructed;
542 bool __second_constructed;
543
Howard Hinnant756c69b2010-09-22 16:48:34 +0000544 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000545 explicit __map_node_destructor(allocator_type& __na) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +0000546 : __na_(__na),
547 __first_constructed(false),
548 __second_constructed(false)
549 {}
550
Howard Hinnant74279a52010-09-04 23:28:19 +0000551#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant756c69b2010-09-22 16:48:34 +0000552 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000553 __map_node_destructor(__tree_node_destructor<allocator_type>&& __x) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +0000554 : __na_(__x.__na_),
555 __first_constructed(__x.__value_constructed),
556 __second_constructed(__x.__value_constructed)
557 {
558 __x.__value_constructed = false;
559 }
Howard Hinnant5dc89112010-09-04 23:46:48 +0000560#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +0000561
Howard Hinnant756c69b2010-09-22 16:48:34 +0000562 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000563 void operator()(pointer __p) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +0000564 {
565 if (__second_constructed)
Howard Hinnant2d0046b2013-06-19 21:29:40 +0000566 __alloc_traits::destroy(__na_, _VSTD::addressof(__p->__value_.__cc.second));
Howard Hinnantc51e1022010-05-11 19:42:16 +0000567 if (__first_constructed)
Howard Hinnant2d0046b2013-06-19 21:29:40 +0000568 __alloc_traits::destroy(__na_, _VSTD::addressof(__p->__value_.__cc.first));
Howard Hinnantc51e1022010-05-11 19:42:16 +0000569 if (__p)
570 __alloc_traits::deallocate(__na_, __p, 1);
571 }
572};
573
Howard Hinnant944510a2011-06-14 19:58:17 +0000574template <class _Key, class _Tp, class _Compare, class _Allocator>
575 class map;
576template <class _Key, class _Tp, class _Compare, class _Allocator>
577 class multimap;
578template <class _TreeIterator> class __map_const_iterator;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000579
Howard Hinnant89f8b792013-09-30 19:08:22 +0000580#if __cplusplus >= 201103L
581
582template <class _Key, class _Tp>
583union __value_type
584{
585 typedef _Key key_type;
586 typedef _Tp mapped_type;
587 typedef pair<const key_type, mapped_type> value_type;
588 typedef pair<key_type, mapped_type> __nc_value_type;
589
590 value_type __cc;
591 __nc_value_type __nc;
592
593 template <class ..._Args>
594 _LIBCPP_INLINE_VISIBILITY
595 __value_type(_Args&& ...__args)
596 : __cc(std::forward<_Args>(__args)...) {}
597
598 _LIBCPP_INLINE_VISIBILITY
599 __value_type(const __value_type& __v)
600 : __cc(__v.__cc) {}
601
602 _LIBCPP_INLINE_VISIBILITY
603 __value_type(__value_type& __v)
604 : __cc(__v.__cc) {}
605
606 _LIBCPP_INLINE_VISIBILITY
607 __value_type(__value_type&& __v)
608 : __nc(std::move(__v.__nc)) {}
609
610 _LIBCPP_INLINE_VISIBILITY
611 __value_type& operator=(const __value_type& __v)
612 {__nc = __v.__cc; return *this;}
613
614 _LIBCPP_INLINE_VISIBILITY
615 __value_type& operator=(__value_type&& __v)
616 {__nc = std::move(__v.__nc); return *this;}
617
618 _LIBCPP_INLINE_VISIBILITY
619 ~__value_type() {__cc.~value_type();}
620};
621
622#else
623
624template <class _Key, class _Tp>
625struct __value_type
626{
627 typedef _Key key_type;
628 typedef _Tp mapped_type;
629 typedef pair<const key_type, mapped_type> value_type;
630
631 value_type __cc;
632
633 _LIBCPP_INLINE_VISIBILITY
634 __value_type() {}
635
636 template <class _A0>
637 _LIBCPP_INLINE_VISIBILITY
638 __value_type(const _A0& __a0)
639 : __cc(__a0) {}
640
641 template <class _A0, class _A1>
642 _LIBCPP_INLINE_VISIBILITY
643 __value_type(const _A0& __a0, const _A1& __a1)
644 : __cc(__a0, __a1) {}
645};
646
647#endif
648
Eric Fiselier44f9fd02015-03-03 20:10:01 +0000649template <class _Tp>
650struct __extract_key_value_types;
651
652template <class _Key, class _Tp>
653struct __extract_key_value_types<__value_type<_Key, _Tp> >
654{
655 typedef _Key const __key_type;
656 typedef _Tp __mapped_type;
657};
658
Howard Hinnantc51e1022010-05-11 19:42:16 +0000659template <class _TreeIterator>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +0000660class _LIBCPP_TYPE_VIS_ONLY __map_iterator
Howard Hinnantc51e1022010-05-11 19:42:16 +0000661{
662 _TreeIterator __i_;
663
664 typedef typename _TreeIterator::__pointer_traits __pointer_traits;
Eric Fiselier44f9fd02015-03-03 20:10:01 +0000665 typedef typename _TreeIterator::value_type __value_type;
666 typedef typename __extract_key_value_types<__value_type>::__key_type __key_type;
667 typedef typename __extract_key_value_types<__value_type>::__mapped_type __mapped_type;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000668public:
669 typedef bidirectional_iterator_tag iterator_category;
Howard Hinnantb2e8a422011-02-27 18:02:02 +0000670 typedef pair<__key_type, __mapped_type> value_type;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000671 typedef typename _TreeIterator::difference_type difference_type;
672 typedef value_type& reference;
673 typedef typename __pointer_traits::template
674#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
675 rebind<value_type>
676#else
677 rebind<value_type>::other
678#endif
679 pointer;
680
Howard Hinnant756c69b2010-09-22 16:48:34 +0000681 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000682 __map_iterator() _NOEXCEPT {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000683
Howard Hinnant756c69b2010-09-22 16:48:34 +0000684 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000685 __map_iterator(_TreeIterator __i) _NOEXCEPT : __i_(__i) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000686
Howard Hinnant756c69b2010-09-22 16:48:34 +0000687 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2d0046b2013-06-19 21:29:40 +0000688 reference operator*() const {return __i_->__cc;}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000689 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2d0046b2013-06-19 21:29:40 +0000690 pointer operator->() const {return pointer_traits<pointer>::pointer_to(__i_->__cc);}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000691
Howard Hinnant756c69b2010-09-22 16:48:34 +0000692 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000693 __map_iterator& operator++() {++__i_; return *this;}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000694 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000695 __map_iterator operator++(int)
696 {
697 __map_iterator __t(*this);
698 ++(*this);
699 return __t;
700 }
701
Howard Hinnant756c69b2010-09-22 16:48:34 +0000702 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000703 __map_iterator& operator--() {--__i_; return *this;}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000704 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000705 __map_iterator operator--(int)
706 {
707 __map_iterator __t(*this);
708 --(*this);
709 return __t;
710 }
711
Howard Hinnant756c69b2010-09-22 16:48:34 +0000712 friend _LIBCPP_INLINE_VISIBILITY
713 bool operator==(const __map_iterator& __x, const __map_iterator& __y)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000714 {return __x.__i_ == __y.__i_;}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000715 friend
716 _LIBCPP_INLINE_VISIBILITY
717 bool operator!=(const __map_iterator& __x, const __map_iterator& __y)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000718 {return __x.__i_ != __y.__i_;}
719
Howard Hinnanta37d3cf2013-08-12 18:38:34 +0000720 template <class, class, class, class> friend class _LIBCPP_TYPE_VIS_ONLY map;
721 template <class, class, class, class> friend class _LIBCPP_TYPE_VIS_ONLY multimap;
722 template <class> friend class _LIBCPP_TYPE_VIS_ONLY __map_const_iterator;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000723};
724
725template <class _TreeIterator>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +0000726class _LIBCPP_TYPE_VIS_ONLY __map_const_iterator
Howard Hinnantc51e1022010-05-11 19:42:16 +0000727{
728 _TreeIterator __i_;
729
730 typedef typename _TreeIterator::__pointer_traits __pointer_traits;
Eric Fiselier44f9fd02015-03-03 20:10:01 +0000731 typedef typename _TreeIterator::value_type __value_type;
732 typedef typename __extract_key_value_types<__value_type>::__key_type __key_type;
733 typedef typename __extract_key_value_types<__value_type>::__mapped_type __mapped_type;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000734public:
735 typedef bidirectional_iterator_tag iterator_category;
Howard Hinnantb2e8a422011-02-27 18:02:02 +0000736 typedef pair<__key_type, __mapped_type> value_type;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000737 typedef typename _TreeIterator::difference_type difference_type;
738 typedef const value_type& reference;
739 typedef typename __pointer_traits::template
740#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
Howard Hinnant73f3c8a2011-04-11 02:18:41 +0000741 rebind<const value_type>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000742#else
Howard Hinnant73f3c8a2011-04-11 02:18:41 +0000743 rebind<const value_type>::other
Howard Hinnantc51e1022010-05-11 19:42:16 +0000744#endif
745 pointer;
746
Howard Hinnant756c69b2010-09-22 16:48:34 +0000747 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000748 __map_const_iterator() _NOEXCEPT {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000749
Howard Hinnant756c69b2010-09-22 16:48:34 +0000750 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000751 __map_const_iterator(_TreeIterator __i) _NOEXCEPT : __i_(__i) {}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000752 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier44f9fd02015-03-03 20:10:01 +0000753 __map_const_iterator(__map_iterator<
754 typename _TreeIterator::__non_const_iterator> __i) _NOEXCEPT
755 : __i_(__i.__i_) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000756
Howard Hinnant756c69b2010-09-22 16:48:34 +0000757 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2d0046b2013-06-19 21:29:40 +0000758 reference operator*() const {return __i_->__cc;}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000759 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2d0046b2013-06-19 21:29:40 +0000760 pointer operator->() const {return pointer_traits<pointer>::pointer_to(__i_->__cc);}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000761
Howard Hinnant756c69b2010-09-22 16:48:34 +0000762 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000763 __map_const_iterator& operator++() {++__i_; return *this;}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000764 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000765 __map_const_iterator operator++(int)
766 {
767 __map_const_iterator __t(*this);
768 ++(*this);
769 return __t;
770 }
771
Howard Hinnant756c69b2010-09-22 16:48:34 +0000772 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000773 __map_const_iterator& operator--() {--__i_; return *this;}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000774 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000775 __map_const_iterator operator--(int)
776 {
777 __map_const_iterator __t(*this);
778 --(*this);
779 return __t;
780 }
781
Howard Hinnant756c69b2010-09-22 16:48:34 +0000782 friend _LIBCPP_INLINE_VISIBILITY
783 bool operator==(const __map_const_iterator& __x, const __map_const_iterator& __y)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000784 {return __x.__i_ == __y.__i_;}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000785 friend _LIBCPP_INLINE_VISIBILITY
786 bool operator!=(const __map_const_iterator& __x, const __map_const_iterator& __y)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000787 {return __x.__i_ != __y.__i_;}
788
Howard Hinnanta37d3cf2013-08-12 18:38:34 +0000789 template <class, class, class, class> friend class _LIBCPP_TYPE_VIS_ONLY map;
790 template <class, class, class, class> friend class _LIBCPP_TYPE_VIS_ONLY multimap;
791 template <class, class, class> friend class _LIBCPP_TYPE_VIS_ONLY __tree_const_iterator;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000792};
793
794template <class _Key, class _Tp, class _Compare = less<_Key>,
795 class _Allocator = allocator<pair<const _Key, _Tp> > >
Howard Hinnanta37d3cf2013-08-12 18:38:34 +0000796class _LIBCPP_TYPE_VIS_ONLY map
Howard Hinnantc51e1022010-05-11 19:42:16 +0000797{
798public:
799 // types:
800 typedef _Key key_type;
801 typedef _Tp mapped_type;
802 typedef pair<const key_type, mapped_type> value_type;
Howard Hinnant2d0046b2013-06-19 21:29:40 +0000803 typedef pair<key_type, mapped_type> __nc_value_type;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000804 typedef _Compare key_compare;
805 typedef _Allocator allocator_type;
806 typedef value_type& reference;
807 typedef const value_type& const_reference;
808
Howard Hinnanta37d3cf2013-08-12 18:38:34 +0000809 class _LIBCPP_TYPE_VIS_ONLY value_compare
Howard Hinnantc51e1022010-05-11 19:42:16 +0000810 : public binary_function<value_type, value_type, bool>
811 {
812 friend class map;
813 protected:
814 key_compare comp;
815
Howard Hinnant756c69b2010-09-22 16:48:34 +0000816 _LIBCPP_INLINE_VISIBILITY value_compare(key_compare c) : comp(c) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000817 public:
Howard Hinnant756c69b2010-09-22 16:48:34 +0000818 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000819 bool operator()(const value_type& __x, const value_type& __y) const
820 {return comp(__x.first, __y.first);}
821 };
822
823private:
Howard Hinnant2d0046b2013-06-19 21:29:40 +0000824
Howard Hinnant89f8b792013-09-30 19:08:22 +0000825 typedef _VSTD::__value_type<key_type, mapped_type> __value_type;
Howard Hinnant90b91592013-07-05 18:06:00 +0000826 typedef __map_value_compare<key_type, __value_type, key_compare> __vc;
Marshall Clow940e01c2015-04-07 05:21:38 +0000827 typedef typename __rebind_alloc_helper<allocator_traits<allocator_type>,
828 __value_type>::type __allocator_type;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000829 typedef __tree<__value_type, __vc, __allocator_type> __base;
830 typedef typename __base::__node_traits __node_traits;
831 typedef allocator_traits<allocator_type> __alloc_traits;
832
833 __base __tree_;
834
835public:
836 typedef typename __alloc_traits::pointer pointer;
837 typedef typename __alloc_traits::const_pointer const_pointer;
838 typedef typename __alloc_traits::size_type size_type;
839 typedef typename __alloc_traits::difference_type difference_type;
Eric Fiselier44f9fd02015-03-03 20:10:01 +0000840 typedef __map_iterator<typename __base::iterator> iterator;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000841 typedef __map_const_iterator<typename __base::const_iterator> const_iterator;
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000842 typedef _VSTD::reverse_iterator<iterator> reverse_iterator;
843 typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000844
Howard Hinnant756c69b2010-09-22 16:48:34 +0000845 _LIBCPP_INLINE_VISIBILITY
Marshall Clow7086a5a2014-03-10 04:50:10 +0000846 map()
847 _NOEXCEPT_(
848 is_nothrow_default_constructible<allocator_type>::value &&
849 is_nothrow_default_constructible<key_compare>::value &&
850 is_nothrow_copy_constructible<key_compare>::value)
851 : __tree_(__vc(key_compare())) {}
852
853 _LIBCPP_INLINE_VISIBILITY
854 explicit map(const key_compare& __comp)
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000855 _NOEXCEPT_(
856 is_nothrow_default_constructible<allocator_type>::value &&
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000857 is_nothrow_copy_constructible<key_compare>::value)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000858 : __tree_(__vc(__comp)) {}
859
Howard Hinnant756c69b2010-09-22 16:48:34 +0000860 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000861 explicit map(const key_compare& __comp, const allocator_type& __a)
862 : __tree_(__vc(__comp), __a) {}
863
864 template <class _InputIterator>
Howard Hinnant756c69b2010-09-22 16:48:34 +0000865 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000866 map(_InputIterator __f, _InputIterator __l,
867 const key_compare& __comp = key_compare())
868 : __tree_(__vc(__comp))
869 {
870 insert(__f, __l);
871 }
872
873 template <class _InputIterator>
Howard Hinnant756c69b2010-09-22 16:48:34 +0000874 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000875 map(_InputIterator __f, _InputIterator __l,
876 const key_compare& __comp, const allocator_type& __a)
877 : __tree_(__vc(__comp), __a)
878 {
879 insert(__f, __l);
880 }
881
Marshall Clow300abfb2013-09-11 01:15:47 +0000882#if _LIBCPP_STD_VER > 11
883 template <class _InputIterator>
884 _LIBCPP_INLINE_VISIBILITY
885 map(_InputIterator __f, _InputIterator __l, const allocator_type& __a)
886 : map(__f, __l, key_compare(), __a) {}
887#endif
888
Howard Hinnant756c69b2010-09-22 16:48:34 +0000889 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000890 map(const map& __m)
891 : __tree_(__m.__tree_)
892 {
893 insert(__m.begin(), __m.end());
894 }
895
Howard Hinnantd3a657f2011-07-01 19:24:36 +0000896 _LIBCPP_INLINE_VISIBILITY
897 map& operator=(const map& __m)
898 {
Howard Hinnant2d0046b2013-06-19 21:29:40 +0000899#if __cplusplus >= 201103L
Howard Hinnantd3a657f2011-07-01 19:24:36 +0000900 __tree_ = __m.__tree_;
Howard Hinnant2d0046b2013-06-19 21:29:40 +0000901#else
Marshall Clowdb3cfcb2014-02-08 04:03:14 +0000902 if (this != &__m) {
903 __tree_.clear();
904 __tree_.value_comp() = __m.__tree_.value_comp();
905 __tree_.__copy_assign_alloc(__m.__tree_);
906 insert(__m.begin(), __m.end());
907 }
Howard Hinnant2d0046b2013-06-19 21:29:40 +0000908#endif
Howard Hinnantd3a657f2011-07-01 19:24:36 +0000909 return *this;
910 }
911
Howard Hinnant74279a52010-09-04 23:28:19 +0000912#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +0000913
Howard Hinnant756c69b2010-09-22 16:48:34 +0000914 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000915 map(map&& __m)
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000916 _NOEXCEPT_(is_nothrow_move_constructible<__base>::value)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000917 : __tree_(_VSTD::move(__m.__tree_))
Howard Hinnantc51e1022010-05-11 19:42:16 +0000918 {
919 }
920
921 map(map&& __m, const allocator_type& __a);
922
Howard Hinnant756c69b2010-09-22 16:48:34 +0000923 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant33711792011-08-12 21:56:02 +0000924 map& operator=(map&& __m)
925 _NOEXCEPT_(is_nothrow_move_assignable<__base>::value)
926 {
927 __tree_ = _VSTD::move(__m.__tree_);
928 return *this;
929 }
930
931#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
932
933#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
934
935 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000936 map(initializer_list<value_type> __il, const key_compare& __comp = key_compare())
937 : __tree_(__vc(__comp))
938 {
939 insert(__il.begin(), __il.end());
940 }
941
Howard Hinnant756c69b2010-09-22 16:48:34 +0000942 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000943 map(initializer_list<value_type> __il, const key_compare& __comp, const allocator_type& __a)
944 : __tree_(__vc(__comp), __a)
945 {
946 insert(__il.begin(), __il.end());
947 }
948
Marshall Clow300abfb2013-09-11 01:15:47 +0000949#if _LIBCPP_STD_VER > 11
950 _LIBCPP_INLINE_VISIBILITY
951 map(initializer_list<value_type> __il, const allocator_type& __a)
952 : map(__il, key_compare(), __a) {}
953#endif
954
Howard Hinnant756c69b2010-09-22 16:48:34 +0000955 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000956 map& operator=(initializer_list<value_type> __il)
957 {
958 __tree_.__assign_unique(__il.begin(), __il.end());
959 return *this;
960 }
961
Howard Hinnant33711792011-08-12 21:56:02 +0000962#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000963
Howard Hinnant756c69b2010-09-22 16:48:34 +0000964 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000965 explicit map(const allocator_type& __a)
966 : __tree_(__a)
967 {
968 }
969
Howard Hinnant756c69b2010-09-22 16:48:34 +0000970 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000971 map(const map& __m, const allocator_type& __a)
972 : __tree_(__m.__tree_.value_comp(), __a)
973 {
974 insert(__m.begin(), __m.end());
975 }
976
Howard Hinnant756c69b2010-09-22 16:48:34 +0000977 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000978 iterator begin() _NOEXCEPT {return __tree_.begin();}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000979 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000980 const_iterator begin() const _NOEXCEPT {return __tree_.begin();}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000981 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000982 iterator end() _NOEXCEPT {return __tree_.end();}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000983 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000984 const_iterator end() const _NOEXCEPT {return __tree_.end();}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000985
Howard Hinnant756c69b2010-09-22 16:48:34 +0000986 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000987 reverse_iterator rbegin() _NOEXCEPT {return reverse_iterator(end());}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000988 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000989 const_reverse_iterator rbegin() const _NOEXCEPT
990 {return const_reverse_iterator(end());}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000991 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000992 reverse_iterator rend() _NOEXCEPT
993 {return reverse_iterator(begin());}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000994 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000995 const_reverse_iterator rend() const _NOEXCEPT
996 {return const_reverse_iterator(begin());}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000997
Howard Hinnant756c69b2010-09-22 16:48:34 +0000998 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000999 const_iterator cbegin() const _NOEXCEPT {return begin();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001000 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001001 const_iterator cend() const _NOEXCEPT {return end();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001002 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001003 const_reverse_iterator crbegin() const _NOEXCEPT {return rbegin();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001004 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001005 const_reverse_iterator crend() const _NOEXCEPT {return rend();}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001006
Howard Hinnant756c69b2010-09-22 16:48:34 +00001007 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001008 bool empty() const _NOEXCEPT {return __tree_.size() == 0;}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001009 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001010 size_type size() const _NOEXCEPT {return __tree_.size();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001011 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001012 size_type max_size() const _NOEXCEPT {return __tree_.max_size();}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001013
1014 mapped_type& operator[](const key_type& __k);
Howard Hinnant74279a52010-09-04 23:28:19 +00001015#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +00001016 mapped_type& operator[](key_type&& __k);
1017#endif
1018
1019 mapped_type& at(const key_type& __k);
1020 const mapped_type& at(const key_type& __k) const;
1021
Howard Hinnant756c69b2010-09-22 16:48:34 +00001022 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001023 allocator_type get_allocator() const _NOEXCEPT {return __tree_.__alloc();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001024 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001025 key_compare key_comp() const {return __tree_.value_comp().key_comp();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001026 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001027 value_compare value_comp() const {return value_compare(__tree_.value_comp().key_comp());}
1028
Howard Hinnant74279a52010-09-04 23:28:19 +00001029#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant74279a52010-09-04 23:28:19 +00001030#ifndef _LIBCPP_HAS_NO_VARIADICS
1031
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001032 template <class ..._Args>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001033 pair<iterator, bool>
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001034 emplace(_Args&& ...__args);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001035
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001036 template <class ..._Args>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001037 iterator
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001038 emplace_hint(const_iterator __p, _Args&& ...__args);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001039
Howard Hinnant74279a52010-09-04 23:28:19 +00001040#endif // _LIBCPP_HAS_NO_VARIADICS
1041
Howard Hinnantc834c512011-11-29 18:15:50 +00001042 template <class _Pp,
1043 class = typename enable_if<is_constructible<value_type, _Pp>::value>::type>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001044 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc834c512011-11-29 18:15:50 +00001045 pair<iterator, bool> insert(_Pp&& __p)
1046 {return __tree_.__insert_unique(_VSTD::forward<_Pp>(__p));}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001047
Howard Hinnantc834c512011-11-29 18:15:50 +00001048 template <class _Pp,
1049 class = typename enable_if<is_constructible<value_type, _Pp>::value>::type>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001050 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc834c512011-11-29 18:15:50 +00001051 iterator insert(const_iterator __pos, _Pp&& __p)
1052 {return __tree_.__insert_unique(__pos.__i_, _VSTD::forward<_Pp>(__p));}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001053
Howard Hinnant74279a52010-09-04 23:28:19 +00001054#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +00001055
Howard Hinnant756c69b2010-09-22 16:48:34 +00001056 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001057 pair<iterator, bool>
1058 insert(const value_type& __v) {return __tree_.__insert_unique(__v);}
1059
Howard Hinnant756c69b2010-09-22 16:48:34 +00001060 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001061 iterator
1062 insert(const_iterator __p, const value_type& __v)
1063 {return __tree_.__insert_unique(__p.__i_, __v);}
1064
1065 template <class _InputIterator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001066 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001067 void insert(_InputIterator __f, _InputIterator __l)
1068 {
1069 for (const_iterator __e = cend(); __f != __l; ++__f)
1070 insert(__e.__i_, *__f);
1071 }
1072
Howard Hinnant33711792011-08-12 21:56:02 +00001073#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1074
Howard Hinnant756c69b2010-09-22 16:48:34 +00001075 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001076 void insert(initializer_list<value_type> __il)
1077 {insert(__il.begin(), __il.end());}
1078
Howard Hinnant33711792011-08-12 21:56:02 +00001079#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1080
Howard Hinnant756c69b2010-09-22 16:48:34 +00001081 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001082 iterator erase(const_iterator __p) {return __tree_.erase(__p.__i_);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001083 _LIBCPP_INLINE_VISIBILITY
Marshall Clow22ea5b82015-05-10 13:35:00 +00001084 iterator erase(iterator __p) {return __tree_.erase(__p.__i_);}
1085 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001086 size_type erase(const key_type& __k)
1087 {return __tree_.__erase_unique(__k);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001088 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001089 iterator erase(const_iterator __f, const_iterator __l)
1090 {return __tree_.erase(__f.__i_, __l.__i_);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001091 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001092 void clear() _NOEXCEPT {__tree_.clear();}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001093
Howard Hinnant756c69b2010-09-22 16:48:34 +00001094 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001095 void swap(map& __m)
1096 _NOEXCEPT_(__is_nothrow_swappable<__base>::value)
1097 {__tree_.swap(__m.__tree_);}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001098
Howard Hinnant756c69b2010-09-22 16:48:34 +00001099 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001100 iterator find(const key_type& __k) {return __tree_.find(__k);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001101 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001102 const_iterator find(const key_type& __k) const {return __tree_.find(__k);}
Marshall Clowebb57322013-08-13 22:18:47 +00001103#if _LIBCPP_STD_VER > 11
1104 template <typename _K2>
1105 _LIBCPP_INLINE_VISIBILITY
1106 typename enable_if<__is_transparent<_Compare, _K2>::value,iterator>::type
1107 find(const _K2& __k) {return __tree_.find(__k);}
1108 template <typename _K2>
1109 _LIBCPP_INLINE_VISIBILITY
1110 typename enable_if<__is_transparent<_Compare, _K2>::value,const_iterator>::type
1111 find(const _K2& __k) const {return __tree_.find(__k);}
1112#endif
1113
Howard Hinnant756c69b2010-09-22 16:48:34 +00001114 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001115 size_type count(const key_type& __k) const
1116 {return __tree_.__count_unique(__k);}
Marshall Clowe6a5f522014-08-24 23:54:16 +00001117#if _LIBCPP_STD_VER > 11
1118 template <typename _K2>
1119 _LIBCPP_INLINE_VISIBILITY
1120 typename enable_if<__is_transparent<_Compare, _K2>::value,size_type>::type
1121 count(const _K2& __k) {return __tree_.__count_unique(__k);}
1122#endif
Howard Hinnant756c69b2010-09-22 16:48:34 +00001123 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001124 iterator lower_bound(const key_type& __k)
1125 {return __tree_.lower_bound(__k);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001126 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001127 const_iterator lower_bound(const key_type& __k) const
1128 {return __tree_.lower_bound(__k);}
Marshall Clowebb57322013-08-13 22:18:47 +00001129#if _LIBCPP_STD_VER > 11
1130 template <typename _K2>
1131 _LIBCPP_INLINE_VISIBILITY
1132 typename enable_if<__is_transparent<_Compare, _K2>::value,iterator>::type
1133 lower_bound(const _K2& __k) {return __tree_.lower_bound(__k);}
1134
1135 template <typename _K2>
1136 _LIBCPP_INLINE_VISIBILITY
1137 typename enable_if<__is_transparent<_Compare, _K2>::value,const_iterator>::type
1138 lower_bound(const _K2& __k) const {return __tree_.lower_bound(__k);}
1139#endif
1140
Howard Hinnant756c69b2010-09-22 16:48:34 +00001141 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001142 iterator upper_bound(const key_type& __k)
1143 {return __tree_.upper_bound(__k);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001144 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001145 const_iterator upper_bound(const key_type& __k) const
1146 {return __tree_.upper_bound(__k);}
Marshall Clowebb57322013-08-13 22:18:47 +00001147#if _LIBCPP_STD_VER > 11
1148 template <typename _K2>
1149 _LIBCPP_INLINE_VISIBILITY
1150 typename enable_if<__is_transparent<_Compare, _K2>::value,iterator>::type
1151 upper_bound(const _K2& __k) {return __tree_.upper_bound(__k);}
1152 template <typename _K2>
1153 _LIBCPP_INLINE_VISIBILITY
1154 typename enable_if<__is_transparent<_Compare, _K2>::value,const_iterator>::type
1155 upper_bound(const _K2& __k) const {return __tree_.upper_bound(__k);}
1156#endif
1157
Howard Hinnant756c69b2010-09-22 16:48:34 +00001158 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001159 pair<iterator,iterator> equal_range(const key_type& __k)
1160 {return __tree_.__equal_range_unique(__k);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001161 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001162 pair<const_iterator,const_iterator> equal_range(const key_type& __k) const
1163 {return __tree_.__equal_range_unique(__k);}
Marshall Clowebb57322013-08-13 22:18:47 +00001164#if _LIBCPP_STD_VER > 11
1165 template <typename _K2>
1166 _LIBCPP_INLINE_VISIBILITY
1167 typename enable_if<__is_transparent<_Compare, _K2>::value,pair<iterator,iterator>>::type
1168 equal_range(const _K2& __k) {return __tree_.__equal_range_unique(__k);}
1169 template <typename _K2>
1170 _LIBCPP_INLINE_VISIBILITY
1171 typename enable_if<__is_transparent<_Compare, _K2>::value,pair<const_iterator,const_iterator>>::type
1172 equal_range(const _K2& __k) const {return __tree_.__equal_range_unique(__k);}
1173#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001174
1175private:
1176 typedef typename __base::__node __node;
1177 typedef typename __base::__node_allocator __node_allocator;
1178 typedef typename __base::__node_pointer __node_pointer;
1179 typedef typename __base::__node_const_pointer __node_const_pointer;
1180 typedef typename __base::__node_base_pointer __node_base_pointer;
1181 typedef typename __base::__node_base_const_pointer __node_base_const_pointer;
Howard Hinnantc834c512011-11-29 18:15:50 +00001182 typedef __map_node_destructor<__node_allocator> _Dp;
1183 typedef unique_ptr<__node, _Dp> __node_holder;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001184
Howard Hinnant74279a52010-09-04 23:28:19 +00001185#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +00001186 __node_holder __construct_node();
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001187 template <class _A0>
Howard Hinnantac7e7482013-07-04 20:59:16 +00001188 __node_holder __construct_node(_A0&& __a0);
1189 __node_holder __construct_node_with_key(key_type&& __k);
Howard Hinnant74279a52010-09-04 23:28:19 +00001190#ifndef _LIBCPP_HAS_NO_VARIADICS
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001191 template <class _A0, class _A1, class ..._Args>
1192 __node_holder __construct_node(_A0&& __a0, _A1&& __a1, _Args&& ...__args);
Howard Hinnant74279a52010-09-04 23:28:19 +00001193#endif // _LIBCPP_HAS_NO_VARIADICS
Howard Hinnantc51e1022010-05-11 19:42:16 +00001194#endif
Howard Hinnantac7e7482013-07-04 20:59:16 +00001195 __node_holder __construct_node_with_key(const key_type& __k);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001196
1197 __node_base_pointer&
1198 __find_equal_key(__node_base_pointer& __parent, const key_type& __k);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001199 __node_base_const_pointer
1200 __find_equal_key(__node_base_const_pointer& __parent, const key_type& __k) const;
1201};
1202
1203// Find place to insert if __k doesn't exist
1204// Set __parent to parent of null leaf
1205// Return reference to null leaf
1206// If __k exists, set parent to node of __k and return reference to node of __k
1207template <class _Key, class _Tp, class _Compare, class _Allocator>
1208typename map<_Key, _Tp, _Compare, _Allocator>::__node_base_pointer&
1209map<_Key, _Tp, _Compare, _Allocator>::__find_equal_key(__node_base_pointer& __parent,
1210 const key_type& __k)
1211{
1212 __node_pointer __nd = __tree_.__root();
1213 if (__nd != nullptr)
1214 {
1215 while (true)
1216 {
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001217 if (__tree_.value_comp().key_comp()(__k, __nd->__value_.__cc.first))
Howard Hinnantc51e1022010-05-11 19:42:16 +00001218 {
1219 if (__nd->__left_ != nullptr)
1220 __nd = static_cast<__node_pointer>(__nd->__left_);
1221 else
1222 {
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001223 __parent = static_cast<__node_base_pointer>(__nd);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001224 return __parent->__left_;
1225 }
1226 }
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001227 else if (__tree_.value_comp().key_comp()(__nd->__value_.__cc.first, __k))
Howard Hinnantc51e1022010-05-11 19:42:16 +00001228 {
1229 if (__nd->__right_ != nullptr)
1230 __nd = static_cast<__node_pointer>(__nd->__right_);
1231 else
1232 {
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001233 __parent = static_cast<__node_base_pointer>(__nd);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001234 return __parent->__right_;
1235 }
1236 }
1237 else
1238 {
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001239 __parent = static_cast<__node_base_pointer>(__nd);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001240 return __parent;
1241 }
1242 }
1243 }
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001244 __parent = static_cast<__node_base_pointer>(__tree_.__end_node());
Howard Hinnantc51e1022010-05-11 19:42:16 +00001245 return __parent->__left_;
1246}
1247
Howard Hinnantc51e1022010-05-11 19:42:16 +00001248// Find __k
1249// Set __parent to parent of null leaf and
1250// return reference to null leaf iv __k does not exist.
1251// If __k exists, set parent to node of __k and return reference to node of __k
1252template <class _Key, class _Tp, class _Compare, class _Allocator>
1253typename map<_Key, _Tp, _Compare, _Allocator>::__node_base_const_pointer
1254map<_Key, _Tp, _Compare, _Allocator>::__find_equal_key(__node_base_const_pointer& __parent,
1255 const key_type& __k) const
1256{
1257 __node_const_pointer __nd = __tree_.__root();
1258 if (__nd != nullptr)
1259 {
1260 while (true)
1261 {
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001262 if (__tree_.value_comp().key_comp()(__k, __nd->__value_.__cc.first))
Howard Hinnantc51e1022010-05-11 19:42:16 +00001263 {
1264 if (__nd->__left_ != nullptr)
1265 __nd = static_cast<__node_pointer>(__nd->__left_);
1266 else
1267 {
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001268 __parent = static_cast<__node_base_pointer>(__nd);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001269 return const_cast<const __node_base_const_pointer&>(__parent->__left_);
1270 }
1271 }
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001272 else if (__tree_.value_comp().key_comp()(__nd->__value_.__cc.first, __k))
Howard Hinnantc51e1022010-05-11 19:42:16 +00001273 {
1274 if (__nd->__right_ != nullptr)
1275 __nd = static_cast<__node_pointer>(__nd->__right_);
1276 else
1277 {
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001278 __parent = static_cast<__node_base_pointer>(__nd);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001279 return const_cast<const __node_base_const_pointer&>(__parent->__right_);
1280 }
1281 }
1282 else
1283 {
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001284 __parent = static_cast<__node_base_pointer>(__nd);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001285 return __parent;
1286 }
1287 }
1288 }
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001289 __parent = static_cast<__node_base_pointer>(__tree_.__end_node());
Howard Hinnantc51e1022010-05-11 19:42:16 +00001290 return const_cast<const __node_base_const_pointer&>(__parent->__left_);
1291}
1292
Howard Hinnant74279a52010-09-04 23:28:19 +00001293#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +00001294
1295template <class _Key, class _Tp, class _Compare, class _Allocator>
1296map<_Key, _Tp, _Compare, _Allocator>::map(map&& __m, const allocator_type& __a)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001297 : __tree_(_VSTD::move(__m.__tree_), __a)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001298{
1299 if (__a != __m.get_allocator())
1300 {
1301 const_iterator __e = cend();
1302 while (!__m.empty())
1303 __tree_.__insert_unique(__e.__i_,
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001304 _VSTD::move(__m.__tree_.remove(__m.begin().__i_)->__value_));
Howard Hinnantc51e1022010-05-11 19:42:16 +00001305 }
1306}
1307
1308template <class _Key, class _Tp, class _Compare, class _Allocator>
1309typename map<_Key, _Tp, _Compare, _Allocator>::__node_holder
1310map<_Key, _Tp, _Compare, _Allocator>::__construct_node()
1311{
1312 __node_allocator& __na = __tree_.__node_alloc();
Howard Hinnantc834c512011-11-29 18:15:50 +00001313 __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001314 __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__cc.first));
Howard Hinnantc51e1022010-05-11 19:42:16 +00001315 __h.get_deleter().__first_constructed = true;
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001316 __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__cc.second));
Howard Hinnantc51e1022010-05-11 19:42:16 +00001317 __h.get_deleter().__second_constructed = true;
1318 return __h;
1319}
1320
1321template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001322template <class _A0>
Howard Hinnantac7e7482013-07-04 20:59:16 +00001323typename map<_Key, _Tp, _Compare, _Allocator>::__node_holder
Howard Hinnantc51e1022010-05-11 19:42:16 +00001324map<_Key, _Tp, _Compare, _Allocator>::__construct_node(_A0&& __a0)
1325{
1326 __node_allocator& __na = __tree_.__node_alloc();
Howard Hinnantc834c512011-11-29 18:15:50 +00001327 __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001328 __node_traits::construct(__na, _VSTD::addressof(__h->__value_), _VSTD::forward<_A0>(__a0));
Howard Hinnantc51e1022010-05-11 19:42:16 +00001329 __h.get_deleter().__first_constructed = true;
1330 __h.get_deleter().__second_constructed = true;
1331 return __h;
1332}
1333
1334template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnantac7e7482013-07-04 20:59:16 +00001335typename map<_Key, _Tp, _Compare, _Allocator>::__node_holder
1336map<_Key, _Tp, _Compare, _Allocator>::__construct_node_with_key(key_type&& __k)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001337{
1338 __node_allocator& __na = __tree_.__node_alloc();
Howard Hinnantc834c512011-11-29 18:15:50 +00001339 __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
Howard Hinnantac7e7482013-07-04 20:59:16 +00001340 __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__cc.first), _VSTD::move(__k));
Howard Hinnantc51e1022010-05-11 19:42:16 +00001341 __h.get_deleter().__first_constructed = true;
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001342 __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__cc.second));
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001343 __h.get_deleter().__second_constructed = true;
Howard Hinnanta31e9682013-08-22 18:29:50 +00001344 return __h;
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001345}
1346
1347#ifndef _LIBCPP_HAS_NO_VARIADICS
1348
1349template <class _Key, class _Tp, class _Compare, class _Allocator>
1350template <class _A0, class _A1, class ..._Args>
1351typename map<_Key, _Tp, _Compare, _Allocator>::__node_holder
1352map<_Key, _Tp, _Compare, _Allocator>::__construct_node(_A0&& __a0, _A1&& __a1, _Args&& ...__args)
1353{
1354 __node_allocator& __na = __tree_.__node_alloc();
1355 __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
1356 __node_traits::construct(__na, _VSTD::addressof(__h->__value_),
1357 _VSTD::forward<_A0>(__a0), _VSTD::forward<_A1>(__a1),
1358 _VSTD::forward<_Args>(__args)...);
1359 __h.get_deleter().__first_constructed = true;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001360 __h.get_deleter().__second_constructed = true;
1361 return __h;
1362}
1363
Howard Hinnant74279a52010-09-04 23:28:19 +00001364#endif // _LIBCPP_HAS_NO_VARIADICS
1365
Howard Hinnantac7e7482013-07-04 20:59:16 +00001366#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +00001367
1368template <class _Key, class _Tp, class _Compare, class _Allocator>
1369typename map<_Key, _Tp, _Compare, _Allocator>::__node_holder
Howard Hinnantac7e7482013-07-04 20:59:16 +00001370map<_Key, _Tp, _Compare, _Allocator>::__construct_node_with_key(const key_type& __k)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001371{
1372 __node_allocator& __na = __tree_.__node_alloc();
Howard Hinnantc834c512011-11-29 18:15:50 +00001373 __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001374 __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__cc.first), __k);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001375 __h.get_deleter().__first_constructed = true;
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001376 __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__cc.second));
Howard Hinnantc51e1022010-05-11 19:42:16 +00001377 __h.get_deleter().__second_constructed = true;
Howard Hinnanta31e9682013-08-22 18:29:50 +00001378 return _VSTD::move(__h); // explicitly moved for C++03
Howard Hinnantc51e1022010-05-11 19:42:16 +00001379}
1380
Howard Hinnantc51e1022010-05-11 19:42:16 +00001381template <class _Key, class _Tp, class _Compare, class _Allocator>
1382_Tp&
1383map<_Key, _Tp, _Compare, _Allocator>::operator[](const key_type& __k)
1384{
1385 __node_base_pointer __parent;
1386 __node_base_pointer& __child = __find_equal_key(__parent, __k);
1387 __node_pointer __r = static_cast<__node_pointer>(__child);
1388 if (__child == nullptr)
1389 {
Howard Hinnantac7e7482013-07-04 20:59:16 +00001390 __node_holder __h = __construct_node_with_key(__k);
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001391 __tree_.__insert_node_at(__parent, __child, static_cast<__node_base_pointer>(__h.get()));
Howard Hinnantc51e1022010-05-11 19:42:16 +00001392 __r = __h.release();
1393 }
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001394 return __r->__value_.__cc.second;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001395}
1396
Howard Hinnant74279a52010-09-04 23:28:19 +00001397#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +00001398
1399template <class _Key, class _Tp, class _Compare, class _Allocator>
1400_Tp&
1401map<_Key, _Tp, _Compare, _Allocator>::operator[](key_type&& __k)
1402{
1403 __node_base_pointer __parent;
1404 __node_base_pointer& __child = __find_equal_key(__parent, __k);
1405 __node_pointer __r = static_cast<__node_pointer>(__child);
1406 if (__child == nullptr)
1407 {
Howard Hinnantac7e7482013-07-04 20:59:16 +00001408 __node_holder __h = __construct_node_with_key(_VSTD::move(__k));
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001409 __tree_.__insert_node_at(__parent, __child, static_cast<__node_base_pointer>(__h.get()));
Howard Hinnantc51e1022010-05-11 19:42:16 +00001410 __r = __h.release();
1411 }
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001412 return __r->__value_.__cc.second;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001413}
1414
Howard Hinnant74279a52010-09-04 23:28:19 +00001415#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +00001416
1417template <class _Key, class _Tp, class _Compare, class _Allocator>
1418_Tp&
1419map<_Key, _Tp, _Compare, _Allocator>::at(const key_type& __k)
1420{
1421 __node_base_pointer __parent;
1422 __node_base_pointer& __child = __find_equal_key(__parent, __k);
Howard Hinnant72f73582010-08-11 17:04:31 +00001423#ifndef _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +00001424 if (__child == nullptr)
1425 throw out_of_range("map::at: key not found");
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001426#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001427 return static_cast<__node_pointer>(__child)->__value_.__cc.second;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001428}
1429
1430template <class _Key, class _Tp, class _Compare, class _Allocator>
1431const _Tp&
1432map<_Key, _Tp, _Compare, _Allocator>::at(const key_type& __k) const
1433{
1434 __node_base_const_pointer __parent;
1435 __node_base_const_pointer __child = __find_equal_key(__parent, __k);
Howard Hinnant72f73582010-08-11 17:04:31 +00001436#ifndef _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +00001437 if (__child == nullptr)
1438 throw out_of_range("map::at: key not found");
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001439#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001440 return static_cast<__node_const_pointer>(__child)->__value_.__cc.second;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001441}
1442
Howard Hinnant74279a52010-09-04 23:28:19 +00001443#if !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001444
1445template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001446template <class ..._Args>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001447pair<typename map<_Key, _Tp, _Compare, _Allocator>::iterator, bool>
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001448map<_Key, _Tp, _Compare, _Allocator>::emplace(_Args&& ...__args)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001449{
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001450 __node_holder __h = __construct_node(_VSTD::forward<_Args>(__args)...);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001451 pair<iterator, bool> __r = __tree_.__node_insert_unique(__h.get());
1452 if (__r.second)
1453 __h.release();
1454 return __r;
1455}
1456
1457template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001458template <class ..._Args>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001459typename map<_Key, _Tp, _Compare, _Allocator>::iterator
1460map<_Key, _Tp, _Compare, _Allocator>::emplace_hint(const_iterator __p,
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001461 _Args&& ...__args)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001462{
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001463 __node_holder __h = __construct_node(_VSTD::forward<_Args>(__args)...);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001464 iterator __r = __tree_.__node_insert_unique(__p.__i_, __h.get());
1465 if (__r.__i_.__ptr_ == __h.get())
1466 __h.release();
1467 return __r;
1468}
1469
Howard Hinnant74279a52010-09-04 23:28:19 +00001470#endif // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001471
1472template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001473inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001474bool
1475operator==(const map<_Key, _Tp, _Compare, _Allocator>& __x,
1476 const map<_Key, _Tp, _Compare, _Allocator>& __y)
1477{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001478 return __x.size() == __y.size() && _VSTD::equal(__x.begin(), __x.end(), __y.begin());
Howard Hinnantc51e1022010-05-11 19:42:16 +00001479}
1480
1481template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001482inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001483bool
1484operator< (const map<_Key, _Tp, _Compare, _Allocator>& __x,
1485 const map<_Key, _Tp, _Compare, _Allocator>& __y)
1486{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001487 return _VSTD::lexicographical_compare(__x.begin(), __x.end(), __y.begin(), __y.end());
Howard Hinnantc51e1022010-05-11 19:42:16 +00001488}
1489
1490template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001491inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001492bool
1493operator!=(const map<_Key, _Tp, _Compare, _Allocator>& __x,
1494 const map<_Key, _Tp, _Compare, _Allocator>& __y)
1495{
1496 return !(__x == __y);
1497}
1498
1499template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001500inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001501bool
1502operator> (const map<_Key, _Tp, _Compare, _Allocator>& __x,
1503 const map<_Key, _Tp, _Compare, _Allocator>& __y)
1504{
1505 return __y < __x;
1506}
1507
1508template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001509inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001510bool
1511operator>=(const map<_Key, _Tp, _Compare, _Allocator>& __x,
1512 const map<_Key, _Tp, _Compare, _Allocator>& __y)
1513{
1514 return !(__x < __y);
1515}
1516
1517template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001518inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001519bool
1520operator<=(const map<_Key, _Tp, _Compare, _Allocator>& __x,
1521 const map<_Key, _Tp, _Compare, _Allocator>& __y)
1522{
1523 return !(__y < __x);
1524}
1525
1526template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001527inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001528void
1529swap(map<_Key, _Tp, _Compare, _Allocator>& __x,
1530 map<_Key, _Tp, _Compare, _Allocator>& __y)
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001531 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
Howard Hinnantc51e1022010-05-11 19:42:16 +00001532{
1533 __x.swap(__y);
1534}
1535
1536template <class _Key, class _Tp, class _Compare = less<_Key>,
1537 class _Allocator = allocator<pair<const _Key, _Tp> > >
Howard Hinnanta37d3cf2013-08-12 18:38:34 +00001538class _LIBCPP_TYPE_VIS_ONLY multimap
Howard Hinnantc51e1022010-05-11 19:42:16 +00001539{
1540public:
1541 // types:
1542 typedef _Key key_type;
1543 typedef _Tp mapped_type;
1544 typedef pair<const key_type, mapped_type> value_type;
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001545 typedef pair<key_type, mapped_type> __nc_value_type;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001546 typedef _Compare key_compare;
1547 typedef _Allocator allocator_type;
1548 typedef value_type& reference;
1549 typedef const value_type& const_reference;
1550
Howard Hinnanta37d3cf2013-08-12 18:38:34 +00001551 class _LIBCPP_TYPE_VIS_ONLY value_compare
Howard Hinnantc51e1022010-05-11 19:42:16 +00001552 : public binary_function<value_type, value_type, bool>
1553 {
1554 friend class multimap;
1555 protected:
1556 key_compare comp;
1557
Howard Hinnant756c69b2010-09-22 16:48:34 +00001558 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001559 value_compare(key_compare c) : comp(c) {}
1560 public:
Howard Hinnant756c69b2010-09-22 16:48:34 +00001561 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001562 bool operator()(const value_type& __x, const value_type& __y) const
1563 {return comp(__x.first, __y.first);}
1564 };
1565
1566private:
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001567
Howard Hinnant89f8b792013-09-30 19:08:22 +00001568 typedef _VSTD::__value_type<key_type, mapped_type> __value_type;
Howard Hinnant90b91592013-07-05 18:06:00 +00001569 typedef __map_value_compare<key_type, __value_type, key_compare> __vc;
Marshall Clow940e01c2015-04-07 05:21:38 +00001570 typedef typename __rebind_alloc_helper<allocator_traits<allocator_type>,
1571 __value_type>::type __allocator_type;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001572 typedef __tree<__value_type, __vc, __allocator_type> __base;
1573 typedef typename __base::__node_traits __node_traits;
1574 typedef allocator_traits<allocator_type> __alloc_traits;
1575
1576 __base __tree_;
1577
1578public:
1579 typedef typename __alloc_traits::pointer pointer;
1580 typedef typename __alloc_traits::const_pointer const_pointer;
1581 typedef typename __alloc_traits::size_type size_type;
1582 typedef typename __alloc_traits::difference_type difference_type;
1583 typedef __map_iterator<typename __base::iterator> iterator;
1584 typedef __map_const_iterator<typename __base::const_iterator> const_iterator;
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001585 typedef _VSTD::reverse_iterator<iterator> reverse_iterator;
1586 typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001587
Howard Hinnant756c69b2010-09-22 16:48:34 +00001588 _LIBCPP_INLINE_VISIBILITY
Marshall Clow7086a5a2014-03-10 04:50:10 +00001589 multimap()
1590 _NOEXCEPT_(
1591 is_nothrow_default_constructible<allocator_type>::value &&
1592 is_nothrow_default_constructible<key_compare>::value &&
1593 is_nothrow_copy_constructible<key_compare>::value)
1594 : __tree_(__vc(key_compare())) {}
1595
1596 _LIBCPP_INLINE_VISIBILITY
1597 explicit multimap(const key_compare& __comp)
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001598 _NOEXCEPT_(
1599 is_nothrow_default_constructible<allocator_type>::value &&
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001600 is_nothrow_copy_constructible<key_compare>::value)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001601 : __tree_(__vc(__comp)) {}
1602
Howard Hinnant756c69b2010-09-22 16:48:34 +00001603 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001604 explicit multimap(const key_compare& __comp, const allocator_type& __a)
1605 : __tree_(__vc(__comp), __a) {}
1606
1607 template <class _InputIterator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001608 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001609 multimap(_InputIterator __f, _InputIterator __l,
1610 const key_compare& __comp = key_compare())
1611 : __tree_(__vc(__comp))
1612 {
1613 insert(__f, __l);
1614 }
1615
1616 template <class _InputIterator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001617 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001618 multimap(_InputIterator __f, _InputIterator __l,
1619 const key_compare& __comp, const allocator_type& __a)
1620 : __tree_(__vc(__comp), __a)
1621 {
1622 insert(__f, __l);
1623 }
1624
Marshall Clow300abfb2013-09-11 01:15:47 +00001625#if _LIBCPP_STD_VER > 11
1626 template <class _InputIterator>
1627 _LIBCPP_INLINE_VISIBILITY
1628 multimap(_InputIterator __f, _InputIterator __l, const allocator_type& __a)
1629 : multimap(__f, __l, key_compare(), __a) {}
1630#endif
1631
Howard Hinnant756c69b2010-09-22 16:48:34 +00001632 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001633 multimap(const multimap& __m)
1634 : __tree_(__m.__tree_.value_comp(),
1635 __alloc_traits::select_on_container_copy_construction(__m.__tree_.__alloc()))
1636 {
1637 insert(__m.begin(), __m.end());
1638 }
1639
Howard Hinnantd3a657f2011-07-01 19:24:36 +00001640 _LIBCPP_INLINE_VISIBILITY
1641 multimap& operator=(const multimap& __m)
1642 {
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001643#if __cplusplus >= 201103L
Howard Hinnantd3a657f2011-07-01 19:24:36 +00001644 __tree_ = __m.__tree_;
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001645#else
Marshall Clowdb3cfcb2014-02-08 04:03:14 +00001646 if (this != &__m) {
1647 __tree_.clear();
1648 __tree_.value_comp() = __m.__tree_.value_comp();
1649 __tree_.__copy_assign_alloc(__m.__tree_);
1650 insert(__m.begin(), __m.end());
1651 }
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001652#endif
Howard Hinnantd3a657f2011-07-01 19:24:36 +00001653 return *this;
1654 }
1655
Howard Hinnant74279a52010-09-04 23:28:19 +00001656#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +00001657
Howard Hinnant756c69b2010-09-22 16:48:34 +00001658 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001659 multimap(multimap&& __m)
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001660 _NOEXCEPT_(is_nothrow_move_constructible<__base>::value)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001661 : __tree_(_VSTD::move(__m.__tree_))
Howard Hinnantc51e1022010-05-11 19:42:16 +00001662 {
1663 }
1664
1665 multimap(multimap&& __m, const allocator_type& __a);
1666
Howard Hinnant756c69b2010-09-22 16:48:34 +00001667 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant33711792011-08-12 21:56:02 +00001668 multimap& operator=(multimap&& __m)
1669 _NOEXCEPT_(is_nothrow_move_assignable<__base>::value)
1670 {
1671 __tree_ = _VSTD::move(__m.__tree_);
1672 return *this;
1673 }
1674
1675#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
1676
1677#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1678
1679 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001680 multimap(initializer_list<value_type> __il, const key_compare& __comp = key_compare())
1681 : __tree_(__vc(__comp))
1682 {
1683 insert(__il.begin(), __il.end());
1684 }
1685
Howard Hinnant756c69b2010-09-22 16:48:34 +00001686 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001687 multimap(initializer_list<value_type> __il, const key_compare& __comp, const allocator_type& __a)
1688 : __tree_(__vc(__comp), __a)
1689 {
1690 insert(__il.begin(), __il.end());
1691 }
1692
Marshall Clow300abfb2013-09-11 01:15:47 +00001693#if _LIBCPP_STD_VER > 11
1694 _LIBCPP_INLINE_VISIBILITY
1695 multimap(initializer_list<value_type> __il, const allocator_type& __a)
1696 : multimap(__il, key_compare(), __a) {}
1697#endif
1698
Howard Hinnant756c69b2010-09-22 16:48:34 +00001699 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001700 multimap& operator=(initializer_list<value_type> __il)
1701 {
1702 __tree_.__assign_multi(__il.begin(), __il.end());
1703 return *this;
1704 }
Howard Hinnant33711792011-08-12 21:56:02 +00001705
1706#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantc51e1022010-05-11 19:42:16 +00001707
Howard Hinnant756c69b2010-09-22 16:48:34 +00001708 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001709 explicit multimap(const allocator_type& __a)
1710 : __tree_(__a)
1711 {
1712 }
1713
Howard Hinnant756c69b2010-09-22 16:48:34 +00001714 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001715 multimap(const multimap& __m, const allocator_type& __a)
1716 : __tree_(__m.__tree_.value_comp(), __a)
1717 {
1718 insert(__m.begin(), __m.end());
1719 }
1720
Howard Hinnant756c69b2010-09-22 16:48:34 +00001721 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001722 iterator begin() _NOEXCEPT {return __tree_.begin();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001723 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001724 const_iterator begin() const _NOEXCEPT {return __tree_.begin();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001725 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001726 iterator end() _NOEXCEPT {return __tree_.end();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001727 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001728 const_iterator end() const _NOEXCEPT {return __tree_.end();}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001729
Howard Hinnant756c69b2010-09-22 16:48:34 +00001730 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001731 reverse_iterator rbegin() _NOEXCEPT {return reverse_iterator(end());}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001732 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001733 const_reverse_iterator rbegin() const _NOEXCEPT
1734 {return const_reverse_iterator(end());}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001735 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001736 reverse_iterator rend() _NOEXCEPT {return reverse_iterator(begin());}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001737 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001738 const_reverse_iterator rend() const _NOEXCEPT
1739 {return const_reverse_iterator(begin());}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001740
Howard Hinnant756c69b2010-09-22 16:48:34 +00001741 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001742 const_iterator cbegin() const _NOEXCEPT {return begin();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001743 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001744 const_iterator cend() const _NOEXCEPT {return end();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001745 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001746 const_reverse_iterator crbegin() const _NOEXCEPT {return rbegin();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001747 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001748 const_reverse_iterator crend() const _NOEXCEPT {return rend();}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001749
Howard Hinnant756c69b2010-09-22 16:48:34 +00001750 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001751 bool empty() const _NOEXCEPT {return __tree_.size() == 0;}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001752 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001753 size_type size() const _NOEXCEPT {return __tree_.size();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001754 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001755 size_type max_size() const _NOEXCEPT {return __tree_.max_size();}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001756
Howard Hinnant756c69b2010-09-22 16:48:34 +00001757 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001758 allocator_type get_allocator() const _NOEXCEPT {return __tree_.__alloc();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001759 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001760 key_compare key_comp() const {return __tree_.value_comp().key_comp();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001761 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001762 value_compare value_comp() const
1763 {return value_compare(__tree_.value_comp().key_comp());}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001764
Howard Hinnant74279a52010-09-04 23:28:19 +00001765#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant74279a52010-09-04 23:28:19 +00001766#ifndef _LIBCPP_HAS_NO_VARIADICS
1767
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001768 template <class ..._Args>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001769 iterator
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001770 emplace(_Args&& ...__args);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001771
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001772 template <class ..._Args>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001773 iterator
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001774 emplace_hint(const_iterator __p, _Args&& ...__args);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001775
Howard Hinnant74279a52010-09-04 23:28:19 +00001776#endif // _LIBCPP_HAS_NO_VARIADICS
1777
Howard Hinnantc834c512011-11-29 18:15:50 +00001778 template <class _Pp,
1779 class = typename enable_if<is_constructible<value_type, _Pp>::value>::type>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001780 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc834c512011-11-29 18:15:50 +00001781 iterator insert(_Pp&& __p)
1782 {return __tree_.__insert_multi(_VSTD::forward<_Pp>(__p));}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001783
Howard Hinnantc834c512011-11-29 18:15:50 +00001784 template <class _Pp,
1785 class = typename enable_if<is_constructible<value_type, _Pp>::value>::type>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001786 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc834c512011-11-29 18:15:50 +00001787 iterator insert(const_iterator __pos, _Pp&& __p)
1788 {return __tree_.__insert_multi(__pos.__i_, _VSTD::forward<_Pp>(__p));}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001789
Howard Hinnant74279a52010-09-04 23:28:19 +00001790#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +00001791
Howard Hinnant756c69b2010-09-22 16:48:34 +00001792 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001793 iterator insert(const value_type& __v) {return __tree_.__insert_multi(__v);}
1794
Howard Hinnant756c69b2010-09-22 16:48:34 +00001795 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001796 iterator insert(const_iterator __p, const value_type& __v)
1797 {return __tree_.__insert_multi(__p.__i_, __v);}
1798
1799 template <class _InputIterator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001800 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001801 void insert(_InputIterator __f, _InputIterator __l)
1802 {
1803 for (const_iterator __e = cend(); __f != __l; ++__f)
1804 __tree_.__insert_multi(__e.__i_, *__f);
1805 }
1806
Howard Hinnant33711792011-08-12 21:56:02 +00001807#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1808
Howard Hinnant756c69b2010-09-22 16:48:34 +00001809 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001810 void insert(initializer_list<value_type> __il)
1811 {insert(__il.begin(), __il.end());}
1812
Howard Hinnant33711792011-08-12 21:56:02 +00001813#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1814
Howard Hinnant756c69b2010-09-22 16:48:34 +00001815 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001816 iterator erase(const_iterator __p) {return __tree_.erase(__p.__i_);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001817 _LIBCPP_INLINE_VISIBILITY
Marshall Clow22ea5b82015-05-10 13:35:00 +00001818 iterator erase(iterator __p) {return __tree_.erase(__p.__i_);}
1819 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001820 size_type erase(const key_type& __k) {return __tree_.__erase_multi(__k);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001821 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001822 iterator erase(const_iterator __f, const_iterator __l)
1823 {return __tree_.erase(__f.__i_, __l.__i_);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001824 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001825 void clear() {__tree_.clear();}
1826
Howard Hinnant756c69b2010-09-22 16:48:34 +00001827 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001828 void swap(multimap& __m)
1829 _NOEXCEPT_(__is_nothrow_swappable<__base>::value)
1830 {__tree_.swap(__m.__tree_);}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001831
Howard Hinnant756c69b2010-09-22 16:48:34 +00001832 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001833 iterator find(const key_type& __k) {return __tree_.find(__k);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001834 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001835 const_iterator find(const key_type& __k) const {return __tree_.find(__k);}
Marshall Clowebb57322013-08-13 22:18:47 +00001836#if _LIBCPP_STD_VER > 11
1837 template <typename _K2>
1838 _LIBCPP_INLINE_VISIBILITY
1839 typename enable_if<__is_transparent<_Compare, _K2>::value,iterator>::type
1840 find(const _K2& __k) {return __tree_.find(__k);}
1841 template <typename _K2>
1842 _LIBCPP_INLINE_VISIBILITY
1843 typename enable_if<__is_transparent<_Compare, _K2>::value,const_iterator>::type
1844 find(const _K2& __k) const {return __tree_.find(__k);}
1845#endif
1846
Howard Hinnant756c69b2010-09-22 16:48:34 +00001847 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001848 size_type count(const key_type& __k) const
1849 {return __tree_.__count_multi(__k);}
Marshall Clowe6a5f522014-08-24 23:54:16 +00001850#if _LIBCPP_STD_VER > 11
1851 template <typename _K2>
1852 _LIBCPP_INLINE_VISIBILITY
1853 typename enable_if<__is_transparent<_Compare, _K2>::value,size_type>::type
1854 count(const _K2& __k) {return __tree_.__count_multi(__k);}
1855#endif
Howard Hinnant756c69b2010-09-22 16:48:34 +00001856 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001857 iterator lower_bound(const key_type& __k)
1858 {return __tree_.lower_bound(__k);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001859 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001860 const_iterator lower_bound(const key_type& __k) const
1861 {return __tree_.lower_bound(__k);}
Marshall Clowebb57322013-08-13 22:18:47 +00001862#if _LIBCPP_STD_VER > 11
1863 template <typename _K2>
1864 _LIBCPP_INLINE_VISIBILITY
1865 typename enable_if<__is_transparent<_Compare, _K2>::value,iterator>::type
1866 lower_bound(const _K2& __k) {return __tree_.lower_bound(__k);}
1867
1868 template <typename _K2>
1869 _LIBCPP_INLINE_VISIBILITY
1870 typename enable_if<__is_transparent<_Compare, _K2>::value,const_iterator>::type
1871 lower_bound(const _K2& __k) const {return __tree_.lower_bound(__k);}
1872#endif
1873
Howard Hinnant756c69b2010-09-22 16:48:34 +00001874 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001875 iterator upper_bound(const key_type& __k)
1876 {return __tree_.upper_bound(__k);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001877 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001878 const_iterator upper_bound(const key_type& __k) const
1879 {return __tree_.upper_bound(__k);}
Marshall Clowebb57322013-08-13 22:18:47 +00001880#if _LIBCPP_STD_VER > 11
1881 template <typename _K2>
1882 _LIBCPP_INLINE_VISIBILITY
1883 typename enable_if<__is_transparent<_Compare, _K2>::value,iterator>::type
1884 upper_bound(const _K2& __k) {return __tree_.upper_bound(__k);}
1885 template <typename _K2>
1886 _LIBCPP_INLINE_VISIBILITY
1887 typename enable_if<__is_transparent<_Compare, _K2>::value,const_iterator>::type
1888 upper_bound(const _K2& __k) const {return __tree_.upper_bound(__k);}
1889#endif
1890
Howard Hinnant756c69b2010-09-22 16:48:34 +00001891 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001892 pair<iterator,iterator> equal_range(const key_type& __k)
1893 {return __tree_.__equal_range_multi(__k);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001894 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001895 pair<const_iterator,const_iterator> equal_range(const key_type& __k) const
1896 {return __tree_.__equal_range_multi(__k);}
Marshall Clowebb57322013-08-13 22:18:47 +00001897#if _LIBCPP_STD_VER > 11
1898 template <typename _K2>
1899 _LIBCPP_INLINE_VISIBILITY
1900 typename enable_if<__is_transparent<_Compare, _K2>::value,pair<iterator,iterator>>::type
1901 equal_range(const _K2& __k) {return __tree_.__equal_range_multi(__k);}
1902 template <typename _K2>
1903 _LIBCPP_INLINE_VISIBILITY
1904 typename enable_if<__is_transparent<_Compare, _K2>::value,pair<const_iterator,const_iterator>>::type
1905 equal_range(const _K2& __k) const {return __tree_.__equal_range_multi(__k);}
1906#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001907
1908private:
1909 typedef typename __base::__node __node;
1910 typedef typename __base::__node_allocator __node_allocator;
1911 typedef typename __base::__node_pointer __node_pointer;
1912 typedef typename __base::__node_const_pointer __node_const_pointer;
Howard Hinnantc834c512011-11-29 18:15:50 +00001913 typedef __map_node_destructor<__node_allocator> _Dp;
1914 typedef unique_ptr<__node, _Dp> __node_holder;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001915
Howard Hinnant74279a52010-09-04 23:28:19 +00001916#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +00001917 __node_holder __construct_node();
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001918 template <class _A0>
Howard Hinnantac7e7482013-07-04 20:59:16 +00001919 __node_holder
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001920 __construct_node(_A0&& __a0);
Howard Hinnant74279a52010-09-04 23:28:19 +00001921#ifndef _LIBCPP_HAS_NO_VARIADICS
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001922 template <class _A0, class _A1, class ..._Args>
1923 __node_holder __construct_node(_A0&& __a0, _A1&& __a1, _Args&& ...__args);
Howard Hinnant74279a52010-09-04 23:28:19 +00001924#endif // _LIBCPP_HAS_NO_VARIADICS
1925#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +00001926};
1927
Howard Hinnant74279a52010-09-04 23:28:19 +00001928#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +00001929
1930template <class _Key, class _Tp, class _Compare, class _Allocator>
1931multimap<_Key, _Tp, _Compare, _Allocator>::multimap(multimap&& __m, const allocator_type& __a)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001932 : __tree_(_VSTD::move(__m.__tree_), __a)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001933{
1934 if (__a != __m.get_allocator())
1935 {
1936 const_iterator __e = cend();
1937 while (!__m.empty())
1938 __tree_.__insert_multi(__e.__i_,
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001939 _VSTD::move(__m.__tree_.remove(__m.begin().__i_)->__value_));
Howard Hinnantc51e1022010-05-11 19:42:16 +00001940 }
1941}
1942
1943template <class _Key, class _Tp, class _Compare, class _Allocator>
1944typename multimap<_Key, _Tp, _Compare, _Allocator>::__node_holder
1945multimap<_Key, _Tp, _Compare, _Allocator>::__construct_node()
1946{
1947 __node_allocator& __na = __tree_.__node_alloc();
Howard Hinnantc834c512011-11-29 18:15:50 +00001948 __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001949 __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__cc.first));
Howard Hinnantc51e1022010-05-11 19:42:16 +00001950 __h.get_deleter().__first_constructed = true;
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001951 __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__cc.second));
Howard Hinnantc51e1022010-05-11 19:42:16 +00001952 __h.get_deleter().__second_constructed = true;
1953 return __h;
1954}
1955
1956template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001957template <class _A0>
Howard Hinnantac7e7482013-07-04 20:59:16 +00001958typename multimap<_Key, _Tp, _Compare, _Allocator>::__node_holder
Howard Hinnantc51e1022010-05-11 19:42:16 +00001959multimap<_Key, _Tp, _Compare, _Allocator>::__construct_node(_A0&& __a0)
1960{
1961 __node_allocator& __na = __tree_.__node_alloc();
Howard Hinnantc834c512011-11-29 18:15:50 +00001962 __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001963 __node_traits::construct(__na, _VSTD::addressof(__h->__value_), _VSTD::forward<_A0>(__a0));
Howard Hinnantc51e1022010-05-11 19:42:16 +00001964 __h.get_deleter().__first_constructed = true;
1965 __h.get_deleter().__second_constructed = true;
1966 return __h;
1967}
1968
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001969#ifndef _LIBCPP_HAS_NO_VARIADICS
1970
1971template <class _Key, class _Tp, class _Compare, class _Allocator>
1972template <class _A0, class _A1, class ..._Args>
1973typename multimap<_Key, _Tp, _Compare, _Allocator>::__node_holder
1974multimap<_Key, _Tp, _Compare, _Allocator>::__construct_node(_A0&& __a0, _A1&& __a1, _Args&& ...__args)
1975{
1976 __node_allocator& __na = __tree_.__node_alloc();
1977 __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
1978 __node_traits::construct(__na, _VSTD::addressof(__h->__value_),
1979 _VSTD::forward<_A0>(__a0), _VSTD::forward<_A1>(__a1),
1980 _VSTD::forward<_Args>(__args)...);
1981 __h.get_deleter().__first_constructed = true;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001982 __h.get_deleter().__second_constructed = true;
1983 return __h;
1984}
1985
Howard Hinnant74279a52010-09-04 23:28:19 +00001986#endif // _LIBCPP_HAS_NO_VARIADICS
1987#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +00001988
Howard Hinnant74279a52010-09-04 23:28:19 +00001989#if !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001990
1991template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001992template <class ..._Args>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001993typename multimap<_Key, _Tp, _Compare, _Allocator>::iterator
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001994multimap<_Key, _Tp, _Compare, _Allocator>::emplace(_Args&& ...__args)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001995{
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001996 __node_holder __h = __construct_node(_VSTD::forward<_Args>(__args)...);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001997 iterator __r = __tree_.__node_insert_multi(__h.get());
1998 __h.release();
1999 return __r;
2000}
2001
2002template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant29eb9b82012-05-25 22:04:21 +00002003template <class ..._Args>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002004typename multimap<_Key, _Tp, _Compare, _Allocator>::iterator
2005multimap<_Key, _Tp, _Compare, _Allocator>::emplace_hint(const_iterator __p,
Howard Hinnantc51e1022010-05-11 19:42:16 +00002006 _Args&& ...__args)
2007{
Howard Hinnant29eb9b82012-05-25 22:04:21 +00002008 __node_holder __h = __construct_node(_VSTD::forward<_Args>(__args)...);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002009 iterator __r = __tree_.__node_insert_multi(__p.__i_, __h.get());
2010 __h.release();
2011 return __r;
2012}
2013
Howard Hinnant74279a52010-09-04 23:28:19 +00002014#endif // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
Howard Hinnantc51e1022010-05-11 19:42:16 +00002015
2016template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00002017inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002018bool
2019operator==(const multimap<_Key, _Tp, _Compare, _Allocator>& __x,
2020 const multimap<_Key, _Tp, _Compare, _Allocator>& __y)
2021{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00002022 return __x.size() == __y.size() && _VSTD::equal(__x.begin(), __x.end(), __y.begin());
Howard Hinnantc51e1022010-05-11 19:42:16 +00002023}
2024
2025template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00002026inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002027bool
2028operator< (const multimap<_Key, _Tp, _Compare, _Allocator>& __x,
2029 const multimap<_Key, _Tp, _Compare, _Allocator>& __y)
2030{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00002031 return _VSTD::lexicographical_compare(__x.begin(), __x.end(), __y.begin(), __y.end());
Howard Hinnantc51e1022010-05-11 19:42:16 +00002032}
2033
2034template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00002035inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002036bool
2037operator!=(const multimap<_Key, _Tp, _Compare, _Allocator>& __x,
2038 const multimap<_Key, _Tp, _Compare, _Allocator>& __y)
2039{
2040 return !(__x == __y);
2041}
2042
2043template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00002044inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002045bool
2046operator> (const multimap<_Key, _Tp, _Compare, _Allocator>& __x,
2047 const multimap<_Key, _Tp, _Compare, _Allocator>& __y)
2048{
2049 return __y < __x;
2050}
2051
2052template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00002053inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002054bool
2055operator>=(const multimap<_Key, _Tp, _Compare, _Allocator>& __x,
2056 const multimap<_Key, _Tp, _Compare, _Allocator>& __y)
2057{
2058 return !(__x < __y);
2059}
2060
2061template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00002062inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002063bool
2064operator<=(const multimap<_Key, _Tp, _Compare, _Allocator>& __x,
2065 const multimap<_Key, _Tp, _Compare, _Allocator>& __y)
2066{
2067 return !(__y < __x);
2068}
2069
2070template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00002071inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002072void
2073swap(multimap<_Key, _Tp, _Compare, _Allocator>& __x,
2074 multimap<_Key, _Tp, _Compare, _Allocator>& __y)
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00002075 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
Howard Hinnantc51e1022010-05-11 19:42:16 +00002076{
2077 __x.swap(__y);
2078}
2079
2080_LIBCPP_END_NAMESPACE_STD
2081
2082#endif // _LIBCPP_MAP