blob: 5449d6ce35b87d9d331e139f8a2971b38d5c6741 [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);
80 ~map();
81
82 map& operator=(const map& m);
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +000083 map& operator=(map&& m)
84 noexcept(
85 allocator_type::propagate_on_container_move_assignment::value &&
86 is_nothrow_move_assignable<allocator_type>::value &&
Howard Hinnantf95f4f52011-06-04 15:22:34 +000087 is_nothrow_move_assignable<key_compare>::value);
Howard Hinnantc51e1022010-05-11 19:42:16 +000088 map& operator=(initializer_list<value_type> il);
89
90 // iterators:
Howard Hinnantf95f4f52011-06-04 15:22:34 +000091 iterator begin() noexcept;
92 const_iterator begin() const noexcept;
93 iterator end() noexcept;
94 const_iterator end() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +000095
Howard Hinnantf95f4f52011-06-04 15:22:34 +000096 reverse_iterator rbegin() noexcept;
97 const_reverse_iterator rbegin() const noexcept;
98 reverse_iterator rend() noexcept;
99 const_reverse_iterator rend() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000100
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000101 const_iterator cbegin() const noexcept;
102 const_iterator cend() const noexcept;
103 const_reverse_iterator crbegin() const noexcept;
104 const_reverse_iterator crend() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000105
106 // capacity:
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000107 bool empty() const noexcept;
108 size_type size() const noexcept;
109 size_type max_size() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000110
111 // element access:
112 mapped_type& operator[](const key_type& k);
113 mapped_type& operator[](key_type&& k);
114
115 mapped_type& at(const key_type& k);
116 const mapped_type& at(const key_type& k) const;
117
118 // modifiers:
119 template <class... Args>
120 pair<iterator, bool> emplace(Args&&... args);
121 template <class... Args>
122 iterator emplace_hint(const_iterator position, Args&&... args);
123 pair<iterator, bool> insert(const value_type& v);
124 template <class P>
125 pair<iterator, bool> insert(P&& p);
126 iterator insert(const_iterator position, const value_type& v);
127 template <class P>
128 iterator insert(const_iterator position, P&& p);
129 template <class InputIterator>
130 void insert(InputIterator first, InputIterator last);
131 void insert(initializer_list<value_type> il);
132
133 iterator erase(const_iterator position);
134 size_type erase(const key_type& k);
135 iterator erase(const_iterator first, const_iterator last);
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000136 void clear() noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000137
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000138 void swap(map& m)
139 noexcept(
140 __is_nothrow_swappable<key_compare>::value &&
141 (!allocator_type::propagate_on_container_swap::value ||
142 __is_nothrow_swappable<allocator_type>::value));
Howard Hinnantc51e1022010-05-11 19:42:16 +0000143
144 // observers:
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000145 allocator_type get_allocator() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000146 key_compare key_comp() const;
147 value_compare value_comp() const;
148
149 // map operations:
150 iterator find(const key_type& k);
151 const_iterator find(const key_type& k) const;
Marshall Clowebb57322013-08-13 22:18:47 +0000152 template<typename K>
153 iterator find(const K& x); // C++14
154 template<typename K>
155 const_iterator find(const K& x) const; // C++14
156 template<typename K>
157 size_type count(const K& x) const;
158
Howard Hinnantc51e1022010-05-11 19:42:16 +0000159 size_type count(const key_type& k) const;
160 iterator lower_bound(const key_type& k);
161 const_iterator lower_bound(const key_type& k) const;
Marshall Clowebb57322013-08-13 22:18:47 +0000162 template<typename K>
163 iterator lower_bound(const K& x); // C++14
164 template<typename K>
165 const_iterator lower_bound(const K& x) const; // C++14
166
Howard Hinnantc51e1022010-05-11 19:42:16 +0000167 iterator upper_bound(const key_type& k);
168 const_iterator upper_bound(const key_type& k) const;
Marshall Clowebb57322013-08-13 22:18:47 +0000169 template<typename K>
170 iterator upper_bound(const K& x); // C++14
171 template<typename K>
172 const_iterator upper_bound(const K& x) const; // C++14
173
Howard Hinnantc51e1022010-05-11 19:42:16 +0000174 pair<iterator,iterator> equal_range(const key_type& k);
175 pair<const_iterator,const_iterator> equal_range(const key_type& k) const;
Marshall Clowebb57322013-08-13 22:18:47 +0000176 template<typename K>
177 pair<iterator,iterator> equal_range(const K& x); // C++14
178 template<typename K>
179 pair<const_iterator,const_iterator> equal_range(const K& x) const; // C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000180};
181
182template <class Key, class T, class Compare, class Allocator>
183bool
184operator==(const map<Key, T, Compare, Allocator>& x,
185 const map<Key, T, Compare, Allocator>& y);
186
187template <class Key, class T, class Compare, class Allocator>
188bool
189operator< (const map<Key, T, Compare, Allocator>& x,
190 const map<Key, T, Compare, Allocator>& y);
191
192template <class Key, class T, class Compare, class Allocator>
193bool
194operator!=(const map<Key, T, Compare, Allocator>& x,
195 const map<Key, T, Compare, Allocator>& y);
196
197template <class Key, class T, class Compare, class Allocator>
198bool
199operator> (const map<Key, T, Compare, Allocator>& x,
200 const map<Key, T, Compare, Allocator>& y);
201
202template <class Key, class T, class Compare, class Allocator>
203bool
204operator>=(const map<Key, T, Compare, Allocator>& x,
205 const map<Key, T, Compare, Allocator>& y);
206
207template <class Key, class T, class Compare, class Allocator>
208bool
209operator<=(const map<Key, T, Compare, Allocator>& x,
210 const map<Key, T, Compare, Allocator>& y);
211
212// specialized algorithms:
213template <class Key, class T, class Compare, class Allocator>
214void
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000215swap(map<Key, T, Compare, Allocator>& x, map<Key, T, Compare, Allocator>& y)
216 noexcept(noexcept(x.swap(y)));
Howard Hinnantc51e1022010-05-11 19:42:16 +0000217
218template <class Key, class T, class Compare = less<Key>,
219 class Allocator = allocator<pair<const Key, T>>>
220class multimap
221{
222public:
223 // types:
224 typedef Key key_type;
225 typedef T mapped_type;
226 typedef pair<const key_type,mapped_type> value_type;
227 typedef Compare key_compare;
228 typedef Allocator allocator_type;
229 typedef typename allocator_type::reference reference;
230 typedef typename allocator_type::const_reference const_reference;
231 typedef typename allocator_type::size_type size_type;
232 typedef typename allocator_type::difference_type difference_type;
233 typedef typename allocator_type::pointer pointer;
234 typedef typename allocator_type::const_pointer const_pointer;
235
236 typedef implementation-defined iterator;
237 typedef implementation-defined const_iterator;
238 typedef std::reverse_iterator<iterator> reverse_iterator;
239 typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
240
241 class value_compare
242 : public binary_function<value_type,value_type,bool>
243 {
244 friend class multimap;
245 protected:
246 key_compare comp;
247 value_compare(key_compare c);
248 public:
249 bool operator()(const value_type& x, const value_type& y) const;
250 };
251
252 // construct/copy/destroy:
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000253 multimap()
254 noexcept(
255 is_nothrow_default_constructible<allocator_type>::value &&
256 is_nothrow_default_constructible<key_compare>::value &&
257 is_nothrow_copy_constructible<key_compare>::value);
258 explicit multimap(const key_compare& comp);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000259 multimap(const key_compare& comp, const allocator_type& a);
260 template <class InputIterator>
261 multimap(InputIterator first, InputIterator last, const key_compare& comp);
262 template <class InputIterator>
263 multimap(InputIterator first, InputIterator last, const key_compare& comp,
264 const allocator_type& a);
265 multimap(const multimap& m);
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000266 multimap(multimap&& m)
267 noexcept(
268 is_nothrow_move_constructible<allocator_type>::value &&
269 is_nothrow_move_constructible<key_compare>::value);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000270 explicit multimap(const allocator_type& a);
271 multimap(const multimap& m, const allocator_type& a);
272 multimap(multimap&& m, const allocator_type& a);
273 multimap(initializer_list<value_type> il, const key_compare& comp = key_compare());
274 multimap(initializer_list<value_type> il, const key_compare& comp,
275 const allocator_type& a);
276 ~multimap();
277
278 multimap& operator=(const multimap& m);
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000279 multimap& operator=(multimap&& m)
280 noexcept(
281 allocator_type::propagate_on_container_move_assignment::value &&
282 is_nothrow_move_assignable<allocator_type>::value &&
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000283 is_nothrow_move_assignable<key_compare>::value);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000284 multimap& operator=(initializer_list<value_type> il);
285
286 // iterators:
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000287 iterator begin() noexcept;
288 const_iterator begin() const noexcept;
289 iterator end() noexcept;
290 const_iterator end() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000291
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000292 reverse_iterator rbegin() noexcept;
293 const_reverse_iterator rbegin() const noexcept;
294 reverse_iterator rend() noexcept;
295 const_reverse_iterator rend() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000296
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000297 const_iterator cbegin() const noexcept;
298 const_iterator cend() const noexcept;
299 const_reverse_iterator crbegin() const noexcept;
300 const_reverse_iterator crend() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000301
302 // capacity:
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000303 bool empty() const noexcept;
304 size_type size() const noexcept;
305 size_type max_size() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000306
307 // modifiers:
308 template <class... Args>
309 iterator emplace(Args&&... args);
310 template <class... Args>
311 iterator emplace_hint(const_iterator position, Args&&... args);
312 iterator insert(const value_type& v);
313 template <class P>
314 iterator insert(P&& p);
315 iterator insert(const_iterator position, const value_type& v);
316 template <class P>
317 iterator insert(const_iterator position, P&& p);
318 template <class InputIterator>
319 void insert(InputIterator first, InputIterator last);
320 void insert(initializer_list<value_type> il);
321
322 iterator erase(const_iterator position);
323 size_type erase(const key_type& k);
324 iterator erase(const_iterator first, const_iterator last);
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000325 void clear() noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000326
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000327 void swap(multimap& m)
328 noexcept(
329 __is_nothrow_swappable<key_compare>::value &&
330 (!allocator_type::propagate_on_container_swap::value ||
331 __is_nothrow_swappable<allocator_type>::value));
Howard Hinnantc51e1022010-05-11 19:42:16 +0000332
333 // observers:
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000334 allocator_type get_allocator() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000335 key_compare key_comp() const;
336 value_compare value_comp() const;
337
338 // map operations:
339 iterator find(const key_type& k);
340 const_iterator find(const key_type& k) const;
Marshall Clowebb57322013-08-13 22:18:47 +0000341 template<typename K>
342 iterator find(const K& x); // C++14
343 template<typename K>
344 const_iterator find(const K& x) const; // C++14
345 template<typename K>
346 size_type count(const K& x) const;
347
Howard Hinnantc51e1022010-05-11 19:42:16 +0000348 size_type count(const key_type& k) const;
349 iterator lower_bound(const key_type& k);
350 const_iterator lower_bound(const key_type& k) const;
Marshall Clowebb57322013-08-13 22:18:47 +0000351 template<typename K>
352 iterator lower_bound(const K& x); // C++14
353 template<typename K>
354 const_iterator lower_bound(const K& x) const; // C++14
355
Howard Hinnantc51e1022010-05-11 19:42:16 +0000356 iterator upper_bound(const key_type& k);
357 const_iterator upper_bound(const key_type& k) const;
Marshall Clowebb57322013-08-13 22:18:47 +0000358 template<typename K>
359 iterator upper_bound(const K& x); // C++14
360 template<typename K>
361 const_iterator upper_bound(const K& x) const; // C++14
362
Howard Hinnantc51e1022010-05-11 19:42:16 +0000363 pair<iterator,iterator> equal_range(const key_type& k);
364 pair<const_iterator,const_iterator> equal_range(const key_type& k) const;
Marshall Clowebb57322013-08-13 22:18:47 +0000365 template<typename K>
366 pair<iterator,iterator> equal_range(const K& x); // C++14
367 template<typename K>
368 pair<const_iterator,const_iterator> equal_range(const K& x) const; // C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000369};
370
371template <class Key, class T, class Compare, class Allocator>
372bool
373operator==(const multimap<Key, T, Compare, Allocator>& x,
374 const multimap<Key, T, Compare, Allocator>& y);
375
376template <class Key, class T, class Compare, class Allocator>
377bool
378operator< (const multimap<Key, T, Compare, Allocator>& x,
379 const multimap<Key, T, Compare, Allocator>& y);
380
381template <class Key, class T, class Compare, class Allocator>
382bool
383operator!=(const multimap<Key, T, Compare, Allocator>& x,
384 const multimap<Key, T, Compare, Allocator>& y);
385
386template <class Key, class T, class Compare, class Allocator>
387bool
388operator> (const multimap<Key, T, Compare, Allocator>& x,
389 const multimap<Key, T, Compare, Allocator>& y);
390
391template <class Key, class T, class Compare, class Allocator>
392bool
393operator>=(const multimap<Key, T, Compare, Allocator>& x,
394 const multimap<Key, T, Compare, Allocator>& y);
395
396template <class Key, class T, class Compare, class Allocator>
397bool
398operator<=(const multimap<Key, T, Compare, Allocator>& x,
399 const multimap<Key, T, Compare, Allocator>& y);
400
401// specialized algorithms:
402template <class Key, class T, class Compare, class Allocator>
403void
404swap(multimap<Key, T, Compare, Allocator>& x,
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000405 multimap<Key, T, Compare, Allocator>& y)
406 noexcept(noexcept(x.swap(y)));
Howard Hinnantc51e1022010-05-11 19:42:16 +0000407
408} // std
409
410*/
411
412#include <__config>
413#include <__tree>
414#include <iterator>
415#include <memory>
416#include <utility>
417#include <functional>
418#include <initializer_list>
419
Howard Hinnantaaaa52b2011-10-17 20:05:10 +0000420#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000421#pragma GCC system_header
Howard Hinnantaaaa52b2011-10-17 20:05:10 +0000422#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000423
424_LIBCPP_BEGIN_NAMESPACE_STD
425
Howard Hinnant90b91592013-07-05 18:06:00 +0000426template <class _Key, class _CP, class _Compare, bool = is_empty<_Compare>::value
Howard Hinnantd0aabf82011-12-11 20:31:33 +0000427#if __has_feature(is_final)
428 && !__is_final(_Compare)
429#endif
430 >
Howard Hinnantc51e1022010-05-11 19:42:16 +0000431class __map_value_compare
432 : private _Compare
433{
Howard Hinnantc51e1022010-05-11 19:42:16 +0000434public:
Howard Hinnant756c69b2010-09-22 16:48:34 +0000435 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000436 __map_value_compare()
437 _NOEXCEPT_(is_nothrow_default_constructible<_Compare>::value)
438 : _Compare() {}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000439 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000440 __map_value_compare(_Compare c)
441 _NOEXCEPT_(is_nothrow_copy_constructible<_Compare>::value)
442 : _Compare(c) {}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000443 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000444 const _Compare& key_comp() const _NOEXCEPT {return *this;}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000445 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000446 bool operator()(const _CP& __x, const _CP& __y) const
Howard Hinnant90b91592013-07-05 18:06:00 +0000447 {return static_cast<const _Compare&>(*this)(__x.__cc.first, __y.__cc.first);}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000448 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000449 bool operator()(const _CP& __x, const _Key& __y) const
Howard Hinnant90b91592013-07-05 18:06:00 +0000450 {return static_cast<const _Compare&>(*this)(__x.__cc.first, __y);}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000451 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000452 bool operator()(const _Key& __x, const _CP& __y) const
Howard Hinnant90b91592013-07-05 18:06:00 +0000453 {return static_cast<const _Compare&>(*this)(__x, __y.__cc.first);}
Marshall Clowebb57322013-08-13 22:18:47 +0000454
455#if _LIBCPP_STD_VER > 11
456 template <typename _K2>
457 _LIBCPP_INLINE_VISIBILITY
458 typename enable_if<__is_transparent<_Compare, _K2>::value, bool>::type
459 operator () ( const _K2& __x, const _CP& __y ) const
460 {return static_cast<const _Compare&>(*this) (__x, __y.__cc.first);}
461
462 template <typename _K2>
463 _LIBCPP_INLINE_VISIBILITY
464 typename enable_if<__is_transparent<_Compare, _K2>::value, bool>::type
465 operator () (const _CP& __x, const _K2& __y) const
466 {return static_cast<const _Compare&>(*this) (__x.__cc.first, __y);}
467#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000468};
469
Howard Hinnant90b91592013-07-05 18:06:00 +0000470template <class _Key, class _CP, class _Compare>
471class __map_value_compare<_Key, _CP, _Compare, false>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000472{
473 _Compare comp;
474
Howard Hinnantc51e1022010-05-11 19:42:16 +0000475public:
Howard Hinnant756c69b2010-09-22 16:48:34 +0000476 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000477 __map_value_compare()
478 _NOEXCEPT_(is_nothrow_default_constructible<_Compare>::value)
479 : comp() {}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000480 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000481 __map_value_compare(_Compare c)
482 _NOEXCEPT_(is_nothrow_copy_constructible<_Compare>::value)
483 : comp(c) {}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000484 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000485 const _Compare& key_comp() const _NOEXCEPT {return comp;}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000486
Howard Hinnant756c69b2010-09-22 16:48:34 +0000487 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000488 bool operator()(const _CP& __x, const _CP& __y) const
Howard Hinnant90b91592013-07-05 18:06:00 +0000489 {return comp(__x.__cc.first, __y.__cc.first);}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000490 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000491 bool operator()(const _CP& __x, const _Key& __y) const
Howard Hinnant90b91592013-07-05 18:06:00 +0000492 {return comp(__x.__cc.first, __y);}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000493 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000494 bool operator()(const _Key& __x, const _CP& __y) const
Howard Hinnant90b91592013-07-05 18:06:00 +0000495 {return comp(__x, __y.__cc.first);}
Marshall Clowebb57322013-08-13 22:18:47 +0000496
497#if _LIBCPP_STD_VER > 11
498 template <typename _K2>
499 _LIBCPP_INLINE_VISIBILITY
500 typename enable_if<__is_transparent<_Compare, _K2>::value, bool>::type
501 operator () ( const _K2& __x, const _CP& __y ) const
502 {return comp (__x, __y.__cc.first);}
503
504 template <typename _K2>
505 _LIBCPP_INLINE_VISIBILITY
506 typename enable_if<__is_transparent<_Compare, _K2>::value, bool>::type
507 operator () (const _CP& __x, const _K2& __y) const
508 {return comp (__x.__cc.first, __y);}
509#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000510};
511
512template <class _Allocator>
513class __map_node_destructor
514{
515 typedef _Allocator allocator_type;
516 typedef allocator_traits<allocator_type> __alloc_traits;
517 typedef typename __alloc_traits::value_type::value_type value_type;
518public:
519 typedef typename __alloc_traits::pointer pointer;
520private:
Howard Hinnant2d0046b2013-06-19 21:29:40 +0000521 typedef typename value_type::value_type::first_type first_type;
522 typedef typename value_type::value_type::second_type second_type;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000523
524 allocator_type& __na_;
525
526 __map_node_destructor& operator=(const __map_node_destructor&);
527
528public:
529 bool __first_constructed;
530 bool __second_constructed;
531
Howard Hinnant756c69b2010-09-22 16:48:34 +0000532 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000533 explicit __map_node_destructor(allocator_type& __na) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +0000534 : __na_(__na),
535 __first_constructed(false),
536 __second_constructed(false)
537 {}
538
Howard Hinnant74279a52010-09-04 23:28:19 +0000539#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant756c69b2010-09-22 16:48:34 +0000540 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000541 __map_node_destructor(__tree_node_destructor<allocator_type>&& __x) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +0000542 : __na_(__x.__na_),
543 __first_constructed(__x.__value_constructed),
544 __second_constructed(__x.__value_constructed)
545 {
546 __x.__value_constructed = false;
547 }
Howard Hinnant5dc89112010-09-04 23:46:48 +0000548#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +0000549
Howard Hinnant756c69b2010-09-22 16:48:34 +0000550 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000551 void operator()(pointer __p) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +0000552 {
553 if (__second_constructed)
Howard Hinnant2d0046b2013-06-19 21:29:40 +0000554 __alloc_traits::destroy(__na_, _VSTD::addressof(__p->__value_.__cc.second));
Howard Hinnantc51e1022010-05-11 19:42:16 +0000555 if (__first_constructed)
Howard Hinnant2d0046b2013-06-19 21:29:40 +0000556 __alloc_traits::destroy(__na_, _VSTD::addressof(__p->__value_.__cc.first));
Howard Hinnantc51e1022010-05-11 19:42:16 +0000557 if (__p)
558 __alloc_traits::deallocate(__na_, __p, 1);
559 }
560};
561
Howard Hinnant944510a2011-06-14 19:58:17 +0000562template <class _Key, class _Tp, class _Compare, class _Allocator>
563 class map;
564template <class _Key, class _Tp, class _Compare, class _Allocator>
565 class multimap;
566template <class _TreeIterator> class __map_const_iterator;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000567
568template <class _TreeIterator>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +0000569class _LIBCPP_TYPE_VIS_ONLY __map_iterator
Howard Hinnantc51e1022010-05-11 19:42:16 +0000570{
571 _TreeIterator __i_;
572
573 typedef typename _TreeIterator::__pointer_traits __pointer_traits;
Howard Hinnant2d0046b2013-06-19 21:29:40 +0000574 typedef const typename _TreeIterator::value_type::value_type::first_type __key_type;
575 typedef typename _TreeIterator::value_type::value_type::second_type __mapped_type;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000576public:
577 typedef bidirectional_iterator_tag iterator_category;
Howard Hinnantb2e8a422011-02-27 18:02:02 +0000578 typedef pair<__key_type, __mapped_type> value_type;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000579 typedef typename _TreeIterator::difference_type difference_type;
580 typedef value_type& reference;
581 typedef typename __pointer_traits::template
582#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
583 rebind<value_type>
584#else
585 rebind<value_type>::other
586#endif
587 pointer;
588
Howard Hinnant756c69b2010-09-22 16:48:34 +0000589 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000590 __map_iterator() _NOEXCEPT {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000591
Howard Hinnant756c69b2010-09-22 16:48:34 +0000592 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000593 __map_iterator(_TreeIterator __i) _NOEXCEPT : __i_(__i) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000594
Howard Hinnant756c69b2010-09-22 16:48:34 +0000595 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2d0046b2013-06-19 21:29:40 +0000596 reference operator*() const {return __i_->__cc;}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000597 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2d0046b2013-06-19 21:29:40 +0000598 pointer operator->() const {return pointer_traits<pointer>::pointer_to(__i_->__cc);}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000599
Howard Hinnant756c69b2010-09-22 16:48:34 +0000600 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000601 __map_iterator& operator++() {++__i_; return *this;}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000602 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000603 __map_iterator operator++(int)
604 {
605 __map_iterator __t(*this);
606 ++(*this);
607 return __t;
608 }
609
Howard Hinnant756c69b2010-09-22 16:48:34 +0000610 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000611 __map_iterator& operator--() {--__i_; return *this;}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000612 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000613 __map_iterator operator--(int)
614 {
615 __map_iterator __t(*this);
616 --(*this);
617 return __t;
618 }
619
Howard Hinnant756c69b2010-09-22 16:48:34 +0000620 friend _LIBCPP_INLINE_VISIBILITY
621 bool operator==(const __map_iterator& __x, const __map_iterator& __y)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000622 {return __x.__i_ == __y.__i_;}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000623 friend
624 _LIBCPP_INLINE_VISIBILITY
625 bool operator!=(const __map_iterator& __x, const __map_iterator& __y)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000626 {return __x.__i_ != __y.__i_;}
627
Howard Hinnanta37d3cf2013-08-12 18:38:34 +0000628 template <class, class, class, class> friend class _LIBCPP_TYPE_VIS_ONLY map;
629 template <class, class, class, class> friend class _LIBCPP_TYPE_VIS_ONLY multimap;
630 template <class> friend class _LIBCPP_TYPE_VIS_ONLY __map_const_iterator;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000631};
632
633template <class _TreeIterator>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +0000634class _LIBCPP_TYPE_VIS_ONLY __map_const_iterator
Howard Hinnantc51e1022010-05-11 19:42:16 +0000635{
636 _TreeIterator __i_;
637
638 typedef typename _TreeIterator::__pointer_traits __pointer_traits;
Howard Hinnant2d0046b2013-06-19 21:29:40 +0000639 typedef const typename _TreeIterator::value_type::value_type::first_type __key_type;
640 typedef typename _TreeIterator::value_type::value_type::second_type __mapped_type;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000641public:
642 typedef bidirectional_iterator_tag iterator_category;
Howard Hinnantb2e8a422011-02-27 18:02:02 +0000643 typedef pair<__key_type, __mapped_type> value_type;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000644 typedef typename _TreeIterator::difference_type difference_type;
645 typedef const value_type& reference;
646 typedef typename __pointer_traits::template
647#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
Howard Hinnant73f3c8a2011-04-11 02:18:41 +0000648 rebind<const value_type>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000649#else
Howard Hinnant73f3c8a2011-04-11 02:18:41 +0000650 rebind<const value_type>::other
Howard Hinnantc51e1022010-05-11 19:42:16 +0000651#endif
652 pointer;
653
Howard Hinnant756c69b2010-09-22 16:48:34 +0000654 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000655 __map_const_iterator() _NOEXCEPT {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000656
Howard Hinnant756c69b2010-09-22 16:48:34 +0000657 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000658 __map_const_iterator(_TreeIterator __i) _NOEXCEPT : __i_(__i) {}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000659 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000660 __map_const_iterator(
661 __map_iterator<typename _TreeIterator::__non_const_iterator> __i)
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000662 _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +0000663 : __i_(__i.__i_) {}
664
Howard Hinnant756c69b2010-09-22 16:48:34 +0000665 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2d0046b2013-06-19 21:29:40 +0000666 reference operator*() const {return __i_->__cc;}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000667 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2d0046b2013-06-19 21:29:40 +0000668 pointer operator->() const {return pointer_traits<pointer>::pointer_to(__i_->__cc);}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000669
Howard Hinnant756c69b2010-09-22 16:48:34 +0000670 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000671 __map_const_iterator& operator++() {++__i_; return *this;}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000672 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000673 __map_const_iterator operator++(int)
674 {
675 __map_const_iterator __t(*this);
676 ++(*this);
677 return __t;
678 }
679
Howard Hinnant756c69b2010-09-22 16:48:34 +0000680 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000681 __map_const_iterator& operator--() {--__i_; return *this;}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000682 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000683 __map_const_iterator operator--(int)
684 {
685 __map_const_iterator __t(*this);
686 --(*this);
687 return __t;
688 }
689
Howard Hinnant756c69b2010-09-22 16:48:34 +0000690 friend _LIBCPP_INLINE_VISIBILITY
691 bool operator==(const __map_const_iterator& __x, const __map_const_iterator& __y)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000692 {return __x.__i_ == __y.__i_;}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000693 friend _LIBCPP_INLINE_VISIBILITY
694 bool operator!=(const __map_const_iterator& __x, const __map_const_iterator& __y)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000695 {return __x.__i_ != __y.__i_;}
696
Howard Hinnanta37d3cf2013-08-12 18:38:34 +0000697 template <class, class, class, class> friend class _LIBCPP_TYPE_VIS_ONLY map;
698 template <class, class, class, class> friend class _LIBCPP_TYPE_VIS_ONLY multimap;
699 template <class, class, class> friend class _LIBCPP_TYPE_VIS_ONLY __tree_const_iterator;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000700};
701
702template <class _Key, class _Tp, class _Compare = less<_Key>,
703 class _Allocator = allocator<pair<const _Key, _Tp> > >
Howard Hinnanta37d3cf2013-08-12 18:38:34 +0000704class _LIBCPP_TYPE_VIS_ONLY map
Howard Hinnantc51e1022010-05-11 19:42:16 +0000705{
706public:
707 // types:
708 typedef _Key key_type;
709 typedef _Tp mapped_type;
710 typedef pair<const key_type, mapped_type> value_type;
Howard Hinnant2d0046b2013-06-19 21:29:40 +0000711 typedef pair<key_type, mapped_type> __nc_value_type;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000712 typedef _Compare key_compare;
713 typedef _Allocator allocator_type;
714 typedef value_type& reference;
715 typedef const value_type& const_reference;
716
Howard Hinnanta37d3cf2013-08-12 18:38:34 +0000717 class _LIBCPP_TYPE_VIS_ONLY value_compare
Howard Hinnantc51e1022010-05-11 19:42:16 +0000718 : public binary_function<value_type, value_type, bool>
719 {
720 friend class map;
721 protected:
722 key_compare comp;
723
Howard Hinnant756c69b2010-09-22 16:48:34 +0000724 _LIBCPP_INLINE_VISIBILITY value_compare(key_compare c) : comp(c) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000725 public:
Howard Hinnant756c69b2010-09-22 16:48:34 +0000726 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000727 bool operator()(const value_type& __x, const value_type& __y) const
728 {return comp(__x.first, __y.first);}
729 };
730
731private:
Howard Hinnant2d0046b2013-06-19 21:29:40 +0000732
733#if __cplusplus >= 201103L
734 union __value_type
735 {
736 typedef typename map::value_type value_type;
737 typedef typename map::__nc_value_type __nc_value_type;
738 value_type __cc;
739 __nc_value_type __nc;
740
741 template <class ..._Args>
742 __value_type(_Args&& ...__args)
743 : __cc(std::forward<_Args>(__args)...) {}
744
745 __value_type(const __value_type& __v)
746 : __cc(std::move(__v.__cc)) {}
747
748 __value_type(__value_type&& __v)
749 : __nc(std::move(__v.__nc)) {}
750
751 __value_type& operator=(const __value_type& __v)
752 {__nc = __v.__cc; return *this;}
753
754 __value_type& operator=(__value_type&& __v)
755 {__nc = std::move(__v.__nc); return *this;}
756
757 ~__value_type() {__cc.~value_type();}
Howard Hinnant2d0046b2013-06-19 21:29:40 +0000758 };
759#else
760 struct __value_type
761 {
762 typedef typename map::value_type value_type;
763 value_type __cc;
764
765 __value_type() {}
766
767 template <class _A0>
768 __value_type(const _A0& __a0)
769 : __cc(__a0) {}
770
771 template <class _A0, class _A1>
772 __value_type(const _A0& __a0, const _A1& __a1)
773 : __cc(__a0, __a1) {}
Howard Hinnant2d0046b2013-06-19 21:29:40 +0000774 };
775#endif
Howard Hinnant90b91592013-07-05 18:06:00 +0000776 typedef __map_value_compare<key_type, __value_type, key_compare> __vc;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000777 typedef typename allocator_traits<allocator_type>::template
778#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
779 rebind_alloc<__value_type>
780#else
781 rebind_alloc<__value_type>::other
782#endif
783 __allocator_type;
784 typedef __tree<__value_type, __vc, __allocator_type> __base;
785 typedef typename __base::__node_traits __node_traits;
786 typedef allocator_traits<allocator_type> __alloc_traits;
787
788 __base __tree_;
789
790public:
791 typedef typename __alloc_traits::pointer pointer;
792 typedef typename __alloc_traits::const_pointer const_pointer;
793 typedef typename __alloc_traits::size_type size_type;
794 typedef typename __alloc_traits::difference_type difference_type;
795 typedef __map_iterator<typename __base::iterator> iterator;
796 typedef __map_const_iterator<typename __base::const_iterator> const_iterator;
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000797 typedef _VSTD::reverse_iterator<iterator> reverse_iterator;
798 typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000799
Howard Hinnant756c69b2010-09-22 16:48:34 +0000800 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000801 explicit map(const key_compare& __comp = key_compare())
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000802 _NOEXCEPT_(
803 is_nothrow_default_constructible<allocator_type>::value &&
804 is_nothrow_default_constructible<key_compare>::value &&
805 is_nothrow_copy_constructible<key_compare>::value)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000806 : __tree_(__vc(__comp)) {}
807
Howard Hinnant756c69b2010-09-22 16:48:34 +0000808 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000809 explicit map(const key_compare& __comp, const allocator_type& __a)
810 : __tree_(__vc(__comp), __a) {}
811
812 template <class _InputIterator>
Howard Hinnant756c69b2010-09-22 16:48:34 +0000813 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000814 map(_InputIterator __f, _InputIterator __l,
815 const key_compare& __comp = key_compare())
816 : __tree_(__vc(__comp))
817 {
818 insert(__f, __l);
819 }
820
821 template <class _InputIterator>
Howard Hinnant756c69b2010-09-22 16:48:34 +0000822 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000823 map(_InputIterator __f, _InputIterator __l,
824 const key_compare& __comp, const allocator_type& __a)
825 : __tree_(__vc(__comp), __a)
826 {
827 insert(__f, __l);
828 }
829
Howard Hinnant756c69b2010-09-22 16:48:34 +0000830 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000831 map(const map& __m)
832 : __tree_(__m.__tree_)
833 {
834 insert(__m.begin(), __m.end());
835 }
836
Howard Hinnantd3a657f2011-07-01 19:24:36 +0000837 _LIBCPP_INLINE_VISIBILITY
838 map& operator=(const map& __m)
839 {
Howard Hinnant2d0046b2013-06-19 21:29:40 +0000840#if __cplusplus >= 201103L
Howard Hinnantd3a657f2011-07-01 19:24:36 +0000841 __tree_ = __m.__tree_;
Howard Hinnant2d0046b2013-06-19 21:29:40 +0000842#else
843 __tree_.clear();
844 __tree_.value_comp() = __m.__tree_.value_comp();
845 __tree_.__copy_assign_alloc(__m.__tree_);
846 insert(__m.begin(), __m.end());
847#endif
Howard Hinnantd3a657f2011-07-01 19:24:36 +0000848 return *this;
849 }
850
Howard Hinnant74279a52010-09-04 23:28:19 +0000851#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +0000852
Howard Hinnant756c69b2010-09-22 16:48:34 +0000853 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000854 map(map&& __m)
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000855 _NOEXCEPT_(is_nothrow_move_constructible<__base>::value)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000856 : __tree_(_VSTD::move(__m.__tree_))
Howard Hinnantc51e1022010-05-11 19:42:16 +0000857 {
858 }
859
860 map(map&& __m, const allocator_type& __a);
861
Howard Hinnant756c69b2010-09-22 16:48:34 +0000862 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant33711792011-08-12 21:56:02 +0000863 map& operator=(map&& __m)
864 _NOEXCEPT_(is_nothrow_move_assignable<__base>::value)
865 {
866 __tree_ = _VSTD::move(__m.__tree_);
867 return *this;
868 }
869
870#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
871
872#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
873
874 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000875 map(initializer_list<value_type> __il, const key_compare& __comp = key_compare())
876 : __tree_(__vc(__comp))
877 {
878 insert(__il.begin(), __il.end());
879 }
880
Howard Hinnant756c69b2010-09-22 16:48:34 +0000881 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000882 map(initializer_list<value_type> __il, const key_compare& __comp, const allocator_type& __a)
883 : __tree_(__vc(__comp), __a)
884 {
885 insert(__il.begin(), __il.end());
886 }
887
Howard Hinnant756c69b2010-09-22 16:48:34 +0000888 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000889 map& operator=(initializer_list<value_type> __il)
890 {
891 __tree_.__assign_unique(__il.begin(), __il.end());
892 return *this;
893 }
894
Howard Hinnant33711792011-08-12 21:56:02 +0000895#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000896
Howard Hinnant756c69b2010-09-22 16:48:34 +0000897 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000898 explicit map(const allocator_type& __a)
899 : __tree_(__a)
900 {
901 }
902
Howard Hinnant756c69b2010-09-22 16:48:34 +0000903 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000904 map(const map& __m, const allocator_type& __a)
905 : __tree_(__m.__tree_.value_comp(), __a)
906 {
907 insert(__m.begin(), __m.end());
908 }
909
Howard Hinnant756c69b2010-09-22 16:48:34 +0000910 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000911 iterator begin() _NOEXCEPT {return __tree_.begin();}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000912 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000913 const_iterator begin() const _NOEXCEPT {return __tree_.begin();}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000914 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000915 iterator end() _NOEXCEPT {return __tree_.end();}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000916 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000917 const_iterator end() const _NOEXCEPT {return __tree_.end();}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000918
Howard Hinnant756c69b2010-09-22 16:48:34 +0000919 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000920 reverse_iterator rbegin() _NOEXCEPT {return reverse_iterator(end());}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000921 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000922 const_reverse_iterator rbegin() const _NOEXCEPT
923 {return const_reverse_iterator(end());}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000924 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000925 reverse_iterator rend() _NOEXCEPT
926 {return reverse_iterator(begin());}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000927 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000928 const_reverse_iterator rend() const _NOEXCEPT
929 {return const_reverse_iterator(begin());}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000930
Howard Hinnant756c69b2010-09-22 16:48:34 +0000931 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000932 const_iterator cbegin() const _NOEXCEPT {return begin();}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000933 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000934 const_iterator cend() const _NOEXCEPT {return end();}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000935 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000936 const_reverse_iterator crbegin() const _NOEXCEPT {return rbegin();}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000937 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000938 const_reverse_iterator crend() const _NOEXCEPT {return rend();}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000939
Howard Hinnant756c69b2010-09-22 16:48:34 +0000940 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000941 bool empty() const _NOEXCEPT {return __tree_.size() == 0;}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000942 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000943 size_type size() const _NOEXCEPT {return __tree_.size();}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000944 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000945 size_type max_size() const _NOEXCEPT {return __tree_.max_size();}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000946
947 mapped_type& operator[](const key_type& __k);
Howard Hinnant74279a52010-09-04 23:28:19 +0000948#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +0000949 mapped_type& operator[](key_type&& __k);
950#endif
951
952 mapped_type& at(const key_type& __k);
953 const mapped_type& at(const key_type& __k) const;
954
Howard Hinnant756c69b2010-09-22 16:48:34 +0000955 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000956 allocator_type get_allocator() const _NOEXCEPT {return __tree_.__alloc();}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000957 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000958 key_compare key_comp() const {return __tree_.value_comp().key_comp();}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000959 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000960 value_compare value_comp() const {return value_compare(__tree_.value_comp().key_comp());}
961
Howard Hinnant74279a52010-09-04 23:28:19 +0000962#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant74279a52010-09-04 23:28:19 +0000963#ifndef _LIBCPP_HAS_NO_VARIADICS
964
Howard Hinnant29eb9b82012-05-25 22:04:21 +0000965 template <class ..._Args>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000966 pair<iterator, bool>
Howard Hinnant29eb9b82012-05-25 22:04:21 +0000967 emplace(_Args&& ...__args);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000968
Howard Hinnant29eb9b82012-05-25 22:04:21 +0000969 template <class ..._Args>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000970 iterator
Howard Hinnant29eb9b82012-05-25 22:04:21 +0000971 emplace_hint(const_iterator __p, _Args&& ...__args);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000972
Howard Hinnant74279a52010-09-04 23:28:19 +0000973#endif // _LIBCPP_HAS_NO_VARIADICS
974
Howard Hinnantc834c512011-11-29 18:15:50 +0000975 template <class _Pp,
976 class = typename enable_if<is_constructible<value_type, _Pp>::value>::type>
Howard Hinnant756c69b2010-09-22 16:48:34 +0000977 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc834c512011-11-29 18:15:50 +0000978 pair<iterator, bool> insert(_Pp&& __p)
979 {return __tree_.__insert_unique(_VSTD::forward<_Pp>(__p));}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000980
Howard Hinnantc834c512011-11-29 18:15:50 +0000981 template <class _Pp,
982 class = typename enable_if<is_constructible<value_type, _Pp>::value>::type>
Howard Hinnant756c69b2010-09-22 16:48:34 +0000983 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc834c512011-11-29 18:15:50 +0000984 iterator insert(const_iterator __pos, _Pp&& __p)
985 {return __tree_.__insert_unique(__pos.__i_, _VSTD::forward<_Pp>(__p));}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000986
Howard Hinnant74279a52010-09-04 23:28:19 +0000987#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +0000988
Howard Hinnant756c69b2010-09-22 16:48:34 +0000989 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000990 pair<iterator, bool>
991 insert(const value_type& __v) {return __tree_.__insert_unique(__v);}
992
Howard Hinnant756c69b2010-09-22 16:48:34 +0000993 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000994 iterator
995 insert(const_iterator __p, const value_type& __v)
996 {return __tree_.__insert_unique(__p.__i_, __v);}
997
998 template <class _InputIterator>
Howard Hinnant756c69b2010-09-22 16:48:34 +0000999 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001000 void insert(_InputIterator __f, _InputIterator __l)
1001 {
1002 for (const_iterator __e = cend(); __f != __l; ++__f)
1003 insert(__e.__i_, *__f);
1004 }
1005
Howard Hinnant33711792011-08-12 21:56:02 +00001006#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1007
Howard Hinnant756c69b2010-09-22 16:48:34 +00001008 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001009 void insert(initializer_list<value_type> __il)
1010 {insert(__il.begin(), __il.end());}
1011
Howard Hinnant33711792011-08-12 21:56:02 +00001012#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1013
Howard Hinnant756c69b2010-09-22 16:48:34 +00001014 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001015 iterator erase(const_iterator __p) {return __tree_.erase(__p.__i_);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001016 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001017 size_type erase(const key_type& __k)
1018 {return __tree_.__erase_unique(__k);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001019 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001020 iterator erase(const_iterator __f, const_iterator __l)
1021 {return __tree_.erase(__f.__i_, __l.__i_);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001022 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001023 void clear() _NOEXCEPT {__tree_.clear();}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001024
Howard Hinnant756c69b2010-09-22 16:48:34 +00001025 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001026 void swap(map& __m)
1027 _NOEXCEPT_(__is_nothrow_swappable<__base>::value)
1028 {__tree_.swap(__m.__tree_);}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001029
Howard Hinnant756c69b2010-09-22 16:48:34 +00001030 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001031 iterator find(const key_type& __k) {return __tree_.find(__k);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001032 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001033 const_iterator find(const key_type& __k) const {return __tree_.find(__k);}
Marshall Clowebb57322013-08-13 22:18:47 +00001034#if _LIBCPP_STD_VER > 11
1035 template <typename _K2>
1036 _LIBCPP_INLINE_VISIBILITY
1037 typename enable_if<__is_transparent<_Compare, _K2>::value,iterator>::type
1038 find(const _K2& __k) {return __tree_.find(__k);}
1039 template <typename _K2>
1040 _LIBCPP_INLINE_VISIBILITY
1041 typename enable_if<__is_transparent<_Compare, _K2>::value,const_iterator>::type
1042 find(const _K2& __k) const {return __tree_.find(__k);}
1043#endif
1044
Howard Hinnant756c69b2010-09-22 16:48:34 +00001045 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001046 size_type count(const key_type& __k) const
1047 {return __tree_.__count_unique(__k);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001048 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001049 iterator lower_bound(const key_type& __k)
1050 {return __tree_.lower_bound(__k);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001051 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001052 const_iterator lower_bound(const key_type& __k) const
1053 {return __tree_.lower_bound(__k);}
Marshall Clowebb57322013-08-13 22:18:47 +00001054#if _LIBCPP_STD_VER > 11
1055 template <typename _K2>
1056 _LIBCPP_INLINE_VISIBILITY
1057 typename enable_if<__is_transparent<_Compare, _K2>::value,iterator>::type
1058 lower_bound(const _K2& __k) {return __tree_.lower_bound(__k);}
1059
1060 template <typename _K2>
1061 _LIBCPP_INLINE_VISIBILITY
1062 typename enable_if<__is_transparent<_Compare, _K2>::value,const_iterator>::type
1063 lower_bound(const _K2& __k) const {return __tree_.lower_bound(__k);}
1064#endif
1065
Howard Hinnant756c69b2010-09-22 16:48:34 +00001066 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001067 iterator upper_bound(const key_type& __k)
1068 {return __tree_.upper_bound(__k);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001069 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001070 const_iterator upper_bound(const key_type& __k) const
1071 {return __tree_.upper_bound(__k);}
Marshall Clowebb57322013-08-13 22:18:47 +00001072#if _LIBCPP_STD_VER > 11
1073 template <typename _K2>
1074 _LIBCPP_INLINE_VISIBILITY
1075 typename enable_if<__is_transparent<_Compare, _K2>::value,iterator>::type
1076 upper_bound(const _K2& __k) {return __tree_.upper_bound(__k);}
1077 template <typename _K2>
1078 _LIBCPP_INLINE_VISIBILITY
1079 typename enable_if<__is_transparent<_Compare, _K2>::value,const_iterator>::type
1080 upper_bound(const _K2& __k) const {return __tree_.upper_bound(__k);}
1081#endif
1082
Howard Hinnant756c69b2010-09-22 16:48:34 +00001083 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001084 pair<iterator,iterator> equal_range(const key_type& __k)
1085 {return __tree_.__equal_range_unique(__k);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001086 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001087 pair<const_iterator,const_iterator> equal_range(const key_type& __k) const
1088 {return __tree_.__equal_range_unique(__k);}
Marshall Clowebb57322013-08-13 22:18:47 +00001089#if _LIBCPP_STD_VER > 11
1090 template <typename _K2>
1091 _LIBCPP_INLINE_VISIBILITY
1092 typename enable_if<__is_transparent<_Compare, _K2>::value,pair<iterator,iterator>>::type
1093 equal_range(const _K2& __k) {return __tree_.__equal_range_unique(__k);}
1094 template <typename _K2>
1095 _LIBCPP_INLINE_VISIBILITY
1096 typename enable_if<__is_transparent<_Compare, _K2>::value,pair<const_iterator,const_iterator>>::type
1097 equal_range(const _K2& __k) const {return __tree_.__equal_range_unique(__k);}
1098#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001099
1100private:
1101 typedef typename __base::__node __node;
1102 typedef typename __base::__node_allocator __node_allocator;
1103 typedef typename __base::__node_pointer __node_pointer;
1104 typedef typename __base::__node_const_pointer __node_const_pointer;
1105 typedef typename __base::__node_base_pointer __node_base_pointer;
1106 typedef typename __base::__node_base_const_pointer __node_base_const_pointer;
Howard Hinnantc834c512011-11-29 18:15:50 +00001107 typedef __map_node_destructor<__node_allocator> _Dp;
1108 typedef unique_ptr<__node, _Dp> __node_holder;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001109
Howard Hinnant74279a52010-09-04 23:28:19 +00001110#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +00001111 __node_holder __construct_node();
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001112 template <class _A0>
Howard Hinnantac7e7482013-07-04 20:59:16 +00001113 __node_holder __construct_node(_A0&& __a0);
1114 __node_holder __construct_node_with_key(key_type&& __k);
Howard Hinnant74279a52010-09-04 23:28:19 +00001115#ifndef _LIBCPP_HAS_NO_VARIADICS
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001116 template <class _A0, class _A1, class ..._Args>
1117 __node_holder __construct_node(_A0&& __a0, _A1&& __a1, _Args&& ...__args);
Howard Hinnant74279a52010-09-04 23:28:19 +00001118#endif // _LIBCPP_HAS_NO_VARIADICS
Howard Hinnantc51e1022010-05-11 19:42:16 +00001119#endif
Howard Hinnantac7e7482013-07-04 20:59:16 +00001120 __node_holder __construct_node_with_key(const key_type& __k);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001121
1122 __node_base_pointer&
1123 __find_equal_key(__node_base_pointer& __parent, const key_type& __k);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001124 __node_base_const_pointer
1125 __find_equal_key(__node_base_const_pointer& __parent, const key_type& __k) const;
1126};
1127
1128// Find place to insert if __k doesn't exist
1129// Set __parent to parent of null leaf
1130// Return reference to null leaf
1131// If __k exists, set parent to node of __k and return reference to node of __k
1132template <class _Key, class _Tp, class _Compare, class _Allocator>
1133typename map<_Key, _Tp, _Compare, _Allocator>::__node_base_pointer&
1134map<_Key, _Tp, _Compare, _Allocator>::__find_equal_key(__node_base_pointer& __parent,
1135 const key_type& __k)
1136{
1137 __node_pointer __nd = __tree_.__root();
1138 if (__nd != nullptr)
1139 {
1140 while (true)
1141 {
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001142 if (__tree_.value_comp().key_comp()(__k, __nd->__value_.__cc.first))
Howard Hinnantc51e1022010-05-11 19:42:16 +00001143 {
1144 if (__nd->__left_ != nullptr)
1145 __nd = static_cast<__node_pointer>(__nd->__left_);
1146 else
1147 {
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001148 __parent = static_cast<__node_base_pointer>(__nd);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001149 return __parent->__left_;
1150 }
1151 }
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001152 else if (__tree_.value_comp().key_comp()(__nd->__value_.__cc.first, __k))
Howard Hinnantc51e1022010-05-11 19:42:16 +00001153 {
1154 if (__nd->__right_ != nullptr)
1155 __nd = static_cast<__node_pointer>(__nd->__right_);
1156 else
1157 {
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001158 __parent = static_cast<__node_base_pointer>(__nd);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001159 return __parent->__right_;
1160 }
1161 }
1162 else
1163 {
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001164 __parent = static_cast<__node_base_pointer>(__nd);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001165 return __parent;
1166 }
1167 }
1168 }
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001169 __parent = static_cast<__node_base_pointer>(__tree_.__end_node());
Howard Hinnantc51e1022010-05-11 19:42:16 +00001170 return __parent->__left_;
1171}
1172
Howard Hinnantc51e1022010-05-11 19:42:16 +00001173// Find __k
1174// Set __parent to parent of null leaf and
1175// return reference to null leaf iv __k does not exist.
1176// If __k exists, set parent to node of __k and return reference to node of __k
1177template <class _Key, class _Tp, class _Compare, class _Allocator>
1178typename map<_Key, _Tp, _Compare, _Allocator>::__node_base_const_pointer
1179map<_Key, _Tp, _Compare, _Allocator>::__find_equal_key(__node_base_const_pointer& __parent,
1180 const key_type& __k) const
1181{
1182 __node_const_pointer __nd = __tree_.__root();
1183 if (__nd != nullptr)
1184 {
1185 while (true)
1186 {
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001187 if (__tree_.value_comp().key_comp()(__k, __nd->__value_.__cc.first))
Howard Hinnantc51e1022010-05-11 19:42:16 +00001188 {
1189 if (__nd->__left_ != nullptr)
1190 __nd = static_cast<__node_pointer>(__nd->__left_);
1191 else
1192 {
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001193 __parent = static_cast<__node_base_pointer>(__nd);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001194 return const_cast<const __node_base_const_pointer&>(__parent->__left_);
1195 }
1196 }
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001197 else if (__tree_.value_comp().key_comp()(__nd->__value_.__cc.first, __k))
Howard Hinnantc51e1022010-05-11 19:42:16 +00001198 {
1199 if (__nd->__right_ != nullptr)
1200 __nd = static_cast<__node_pointer>(__nd->__right_);
1201 else
1202 {
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001203 __parent = static_cast<__node_base_pointer>(__nd);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001204 return const_cast<const __node_base_const_pointer&>(__parent->__right_);
1205 }
1206 }
1207 else
1208 {
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001209 __parent = static_cast<__node_base_pointer>(__nd);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001210 return __parent;
1211 }
1212 }
1213 }
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001214 __parent = static_cast<__node_base_pointer>(__tree_.__end_node());
Howard Hinnantc51e1022010-05-11 19:42:16 +00001215 return const_cast<const __node_base_const_pointer&>(__parent->__left_);
1216}
1217
Howard Hinnant74279a52010-09-04 23:28:19 +00001218#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +00001219
1220template <class _Key, class _Tp, class _Compare, class _Allocator>
1221map<_Key, _Tp, _Compare, _Allocator>::map(map&& __m, const allocator_type& __a)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001222 : __tree_(_VSTD::move(__m.__tree_), __a)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001223{
1224 if (__a != __m.get_allocator())
1225 {
1226 const_iterator __e = cend();
1227 while (!__m.empty())
1228 __tree_.__insert_unique(__e.__i_,
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001229 _VSTD::move(__m.__tree_.remove(__m.begin().__i_)->__value_));
Howard Hinnantc51e1022010-05-11 19:42:16 +00001230 }
1231}
1232
1233template <class _Key, class _Tp, class _Compare, class _Allocator>
1234typename map<_Key, _Tp, _Compare, _Allocator>::__node_holder
1235map<_Key, _Tp, _Compare, _Allocator>::__construct_node()
1236{
1237 __node_allocator& __na = __tree_.__node_alloc();
Howard Hinnantc834c512011-11-29 18:15:50 +00001238 __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001239 __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__cc.first));
Howard Hinnantc51e1022010-05-11 19:42:16 +00001240 __h.get_deleter().__first_constructed = true;
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001241 __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__cc.second));
Howard Hinnantc51e1022010-05-11 19:42:16 +00001242 __h.get_deleter().__second_constructed = true;
1243 return __h;
1244}
1245
1246template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001247template <class _A0>
Howard Hinnantac7e7482013-07-04 20:59:16 +00001248typename map<_Key, _Tp, _Compare, _Allocator>::__node_holder
Howard Hinnantc51e1022010-05-11 19:42:16 +00001249map<_Key, _Tp, _Compare, _Allocator>::__construct_node(_A0&& __a0)
1250{
1251 __node_allocator& __na = __tree_.__node_alloc();
Howard Hinnantc834c512011-11-29 18:15:50 +00001252 __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001253 __node_traits::construct(__na, _VSTD::addressof(__h->__value_), _VSTD::forward<_A0>(__a0));
Howard Hinnantc51e1022010-05-11 19:42:16 +00001254 __h.get_deleter().__first_constructed = true;
1255 __h.get_deleter().__second_constructed = true;
1256 return __h;
1257}
1258
1259template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnantac7e7482013-07-04 20:59:16 +00001260typename map<_Key, _Tp, _Compare, _Allocator>::__node_holder
1261map<_Key, _Tp, _Compare, _Allocator>::__construct_node_with_key(key_type&& __k)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001262{
1263 __node_allocator& __na = __tree_.__node_alloc();
Howard Hinnantc834c512011-11-29 18:15:50 +00001264 __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
Howard Hinnantac7e7482013-07-04 20:59:16 +00001265 __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__cc.first), _VSTD::move(__k));
Howard Hinnantc51e1022010-05-11 19:42:16 +00001266 __h.get_deleter().__first_constructed = true;
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001267 __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__cc.second));
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001268 __h.get_deleter().__second_constructed = true;
Howard Hinnanta31e9682013-08-22 18:29:50 +00001269 return __h;
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001270}
1271
1272#ifndef _LIBCPP_HAS_NO_VARIADICS
1273
1274template <class _Key, class _Tp, class _Compare, class _Allocator>
1275template <class _A0, class _A1, class ..._Args>
1276typename map<_Key, _Tp, _Compare, _Allocator>::__node_holder
1277map<_Key, _Tp, _Compare, _Allocator>::__construct_node(_A0&& __a0, _A1&& __a1, _Args&& ...__args)
1278{
1279 __node_allocator& __na = __tree_.__node_alloc();
1280 __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
1281 __node_traits::construct(__na, _VSTD::addressof(__h->__value_),
1282 _VSTD::forward<_A0>(__a0), _VSTD::forward<_A1>(__a1),
1283 _VSTD::forward<_Args>(__args)...);
1284 __h.get_deleter().__first_constructed = true;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001285 __h.get_deleter().__second_constructed = true;
1286 return __h;
1287}
1288
Howard Hinnant74279a52010-09-04 23:28:19 +00001289#endif // _LIBCPP_HAS_NO_VARIADICS
1290
Howard Hinnantac7e7482013-07-04 20:59:16 +00001291#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +00001292
1293template <class _Key, class _Tp, class _Compare, class _Allocator>
1294typename map<_Key, _Tp, _Compare, _Allocator>::__node_holder
Howard Hinnantac7e7482013-07-04 20:59:16 +00001295map<_Key, _Tp, _Compare, _Allocator>::__construct_node_with_key(const key_type& __k)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001296{
1297 __node_allocator& __na = __tree_.__node_alloc();
Howard Hinnantc834c512011-11-29 18:15:50 +00001298 __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001299 __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__cc.first), __k);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001300 __h.get_deleter().__first_constructed = true;
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001301 __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__cc.second));
Howard Hinnantc51e1022010-05-11 19:42:16 +00001302 __h.get_deleter().__second_constructed = true;
Howard Hinnanta31e9682013-08-22 18:29:50 +00001303 return _VSTD::move(__h); // explicitly moved for C++03
Howard Hinnantc51e1022010-05-11 19:42:16 +00001304}
1305
Howard Hinnantc51e1022010-05-11 19:42:16 +00001306template <class _Key, class _Tp, class _Compare, class _Allocator>
1307_Tp&
1308map<_Key, _Tp, _Compare, _Allocator>::operator[](const key_type& __k)
1309{
1310 __node_base_pointer __parent;
1311 __node_base_pointer& __child = __find_equal_key(__parent, __k);
1312 __node_pointer __r = static_cast<__node_pointer>(__child);
1313 if (__child == nullptr)
1314 {
Howard Hinnantac7e7482013-07-04 20:59:16 +00001315 __node_holder __h = __construct_node_with_key(__k);
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001316 __tree_.__insert_node_at(__parent, __child, static_cast<__node_base_pointer>(__h.get()));
Howard Hinnantc51e1022010-05-11 19:42:16 +00001317 __r = __h.release();
1318 }
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001319 return __r->__value_.__cc.second;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001320}
1321
Howard Hinnant74279a52010-09-04 23:28:19 +00001322#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +00001323
1324template <class _Key, class _Tp, class _Compare, class _Allocator>
1325_Tp&
1326map<_Key, _Tp, _Compare, _Allocator>::operator[](key_type&& __k)
1327{
1328 __node_base_pointer __parent;
1329 __node_base_pointer& __child = __find_equal_key(__parent, __k);
1330 __node_pointer __r = static_cast<__node_pointer>(__child);
1331 if (__child == nullptr)
1332 {
Howard Hinnantac7e7482013-07-04 20:59:16 +00001333 __node_holder __h = __construct_node_with_key(_VSTD::move(__k));
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001334 __tree_.__insert_node_at(__parent, __child, static_cast<__node_base_pointer>(__h.get()));
Howard Hinnantc51e1022010-05-11 19:42:16 +00001335 __r = __h.release();
1336 }
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001337 return __r->__value_.__cc.second;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001338}
1339
Howard Hinnant74279a52010-09-04 23:28:19 +00001340#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +00001341
1342template <class _Key, class _Tp, class _Compare, class _Allocator>
1343_Tp&
1344map<_Key, _Tp, _Compare, _Allocator>::at(const key_type& __k)
1345{
1346 __node_base_pointer __parent;
1347 __node_base_pointer& __child = __find_equal_key(__parent, __k);
Howard Hinnant72f73582010-08-11 17:04:31 +00001348#ifndef _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +00001349 if (__child == nullptr)
1350 throw out_of_range("map::at: key not found");
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001351#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001352 return static_cast<__node_pointer>(__child)->__value_.__cc.second;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001353}
1354
1355template <class _Key, class _Tp, class _Compare, class _Allocator>
1356const _Tp&
1357map<_Key, _Tp, _Compare, _Allocator>::at(const key_type& __k) const
1358{
1359 __node_base_const_pointer __parent;
1360 __node_base_const_pointer __child = __find_equal_key(__parent, __k);
Howard Hinnant72f73582010-08-11 17:04:31 +00001361#ifndef _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +00001362 if (__child == nullptr)
1363 throw out_of_range("map::at: key not found");
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001364#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001365 return static_cast<__node_const_pointer>(__child)->__value_.__cc.second;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001366}
1367
Howard Hinnant74279a52010-09-04 23:28:19 +00001368#if !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001369
1370template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001371template <class ..._Args>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001372pair<typename map<_Key, _Tp, _Compare, _Allocator>::iterator, bool>
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001373map<_Key, _Tp, _Compare, _Allocator>::emplace(_Args&& ...__args)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001374{
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001375 __node_holder __h = __construct_node(_VSTD::forward<_Args>(__args)...);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001376 pair<iterator, bool> __r = __tree_.__node_insert_unique(__h.get());
1377 if (__r.second)
1378 __h.release();
1379 return __r;
1380}
1381
1382template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001383template <class ..._Args>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001384typename map<_Key, _Tp, _Compare, _Allocator>::iterator
1385map<_Key, _Tp, _Compare, _Allocator>::emplace_hint(const_iterator __p,
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001386 _Args&& ...__args)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001387{
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001388 __node_holder __h = __construct_node(_VSTD::forward<_Args>(__args)...);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001389 iterator __r = __tree_.__node_insert_unique(__p.__i_, __h.get());
1390 if (__r.__i_.__ptr_ == __h.get())
1391 __h.release();
1392 return __r;
1393}
1394
Howard Hinnant74279a52010-09-04 23:28:19 +00001395#endif // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001396
1397template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001398inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001399bool
1400operator==(const map<_Key, _Tp, _Compare, _Allocator>& __x,
1401 const map<_Key, _Tp, _Compare, _Allocator>& __y)
1402{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001403 return __x.size() == __y.size() && _VSTD::equal(__x.begin(), __x.end(), __y.begin());
Howard Hinnantc51e1022010-05-11 19:42:16 +00001404}
1405
1406template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001407inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001408bool
1409operator< (const map<_Key, _Tp, _Compare, _Allocator>& __x,
1410 const map<_Key, _Tp, _Compare, _Allocator>& __y)
1411{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001412 return _VSTD::lexicographical_compare(__x.begin(), __x.end(), __y.begin(), __y.end());
Howard Hinnantc51e1022010-05-11 19:42:16 +00001413}
1414
1415template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001416inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001417bool
1418operator!=(const map<_Key, _Tp, _Compare, _Allocator>& __x,
1419 const map<_Key, _Tp, _Compare, _Allocator>& __y)
1420{
1421 return !(__x == __y);
1422}
1423
1424template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001425inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001426bool
1427operator> (const map<_Key, _Tp, _Compare, _Allocator>& __x,
1428 const map<_Key, _Tp, _Compare, _Allocator>& __y)
1429{
1430 return __y < __x;
1431}
1432
1433template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001434inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001435bool
1436operator>=(const map<_Key, _Tp, _Compare, _Allocator>& __x,
1437 const map<_Key, _Tp, _Compare, _Allocator>& __y)
1438{
1439 return !(__x < __y);
1440}
1441
1442template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001443inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001444bool
1445operator<=(const map<_Key, _Tp, _Compare, _Allocator>& __x,
1446 const map<_Key, _Tp, _Compare, _Allocator>& __y)
1447{
1448 return !(__y < __x);
1449}
1450
1451template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001452inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001453void
1454swap(map<_Key, _Tp, _Compare, _Allocator>& __x,
1455 map<_Key, _Tp, _Compare, _Allocator>& __y)
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001456 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
Howard Hinnantc51e1022010-05-11 19:42:16 +00001457{
1458 __x.swap(__y);
1459}
1460
1461template <class _Key, class _Tp, class _Compare = less<_Key>,
1462 class _Allocator = allocator<pair<const _Key, _Tp> > >
Howard Hinnanta37d3cf2013-08-12 18:38:34 +00001463class _LIBCPP_TYPE_VIS_ONLY multimap
Howard Hinnantc51e1022010-05-11 19:42:16 +00001464{
1465public:
1466 // types:
1467 typedef _Key key_type;
1468 typedef _Tp mapped_type;
1469 typedef pair<const key_type, mapped_type> value_type;
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001470 typedef pair<key_type, mapped_type> __nc_value_type;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001471 typedef _Compare key_compare;
1472 typedef _Allocator allocator_type;
1473 typedef value_type& reference;
1474 typedef const value_type& const_reference;
1475
Howard Hinnanta37d3cf2013-08-12 18:38:34 +00001476 class _LIBCPP_TYPE_VIS_ONLY value_compare
Howard Hinnantc51e1022010-05-11 19:42:16 +00001477 : public binary_function<value_type, value_type, bool>
1478 {
1479 friend class multimap;
1480 protected:
1481 key_compare comp;
1482
Howard Hinnant756c69b2010-09-22 16:48:34 +00001483 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001484 value_compare(key_compare c) : comp(c) {}
1485 public:
Howard Hinnant756c69b2010-09-22 16:48:34 +00001486 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001487 bool operator()(const value_type& __x, const value_type& __y) const
1488 {return comp(__x.first, __y.first);}
1489 };
1490
1491private:
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001492#if __cplusplus >= 201103L
1493 union __value_type
1494 {
1495 typedef typename multimap::value_type value_type;
1496 typedef typename multimap::__nc_value_type __nc_value_type;
1497 value_type __cc;
1498 __nc_value_type __nc;
1499
1500 template <class ..._Args>
1501 __value_type(_Args&& ...__args)
1502 : __cc(std::forward<_Args>(__args)...) {}
1503
1504 __value_type(const __value_type& __v)
1505 : __cc(std::move(__v.__cc)) {}
1506
1507 __value_type(__value_type&& __v)
1508 : __nc(std::move(__v.__nc)) {}
1509
1510 __value_type& operator=(const __value_type& __v)
1511 {__nc = __v.__cc; return *this;}
1512
1513 __value_type& operator=(__value_type&& __v)
1514 {__nc = std::move(__v.__nc); return *this;}
1515
1516 ~__value_type() {__cc.~value_type();}
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001517 };
1518#else
1519 struct __value_type
1520 {
1521 typedef typename multimap::value_type value_type;
1522 value_type __cc;
1523
1524 __value_type() {}
1525
1526 template <class _A0>
1527 __value_type(const _A0& __a0)
1528 : __cc(__a0) {}
1529
1530 template <class _A0, class _A1>
1531 __value_type(const _A0& __a0, const _A1& __a1)
1532 : __cc(__a0, __a1) {}
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001533 };
1534#endif
Howard Hinnant90b91592013-07-05 18:06:00 +00001535 typedef __map_value_compare<key_type, __value_type, key_compare> __vc;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001536 typedef typename allocator_traits<allocator_type>::template
1537#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
1538 rebind_alloc<__value_type>
1539#else
1540 rebind_alloc<__value_type>::other
1541#endif
1542 __allocator_type;
1543 typedef __tree<__value_type, __vc, __allocator_type> __base;
1544 typedef typename __base::__node_traits __node_traits;
1545 typedef allocator_traits<allocator_type> __alloc_traits;
1546
1547 __base __tree_;
1548
1549public:
1550 typedef typename __alloc_traits::pointer pointer;
1551 typedef typename __alloc_traits::const_pointer const_pointer;
1552 typedef typename __alloc_traits::size_type size_type;
1553 typedef typename __alloc_traits::difference_type difference_type;
1554 typedef __map_iterator<typename __base::iterator> iterator;
1555 typedef __map_const_iterator<typename __base::const_iterator> const_iterator;
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001556 typedef _VSTD::reverse_iterator<iterator> reverse_iterator;
1557 typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001558
Howard Hinnant756c69b2010-09-22 16:48:34 +00001559 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001560 explicit multimap(const key_compare& __comp = key_compare())
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001561 _NOEXCEPT_(
1562 is_nothrow_default_constructible<allocator_type>::value &&
1563 is_nothrow_default_constructible<key_compare>::value &&
1564 is_nothrow_copy_constructible<key_compare>::value)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001565 : __tree_(__vc(__comp)) {}
1566
Howard Hinnant756c69b2010-09-22 16:48:34 +00001567 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001568 explicit multimap(const key_compare& __comp, const allocator_type& __a)
1569 : __tree_(__vc(__comp), __a) {}
1570
1571 template <class _InputIterator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001572 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001573 multimap(_InputIterator __f, _InputIterator __l,
1574 const key_compare& __comp = key_compare())
1575 : __tree_(__vc(__comp))
1576 {
1577 insert(__f, __l);
1578 }
1579
1580 template <class _InputIterator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001581 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001582 multimap(_InputIterator __f, _InputIterator __l,
1583 const key_compare& __comp, const allocator_type& __a)
1584 : __tree_(__vc(__comp), __a)
1585 {
1586 insert(__f, __l);
1587 }
1588
Howard Hinnant756c69b2010-09-22 16:48:34 +00001589 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001590 multimap(const multimap& __m)
1591 : __tree_(__m.__tree_.value_comp(),
1592 __alloc_traits::select_on_container_copy_construction(__m.__tree_.__alloc()))
1593 {
1594 insert(__m.begin(), __m.end());
1595 }
1596
Howard Hinnantd3a657f2011-07-01 19:24:36 +00001597 _LIBCPP_INLINE_VISIBILITY
1598 multimap& operator=(const multimap& __m)
1599 {
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001600#if __cplusplus >= 201103L
Howard Hinnantd3a657f2011-07-01 19:24:36 +00001601 __tree_ = __m.__tree_;
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001602#else
1603 __tree_.clear();
1604 __tree_.value_comp() = __m.__tree_.value_comp();
1605 __tree_.__copy_assign_alloc(__m.__tree_);
1606 insert(__m.begin(), __m.end());
1607#endif
Howard Hinnantd3a657f2011-07-01 19:24:36 +00001608 return *this;
1609 }
1610
Howard Hinnant74279a52010-09-04 23:28:19 +00001611#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +00001612
Howard Hinnant756c69b2010-09-22 16:48:34 +00001613 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001614 multimap(multimap&& __m)
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001615 _NOEXCEPT_(is_nothrow_move_constructible<__base>::value)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001616 : __tree_(_VSTD::move(__m.__tree_))
Howard Hinnantc51e1022010-05-11 19:42:16 +00001617 {
1618 }
1619
1620 multimap(multimap&& __m, const allocator_type& __a);
1621
Howard Hinnant756c69b2010-09-22 16:48:34 +00001622 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant33711792011-08-12 21:56:02 +00001623 multimap& operator=(multimap&& __m)
1624 _NOEXCEPT_(is_nothrow_move_assignable<__base>::value)
1625 {
1626 __tree_ = _VSTD::move(__m.__tree_);
1627 return *this;
1628 }
1629
1630#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
1631
1632#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1633
1634 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001635 multimap(initializer_list<value_type> __il, const key_compare& __comp = key_compare())
1636 : __tree_(__vc(__comp))
1637 {
1638 insert(__il.begin(), __il.end());
1639 }
1640
Howard Hinnant756c69b2010-09-22 16:48:34 +00001641 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001642 multimap(initializer_list<value_type> __il, const key_compare& __comp, const allocator_type& __a)
1643 : __tree_(__vc(__comp), __a)
1644 {
1645 insert(__il.begin(), __il.end());
1646 }
1647
Howard Hinnant756c69b2010-09-22 16:48:34 +00001648 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001649 multimap& operator=(initializer_list<value_type> __il)
1650 {
1651 __tree_.__assign_multi(__il.begin(), __il.end());
1652 return *this;
1653 }
Howard Hinnant33711792011-08-12 21:56:02 +00001654
1655#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantc51e1022010-05-11 19:42:16 +00001656
Howard Hinnant756c69b2010-09-22 16:48:34 +00001657 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001658 explicit multimap(const allocator_type& __a)
1659 : __tree_(__a)
1660 {
1661 }
1662
Howard Hinnant756c69b2010-09-22 16:48:34 +00001663 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001664 multimap(const multimap& __m, const allocator_type& __a)
1665 : __tree_(__m.__tree_.value_comp(), __a)
1666 {
1667 insert(__m.begin(), __m.end());
1668 }
1669
Howard Hinnant756c69b2010-09-22 16:48:34 +00001670 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001671 iterator begin() _NOEXCEPT {return __tree_.begin();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001672 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001673 const_iterator begin() const _NOEXCEPT {return __tree_.begin();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001674 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001675 iterator end() _NOEXCEPT {return __tree_.end();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001676 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001677 const_iterator end() const _NOEXCEPT {return __tree_.end();}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001678
Howard Hinnant756c69b2010-09-22 16:48:34 +00001679 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001680 reverse_iterator rbegin() _NOEXCEPT {return reverse_iterator(end());}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001681 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001682 const_reverse_iterator rbegin() const _NOEXCEPT
1683 {return const_reverse_iterator(end());}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001684 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001685 reverse_iterator rend() _NOEXCEPT {return reverse_iterator(begin());}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001686 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001687 const_reverse_iterator rend() const _NOEXCEPT
1688 {return const_reverse_iterator(begin());}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001689
Howard Hinnant756c69b2010-09-22 16:48:34 +00001690 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001691 const_iterator cbegin() const _NOEXCEPT {return begin();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001692 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001693 const_iterator cend() const _NOEXCEPT {return end();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001694 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001695 const_reverse_iterator crbegin() const _NOEXCEPT {return rbegin();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001696 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001697 const_reverse_iterator crend() const _NOEXCEPT {return rend();}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001698
Howard Hinnant756c69b2010-09-22 16:48:34 +00001699 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001700 bool empty() const _NOEXCEPT {return __tree_.size() == 0;}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001701 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001702 size_type size() const _NOEXCEPT {return __tree_.size();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001703 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001704 size_type max_size() const _NOEXCEPT {return __tree_.max_size();}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001705
Howard Hinnant756c69b2010-09-22 16:48:34 +00001706 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001707 allocator_type get_allocator() const _NOEXCEPT {return __tree_.__alloc();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001708 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001709 key_compare key_comp() const {return __tree_.value_comp().key_comp();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001710 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001711 value_compare value_comp() const
1712 {return value_compare(__tree_.value_comp().key_comp());}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001713
Howard Hinnant74279a52010-09-04 23:28:19 +00001714#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant74279a52010-09-04 23:28:19 +00001715#ifndef _LIBCPP_HAS_NO_VARIADICS
1716
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001717 template <class ..._Args>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001718 iterator
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001719 emplace(_Args&& ...__args);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001720
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001721 template <class ..._Args>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001722 iterator
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001723 emplace_hint(const_iterator __p, _Args&& ...__args);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001724
Howard Hinnant74279a52010-09-04 23:28:19 +00001725#endif // _LIBCPP_HAS_NO_VARIADICS
1726
Howard Hinnantc834c512011-11-29 18:15:50 +00001727 template <class _Pp,
1728 class = typename enable_if<is_constructible<value_type, _Pp>::value>::type>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001729 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc834c512011-11-29 18:15:50 +00001730 iterator insert(_Pp&& __p)
1731 {return __tree_.__insert_multi(_VSTD::forward<_Pp>(__p));}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001732
Howard Hinnantc834c512011-11-29 18:15:50 +00001733 template <class _Pp,
1734 class = typename enable_if<is_constructible<value_type, _Pp>::value>::type>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001735 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc834c512011-11-29 18:15:50 +00001736 iterator insert(const_iterator __pos, _Pp&& __p)
1737 {return __tree_.__insert_multi(__pos.__i_, _VSTD::forward<_Pp>(__p));}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001738
Howard Hinnant74279a52010-09-04 23:28:19 +00001739#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +00001740
Howard Hinnant756c69b2010-09-22 16:48:34 +00001741 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001742 iterator insert(const value_type& __v) {return __tree_.__insert_multi(__v);}
1743
Howard Hinnant756c69b2010-09-22 16:48:34 +00001744 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001745 iterator insert(const_iterator __p, const value_type& __v)
1746 {return __tree_.__insert_multi(__p.__i_, __v);}
1747
1748 template <class _InputIterator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001749 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001750 void insert(_InputIterator __f, _InputIterator __l)
1751 {
1752 for (const_iterator __e = cend(); __f != __l; ++__f)
1753 __tree_.__insert_multi(__e.__i_, *__f);
1754 }
1755
Howard Hinnant33711792011-08-12 21:56:02 +00001756#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1757
Howard Hinnant756c69b2010-09-22 16:48:34 +00001758 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001759 void insert(initializer_list<value_type> __il)
1760 {insert(__il.begin(), __il.end());}
1761
Howard Hinnant33711792011-08-12 21:56:02 +00001762#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1763
Howard Hinnant756c69b2010-09-22 16:48:34 +00001764 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001765 iterator erase(const_iterator __p) {return __tree_.erase(__p.__i_);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001766 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001767 size_type erase(const key_type& __k) {return __tree_.__erase_multi(__k);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001768 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001769 iterator erase(const_iterator __f, const_iterator __l)
1770 {return __tree_.erase(__f.__i_, __l.__i_);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001771 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001772 void clear() {__tree_.clear();}
1773
Howard Hinnant756c69b2010-09-22 16:48:34 +00001774 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001775 void swap(multimap& __m)
1776 _NOEXCEPT_(__is_nothrow_swappable<__base>::value)
1777 {__tree_.swap(__m.__tree_);}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001778
Howard Hinnant756c69b2010-09-22 16:48:34 +00001779 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001780 iterator find(const key_type& __k) {return __tree_.find(__k);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001781 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001782 const_iterator find(const key_type& __k) const {return __tree_.find(__k);}
Marshall Clowebb57322013-08-13 22:18:47 +00001783#if _LIBCPP_STD_VER > 11
1784 template <typename _K2>
1785 _LIBCPP_INLINE_VISIBILITY
1786 typename enable_if<__is_transparent<_Compare, _K2>::value,iterator>::type
1787 find(const _K2& __k) {return __tree_.find(__k);}
1788 template <typename _K2>
1789 _LIBCPP_INLINE_VISIBILITY
1790 typename enable_if<__is_transparent<_Compare, _K2>::value,const_iterator>::type
1791 find(const _K2& __k) const {return __tree_.find(__k);}
1792#endif
1793
Howard Hinnant756c69b2010-09-22 16:48:34 +00001794 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001795 size_type count(const key_type& __k) const
1796 {return __tree_.__count_multi(__k);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001797 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001798 iterator lower_bound(const key_type& __k)
1799 {return __tree_.lower_bound(__k);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001800 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001801 const_iterator lower_bound(const key_type& __k) const
1802 {return __tree_.lower_bound(__k);}
Marshall Clowebb57322013-08-13 22:18:47 +00001803#if _LIBCPP_STD_VER > 11
1804 template <typename _K2>
1805 _LIBCPP_INLINE_VISIBILITY
1806 typename enable_if<__is_transparent<_Compare, _K2>::value,iterator>::type
1807 lower_bound(const _K2& __k) {return __tree_.lower_bound(__k);}
1808
1809 template <typename _K2>
1810 _LIBCPP_INLINE_VISIBILITY
1811 typename enable_if<__is_transparent<_Compare, _K2>::value,const_iterator>::type
1812 lower_bound(const _K2& __k) const {return __tree_.lower_bound(__k);}
1813#endif
1814
Howard Hinnant756c69b2010-09-22 16:48:34 +00001815 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001816 iterator upper_bound(const key_type& __k)
1817 {return __tree_.upper_bound(__k);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001818 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001819 const_iterator upper_bound(const key_type& __k) const
1820 {return __tree_.upper_bound(__k);}
Marshall Clowebb57322013-08-13 22:18:47 +00001821#if _LIBCPP_STD_VER > 11
1822 template <typename _K2>
1823 _LIBCPP_INLINE_VISIBILITY
1824 typename enable_if<__is_transparent<_Compare, _K2>::value,iterator>::type
1825 upper_bound(const _K2& __k) {return __tree_.upper_bound(__k);}
1826 template <typename _K2>
1827 _LIBCPP_INLINE_VISIBILITY
1828 typename enable_if<__is_transparent<_Compare, _K2>::value,const_iterator>::type
1829 upper_bound(const _K2& __k) const {return __tree_.upper_bound(__k);}
1830#endif
1831
Howard Hinnant756c69b2010-09-22 16:48:34 +00001832 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001833 pair<iterator,iterator> equal_range(const key_type& __k)
1834 {return __tree_.__equal_range_multi(__k);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001835 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001836 pair<const_iterator,const_iterator> equal_range(const key_type& __k) const
1837 {return __tree_.__equal_range_multi(__k);}
Marshall Clowebb57322013-08-13 22:18:47 +00001838#if _LIBCPP_STD_VER > 11
1839 template <typename _K2>
1840 _LIBCPP_INLINE_VISIBILITY
1841 typename enable_if<__is_transparent<_Compare, _K2>::value,pair<iterator,iterator>>::type
1842 equal_range(const _K2& __k) {return __tree_.__equal_range_multi(__k);}
1843 template <typename _K2>
1844 _LIBCPP_INLINE_VISIBILITY
1845 typename enable_if<__is_transparent<_Compare, _K2>::value,pair<const_iterator,const_iterator>>::type
1846 equal_range(const _K2& __k) const {return __tree_.__equal_range_multi(__k);}
1847#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001848
1849private:
1850 typedef typename __base::__node __node;
1851 typedef typename __base::__node_allocator __node_allocator;
1852 typedef typename __base::__node_pointer __node_pointer;
1853 typedef typename __base::__node_const_pointer __node_const_pointer;
Howard Hinnantc834c512011-11-29 18:15:50 +00001854 typedef __map_node_destructor<__node_allocator> _Dp;
1855 typedef unique_ptr<__node, _Dp> __node_holder;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001856
Howard Hinnant74279a52010-09-04 23:28:19 +00001857#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +00001858 __node_holder __construct_node();
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001859 template <class _A0>
Howard Hinnantac7e7482013-07-04 20:59:16 +00001860 __node_holder
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001861 __construct_node(_A0&& __a0);
Howard Hinnant74279a52010-09-04 23:28:19 +00001862#ifndef _LIBCPP_HAS_NO_VARIADICS
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001863 template <class _A0, class _A1, class ..._Args>
1864 __node_holder __construct_node(_A0&& __a0, _A1&& __a1, _Args&& ...__args);
Howard Hinnant74279a52010-09-04 23:28:19 +00001865#endif // _LIBCPP_HAS_NO_VARIADICS
1866#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +00001867};
1868
Howard Hinnant74279a52010-09-04 23:28:19 +00001869#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +00001870
1871template <class _Key, class _Tp, class _Compare, class _Allocator>
1872multimap<_Key, _Tp, _Compare, _Allocator>::multimap(multimap&& __m, const allocator_type& __a)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001873 : __tree_(_VSTD::move(__m.__tree_), __a)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001874{
1875 if (__a != __m.get_allocator())
1876 {
1877 const_iterator __e = cend();
1878 while (!__m.empty())
1879 __tree_.__insert_multi(__e.__i_,
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001880 _VSTD::move(__m.__tree_.remove(__m.begin().__i_)->__value_));
Howard Hinnantc51e1022010-05-11 19:42:16 +00001881 }
1882}
1883
1884template <class _Key, class _Tp, class _Compare, class _Allocator>
1885typename multimap<_Key, _Tp, _Compare, _Allocator>::__node_holder
1886multimap<_Key, _Tp, _Compare, _Allocator>::__construct_node()
1887{
1888 __node_allocator& __na = __tree_.__node_alloc();
Howard Hinnantc834c512011-11-29 18:15:50 +00001889 __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001890 __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__cc.first));
Howard Hinnantc51e1022010-05-11 19:42:16 +00001891 __h.get_deleter().__first_constructed = true;
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001892 __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__cc.second));
Howard Hinnantc51e1022010-05-11 19:42:16 +00001893 __h.get_deleter().__second_constructed = true;
1894 return __h;
1895}
1896
1897template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001898template <class _A0>
Howard Hinnantac7e7482013-07-04 20:59:16 +00001899typename multimap<_Key, _Tp, _Compare, _Allocator>::__node_holder
Howard Hinnantc51e1022010-05-11 19:42:16 +00001900multimap<_Key, _Tp, _Compare, _Allocator>::__construct_node(_A0&& __a0)
1901{
1902 __node_allocator& __na = __tree_.__node_alloc();
Howard Hinnantc834c512011-11-29 18:15:50 +00001903 __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001904 __node_traits::construct(__na, _VSTD::addressof(__h->__value_), _VSTD::forward<_A0>(__a0));
Howard Hinnantc51e1022010-05-11 19:42:16 +00001905 __h.get_deleter().__first_constructed = true;
1906 __h.get_deleter().__second_constructed = true;
1907 return __h;
1908}
1909
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001910#ifndef _LIBCPP_HAS_NO_VARIADICS
1911
1912template <class _Key, class _Tp, class _Compare, class _Allocator>
1913template <class _A0, class _A1, class ..._Args>
1914typename multimap<_Key, _Tp, _Compare, _Allocator>::__node_holder
1915multimap<_Key, _Tp, _Compare, _Allocator>::__construct_node(_A0&& __a0, _A1&& __a1, _Args&& ...__args)
1916{
1917 __node_allocator& __na = __tree_.__node_alloc();
1918 __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
1919 __node_traits::construct(__na, _VSTD::addressof(__h->__value_),
1920 _VSTD::forward<_A0>(__a0), _VSTD::forward<_A1>(__a1),
1921 _VSTD::forward<_Args>(__args)...);
1922 __h.get_deleter().__first_constructed = true;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001923 __h.get_deleter().__second_constructed = true;
1924 return __h;
1925}
1926
Howard Hinnant74279a52010-09-04 23:28:19 +00001927#endif // _LIBCPP_HAS_NO_VARIADICS
1928#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +00001929
Howard Hinnant74279a52010-09-04 23:28:19 +00001930#if !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001931
1932template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001933template <class ..._Args>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001934typename multimap<_Key, _Tp, _Compare, _Allocator>::iterator
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001935multimap<_Key, _Tp, _Compare, _Allocator>::emplace(_Args&& ...__args)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001936{
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001937 __node_holder __h = __construct_node(_VSTD::forward<_Args>(__args)...);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001938 iterator __r = __tree_.__node_insert_multi(__h.get());
1939 __h.release();
1940 return __r;
1941}
1942
1943template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001944template <class ..._Args>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001945typename multimap<_Key, _Tp, _Compare, _Allocator>::iterator
1946multimap<_Key, _Tp, _Compare, _Allocator>::emplace_hint(const_iterator __p,
Howard Hinnantc51e1022010-05-11 19:42:16 +00001947 _Args&& ...__args)
1948{
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001949 __node_holder __h = __construct_node(_VSTD::forward<_Args>(__args)...);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001950 iterator __r = __tree_.__node_insert_multi(__p.__i_, __h.get());
1951 __h.release();
1952 return __r;
1953}
1954
Howard Hinnant74279a52010-09-04 23:28:19 +00001955#endif // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001956
1957template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001958inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001959bool
1960operator==(const multimap<_Key, _Tp, _Compare, _Allocator>& __x,
1961 const multimap<_Key, _Tp, _Compare, _Allocator>& __y)
1962{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001963 return __x.size() == __y.size() && _VSTD::equal(__x.begin(), __x.end(), __y.begin());
Howard Hinnantc51e1022010-05-11 19:42:16 +00001964}
1965
1966template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001967inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001968bool
1969operator< (const multimap<_Key, _Tp, _Compare, _Allocator>& __x,
1970 const multimap<_Key, _Tp, _Compare, _Allocator>& __y)
1971{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001972 return _VSTD::lexicographical_compare(__x.begin(), __x.end(), __y.begin(), __y.end());
Howard Hinnantc51e1022010-05-11 19:42:16 +00001973}
1974
1975template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001976inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001977bool
1978operator!=(const multimap<_Key, _Tp, _Compare, _Allocator>& __x,
1979 const multimap<_Key, _Tp, _Compare, _Allocator>& __y)
1980{
1981 return !(__x == __y);
1982}
1983
1984template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001985inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001986bool
1987operator> (const multimap<_Key, _Tp, _Compare, _Allocator>& __x,
1988 const multimap<_Key, _Tp, _Compare, _Allocator>& __y)
1989{
1990 return __y < __x;
1991}
1992
1993template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001994inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001995bool
1996operator>=(const multimap<_Key, _Tp, _Compare, _Allocator>& __x,
1997 const multimap<_Key, _Tp, _Compare, _Allocator>& __y)
1998{
1999 return !(__x < __y);
2000}
2001
2002template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00002003inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002004bool
2005operator<=(const multimap<_Key, _Tp, _Compare, _Allocator>& __x,
2006 const multimap<_Key, _Tp, _Compare, _Allocator>& __y)
2007{
2008 return !(__y < __x);
2009}
2010
2011template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00002012inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002013void
2014swap(multimap<_Key, _Tp, _Compare, _Allocator>& __x,
2015 multimap<_Key, _Tp, _Compare, _Allocator>& __y)
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00002016 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
Howard Hinnantc51e1022010-05-11 19:42:16 +00002017{
2018 __x.swap(__y);
2019}
2020
2021_LIBCPP_END_NAMESPACE_STD
2022
2023#endif // _LIBCPP_MAP