blob: c78231d0c0026c1476c2280c81756aabb36dbe1c [file] [log] [blame]
Howard Hinnantc51e1022010-05-11 19:42:16 +00001// -*- C++ -*-
2//===----------------------------- map ------------------------------------===//
3//
Howard Hinnantc566dc32010-05-11 21:36:01 +00004// The LLVM Compiler Infrastructure
Howard Hinnantc51e1022010-05-11 19:42:16 +00005//
Howard Hinnantee11c312010-11-16 22:09:02 +00006// This file is dual licensed under the MIT and the University of Illinois Open
7// Source Licenses. See LICENSE.TXT for details.
Howard Hinnantc51e1022010-05-11 19:42:16 +00008//
9//===----------------------------------------------------------------------===//
10
11#ifndef _LIBCPP_MAP
12#define _LIBCPP_MAP
13
14/*
15
16 map synopsis
17
18namespace std
19{
20
21template <class Key, class T, class Compare = less<Key>,
22 class Allocator = allocator<pair<const Key, T>>>
23class map
24{
25public:
26 // types:
27 typedef Key key_type;
28 typedef T mapped_type;
29 typedef pair<const key_type, mapped_type> value_type;
30 typedef Compare key_compare;
31 typedef Allocator allocator_type;
32 typedef typename allocator_type::reference reference;
33 typedef typename allocator_type::const_reference const_reference;
34 typedef typename allocator_type::pointer pointer;
35 typedef typename allocator_type::const_pointer const_pointer;
36 typedef typename allocator_type::size_type size_type;
37 typedef typename allocator_type::difference_type difference_type;
38
39 typedef implementation-defined iterator;
40 typedef implementation-defined const_iterator;
41 typedef std::reverse_iterator<iterator> reverse_iterator;
42 typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
43
44 class value_compare
45 : public binary_function<value_type, value_type, bool>
46 {
47 friend class map;
48 protected:
49 key_compare comp;
50
51 value_compare(key_compare c);
52 public:
53 bool operator()(const value_type& x, const value_type& y) const;
54 };
55
56 // construct/copy/destroy:
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +000057 map()
58 noexcept(
59 is_nothrow_default_constructible<allocator_type>::value &&
60 is_nothrow_default_constructible<key_compare>::value &&
61 is_nothrow_copy_constructible<key_compare>::value);
Howard Hinnantc51e1022010-05-11 19:42:16 +000062 explicit map(const key_compare& comp);
63 map(const key_compare& comp, const allocator_type& a);
64 template <class InputIterator>
65 map(InputIterator first, InputIterator last,
66 const key_compare& comp = key_compare());
67 template <class InputIterator>
68 map(InputIterator first, InputIterator last,
69 const key_compare& comp, const allocator_type& a);
70 map(const map& m);
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +000071 map(map&& m)
72 noexcept(
73 is_nothrow_move_constructible<allocator_type>::value &&
74 is_nothrow_move_constructible<key_compare>::value);
Howard Hinnantc51e1022010-05-11 19:42:16 +000075 explicit map(const allocator_type& a);
76 map(const map& m, const allocator_type& a);
77 map(map&& m, const allocator_type& a);
78 map(initializer_list<value_type> il, const key_compare& comp = key_compare());
79 map(initializer_list<value_type> il, const key_compare& comp, const allocator_type& a);
Marshall Clow300abfb2013-09-11 01:15:47 +000080 template <class InputIterator>
81 map(InputIterator first, InputIterator last, const allocator_type& a)
82 : map(first, last, Compare(), a) {} // C++14
83 map(initializer_list<value_type> il, const allocator_type& a)
84 : map(il, Compare(), a) {} // C++14
85 ~map();
Howard Hinnantc51e1022010-05-11 19:42:16 +000086
87 map& operator=(const map& m);
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +000088 map& operator=(map&& m)
89 noexcept(
90 allocator_type::propagate_on_container_move_assignment::value &&
91 is_nothrow_move_assignable<allocator_type>::value &&
Howard Hinnantf95f4f52011-06-04 15:22:34 +000092 is_nothrow_move_assignable<key_compare>::value);
Howard Hinnantc51e1022010-05-11 19:42:16 +000093 map& operator=(initializer_list<value_type> il);
94
95 // iterators:
Howard Hinnantf95f4f52011-06-04 15:22:34 +000096 iterator begin() noexcept;
97 const_iterator begin() const noexcept;
98 iterator end() noexcept;
99 const_iterator end() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000100
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000101 reverse_iterator rbegin() noexcept;
102 const_reverse_iterator rbegin() const noexcept;
103 reverse_iterator rend() noexcept;
104 const_reverse_iterator rend() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000105
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000106 const_iterator cbegin() const noexcept;
107 const_iterator cend() const noexcept;
108 const_reverse_iterator crbegin() const noexcept;
109 const_reverse_iterator crend() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000110
111 // capacity:
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000112 bool empty() const noexcept;
113 size_type size() const noexcept;
114 size_type max_size() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000115
116 // element access:
117 mapped_type& operator[](const key_type& k);
118 mapped_type& operator[](key_type&& k);
119
120 mapped_type& at(const key_type& k);
121 const mapped_type& at(const key_type& k) const;
122
123 // modifiers:
124 template <class... Args>
125 pair<iterator, bool> emplace(Args&&... args);
126 template <class... Args>
127 iterator emplace_hint(const_iterator position, Args&&... args);
128 pair<iterator, bool> insert(const value_type& v);
129 template <class P>
130 pair<iterator, bool> insert(P&& p);
131 iterator insert(const_iterator position, const value_type& v);
132 template <class P>
133 iterator insert(const_iterator position, P&& p);
134 template <class InputIterator>
135 void insert(InputIterator first, InputIterator last);
136 void insert(initializer_list<value_type> il);
137
138 iterator erase(const_iterator position);
139 size_type erase(const key_type& k);
140 iterator erase(const_iterator first, const_iterator last);
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000141 void clear() noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000142
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000143 void swap(map& m)
144 noexcept(
145 __is_nothrow_swappable<key_compare>::value &&
146 (!allocator_type::propagate_on_container_swap::value ||
147 __is_nothrow_swappable<allocator_type>::value));
Howard Hinnantc51e1022010-05-11 19:42:16 +0000148
149 // observers:
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000150 allocator_type get_allocator() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000151 key_compare key_comp() const;
152 value_compare value_comp() const;
153
154 // map operations:
155 iterator find(const key_type& k);
156 const_iterator find(const key_type& k) const;
Marshall Clowebb57322013-08-13 22:18:47 +0000157 template<typename K>
158 iterator find(const K& x); // C++14
159 template<typename K>
160 const_iterator find(const K& x) const; // C++14
161 template<typename K>
162 size_type count(const K& x) const;
163
Howard Hinnantc51e1022010-05-11 19:42:16 +0000164 size_type count(const key_type& k) const;
165 iterator lower_bound(const key_type& k);
166 const_iterator lower_bound(const key_type& k) const;
Marshall Clowebb57322013-08-13 22:18:47 +0000167 template<typename K>
168 iterator lower_bound(const K& x); // C++14
169 template<typename K>
170 const_iterator lower_bound(const K& x) const; // C++14
171
Howard Hinnantc51e1022010-05-11 19:42:16 +0000172 iterator upper_bound(const key_type& k);
173 const_iterator upper_bound(const key_type& k) const;
Marshall Clowebb57322013-08-13 22:18:47 +0000174 template<typename K>
175 iterator upper_bound(const K& x); // C++14
176 template<typename K>
177 const_iterator upper_bound(const K& x) const; // C++14
178
Howard Hinnantc51e1022010-05-11 19:42:16 +0000179 pair<iterator,iterator> equal_range(const key_type& k);
180 pair<const_iterator,const_iterator> equal_range(const key_type& k) const;
Marshall Clowebb57322013-08-13 22:18:47 +0000181 template<typename K>
182 pair<iterator,iterator> equal_range(const K& x); // C++14
183 template<typename K>
184 pair<const_iterator,const_iterator> equal_range(const K& x) const; // C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000185};
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
212template <class Key, class T, class Compare, class Allocator>
213bool
214operator<=(const map<Key, T, Compare, Allocator>& x,
215 const map<Key, T, Compare, Allocator>& y);
216
217// specialized algorithms:
218template <class Key, class T, class Compare, class Allocator>
219void
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000220swap(map<Key, T, Compare, Allocator>& x, map<Key, T, Compare, Allocator>& y)
221 noexcept(noexcept(x.swap(y)));
Howard Hinnantc51e1022010-05-11 19:42:16 +0000222
223template <class Key, class T, class Compare = less<Key>,
224 class Allocator = allocator<pair<const Key, T>>>
225class multimap
226{
227public:
228 // types:
229 typedef Key key_type;
230 typedef T mapped_type;
231 typedef pair<const key_type,mapped_type> value_type;
232 typedef Compare key_compare;
233 typedef Allocator allocator_type;
234 typedef typename allocator_type::reference reference;
235 typedef typename allocator_type::const_reference const_reference;
236 typedef typename allocator_type::size_type size_type;
237 typedef typename allocator_type::difference_type difference_type;
238 typedef typename allocator_type::pointer pointer;
239 typedef typename allocator_type::const_pointer const_pointer;
240
241 typedef implementation-defined iterator;
242 typedef implementation-defined const_iterator;
243 typedef std::reverse_iterator<iterator> reverse_iterator;
244 typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
245
246 class value_compare
247 : public binary_function<value_type,value_type,bool>
248 {
249 friend class multimap;
250 protected:
251 key_compare comp;
252 value_compare(key_compare c);
253 public:
254 bool operator()(const value_type& x, const value_type& y) const;
255 };
256
257 // construct/copy/destroy:
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000258 multimap()
259 noexcept(
260 is_nothrow_default_constructible<allocator_type>::value &&
261 is_nothrow_default_constructible<key_compare>::value &&
262 is_nothrow_copy_constructible<key_compare>::value);
263 explicit multimap(const key_compare& comp);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000264 multimap(const key_compare& comp, const allocator_type& a);
265 template <class InputIterator>
266 multimap(InputIterator first, InputIterator last, const key_compare& comp);
267 template <class InputIterator>
268 multimap(InputIterator first, InputIterator last, const key_compare& comp,
269 const allocator_type& a);
270 multimap(const multimap& m);
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000271 multimap(multimap&& m)
272 noexcept(
273 is_nothrow_move_constructible<allocator_type>::value &&
274 is_nothrow_move_constructible<key_compare>::value);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000275 explicit multimap(const allocator_type& a);
276 multimap(const multimap& m, const allocator_type& a);
277 multimap(multimap&& m, const allocator_type& a);
278 multimap(initializer_list<value_type> il, const key_compare& comp = key_compare());
279 multimap(initializer_list<value_type> il, const key_compare& comp,
280 const allocator_type& a);
Marshall Clow300abfb2013-09-11 01:15:47 +0000281 template <class InputIterator>
282 multimap(InputIterator first, InputIterator last, const allocator_type& a)
283 : multimap(first, last, Compare(), a) {} // C++14
284 multimap(initializer_list<value_type> il, const allocator_type& a)
285 : multimap(il, Compare(), a) {} // C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000286 ~multimap();
287
288 multimap& operator=(const multimap& m);
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000289 multimap& operator=(multimap&& m)
290 noexcept(
291 allocator_type::propagate_on_container_move_assignment::value &&
292 is_nothrow_move_assignable<allocator_type>::value &&
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000293 is_nothrow_move_assignable<key_compare>::value);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000294 multimap& operator=(initializer_list<value_type> il);
295
296 // iterators:
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000297 iterator begin() noexcept;
298 const_iterator begin() const noexcept;
299 iterator end() noexcept;
300 const_iterator end() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000301
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000302 reverse_iterator rbegin() noexcept;
303 const_reverse_iterator rbegin() const noexcept;
304 reverse_iterator rend() noexcept;
305 const_reverse_iterator rend() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000306
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000307 const_iterator cbegin() const noexcept;
308 const_iterator cend() const noexcept;
309 const_reverse_iterator crbegin() const noexcept;
310 const_reverse_iterator crend() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000311
312 // capacity:
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000313 bool empty() const noexcept;
314 size_type size() const noexcept;
315 size_type max_size() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000316
317 // modifiers:
318 template <class... Args>
319 iterator emplace(Args&&... args);
320 template <class... Args>
321 iterator emplace_hint(const_iterator position, Args&&... args);
322 iterator insert(const value_type& v);
323 template <class P>
324 iterator insert(P&& p);
325 iterator insert(const_iterator position, const value_type& v);
326 template <class P>
327 iterator insert(const_iterator position, P&& p);
328 template <class InputIterator>
329 void insert(InputIterator first, InputIterator last);
330 void insert(initializer_list<value_type> il);
331
332 iterator erase(const_iterator position);
333 size_type erase(const key_type& k);
334 iterator erase(const_iterator first, const_iterator last);
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000335 void clear() noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000336
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000337 void swap(multimap& m)
338 noexcept(
339 __is_nothrow_swappable<key_compare>::value &&
340 (!allocator_type::propagate_on_container_swap::value ||
341 __is_nothrow_swappable<allocator_type>::value));
Howard Hinnantc51e1022010-05-11 19:42:16 +0000342
343 // observers:
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000344 allocator_type get_allocator() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000345 key_compare key_comp() const;
346 value_compare value_comp() const;
347
348 // map operations:
349 iterator find(const key_type& k);
350 const_iterator find(const key_type& k) const;
Marshall Clowebb57322013-08-13 22:18:47 +0000351 template<typename K>
352 iterator find(const K& x); // C++14
353 template<typename K>
354 const_iterator find(const K& x) const; // C++14
355 template<typename K>
356 size_type count(const K& x) const;
357
Howard Hinnantc51e1022010-05-11 19:42:16 +0000358 size_type count(const key_type& k) const;
359 iterator lower_bound(const key_type& k);
360 const_iterator lower_bound(const key_type& k) const;
Marshall Clowebb57322013-08-13 22:18:47 +0000361 template<typename K>
362 iterator lower_bound(const K& x); // C++14
363 template<typename K>
364 const_iterator lower_bound(const K& x) const; // C++14
365
Howard Hinnantc51e1022010-05-11 19:42:16 +0000366 iterator upper_bound(const key_type& k);
367 const_iterator upper_bound(const key_type& k) const;
Marshall Clowebb57322013-08-13 22:18:47 +0000368 template<typename K>
369 iterator upper_bound(const K& x); // C++14
370 template<typename K>
371 const_iterator upper_bound(const K& x) const; // C++14
372
Howard Hinnantc51e1022010-05-11 19:42:16 +0000373 pair<iterator,iterator> equal_range(const key_type& k);
374 pair<const_iterator,const_iterator> equal_range(const key_type& k) const;
Marshall Clowebb57322013-08-13 22:18:47 +0000375 template<typename K>
376 pair<iterator,iterator> equal_range(const K& x); // C++14
377 template<typename K>
378 pair<const_iterator,const_iterator> equal_range(const K& x) const; // C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000379};
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
401template <class Key, class T, class Compare, class Allocator>
402bool
403operator>=(const multimap<Key, T, Compare, Allocator>& x,
404 const multimap<Key, T, Compare, Allocator>& y);
405
406template <class Key, class T, class Compare, class Allocator>
407bool
408operator<=(const multimap<Key, T, Compare, Allocator>& x,
409 const multimap<Key, T, Compare, Allocator>& y);
410
411// specialized algorithms:
412template <class Key, class T, class Compare, class Allocator>
413void
414swap(multimap<Key, T, Compare, Allocator>& x,
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000415 multimap<Key, T, Compare, Allocator>& y)
416 noexcept(noexcept(x.swap(y)));
Howard Hinnantc51e1022010-05-11 19:42:16 +0000417
418} // std
419
420*/
421
422#include <__config>
423#include <__tree>
424#include <iterator>
425#include <memory>
426#include <utility>
427#include <functional>
428#include <initializer_list>
429
Howard Hinnantaaaa52b2011-10-17 20:05:10 +0000430#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000431#pragma GCC system_header
Howard Hinnantaaaa52b2011-10-17 20:05:10 +0000432#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000433
434_LIBCPP_BEGIN_NAMESPACE_STD
435
Howard Hinnant90b91592013-07-05 18:06:00 +0000436template <class _Key, class _CP, class _Compare, bool = is_empty<_Compare>::value
Howard Hinnantd0aabf82011-12-11 20:31:33 +0000437#if __has_feature(is_final)
438 && !__is_final(_Compare)
439#endif
440 >
Howard Hinnantc51e1022010-05-11 19:42:16 +0000441class __map_value_compare
442 : private _Compare
443{
Howard Hinnantc51e1022010-05-11 19:42:16 +0000444public:
Howard Hinnant756c69b2010-09-22 16:48:34 +0000445 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000446 __map_value_compare()
447 _NOEXCEPT_(is_nothrow_default_constructible<_Compare>::value)
448 : _Compare() {}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000449 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000450 __map_value_compare(_Compare c)
451 _NOEXCEPT_(is_nothrow_copy_constructible<_Compare>::value)
452 : _Compare(c) {}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000453 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000454 const _Compare& key_comp() const _NOEXCEPT {return *this;}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000455 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000456 bool operator()(const _CP& __x, const _CP& __y) const
Howard Hinnant90b91592013-07-05 18:06:00 +0000457 {return static_cast<const _Compare&>(*this)(__x.__cc.first, __y.__cc.first);}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000458 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000459 bool operator()(const _CP& __x, const _Key& __y) const
Howard Hinnant90b91592013-07-05 18:06:00 +0000460 {return static_cast<const _Compare&>(*this)(__x.__cc.first, __y);}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000461 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000462 bool operator()(const _Key& __x, const _CP& __y) const
Howard Hinnant90b91592013-07-05 18:06:00 +0000463 {return static_cast<const _Compare&>(*this)(__x, __y.__cc.first);}
Marshall Clowebb57322013-08-13 22:18:47 +0000464
465#if _LIBCPP_STD_VER > 11
466 template <typename _K2>
467 _LIBCPP_INLINE_VISIBILITY
468 typename enable_if<__is_transparent<_Compare, _K2>::value, bool>::type
469 operator () ( const _K2& __x, const _CP& __y ) const
470 {return static_cast<const _Compare&>(*this) (__x, __y.__cc.first);}
471
472 template <typename _K2>
473 _LIBCPP_INLINE_VISIBILITY
474 typename enable_if<__is_transparent<_Compare, _K2>::value, bool>::type
475 operator () (const _CP& __x, const _K2& __y) const
476 {return static_cast<const _Compare&>(*this) (__x.__cc.first, __y);}
477#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000478};
479
Howard Hinnant90b91592013-07-05 18:06:00 +0000480template <class _Key, class _CP, class _Compare>
481class __map_value_compare<_Key, _CP, _Compare, false>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000482{
483 _Compare comp;
484
Howard Hinnantc51e1022010-05-11 19:42:16 +0000485public:
Howard Hinnant756c69b2010-09-22 16:48:34 +0000486 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000487 __map_value_compare()
488 _NOEXCEPT_(is_nothrow_default_constructible<_Compare>::value)
489 : comp() {}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000490 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000491 __map_value_compare(_Compare c)
492 _NOEXCEPT_(is_nothrow_copy_constructible<_Compare>::value)
493 : comp(c) {}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000494 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000495 const _Compare& key_comp() const _NOEXCEPT {return comp;}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000496
Howard Hinnant756c69b2010-09-22 16:48:34 +0000497 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000498 bool operator()(const _CP& __x, const _CP& __y) const
Howard Hinnant90b91592013-07-05 18:06:00 +0000499 {return comp(__x.__cc.first, __y.__cc.first);}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000500 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000501 bool operator()(const _CP& __x, const _Key& __y) const
Howard Hinnant90b91592013-07-05 18:06:00 +0000502 {return comp(__x.__cc.first, __y);}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000503 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000504 bool operator()(const _Key& __x, const _CP& __y) const
Howard Hinnant90b91592013-07-05 18:06:00 +0000505 {return comp(__x, __y.__cc.first);}
Marshall Clowebb57322013-08-13 22:18:47 +0000506
507#if _LIBCPP_STD_VER > 11
508 template <typename _K2>
509 _LIBCPP_INLINE_VISIBILITY
510 typename enable_if<__is_transparent<_Compare, _K2>::value, bool>::type
511 operator () ( const _K2& __x, const _CP& __y ) const
512 {return comp (__x, __y.__cc.first);}
513
514 template <typename _K2>
515 _LIBCPP_INLINE_VISIBILITY
516 typename enable_if<__is_transparent<_Compare, _K2>::value, bool>::type
517 operator () (const _CP& __x, const _K2& __y) const
518 {return comp (__x.__cc.first, __y);}
519#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000520};
521
522template <class _Allocator>
523class __map_node_destructor
524{
525 typedef _Allocator allocator_type;
526 typedef allocator_traits<allocator_type> __alloc_traits;
527 typedef typename __alloc_traits::value_type::value_type value_type;
528public:
529 typedef typename __alloc_traits::pointer pointer;
530private:
Howard Hinnant2d0046b2013-06-19 21:29:40 +0000531 typedef typename value_type::value_type::first_type first_type;
532 typedef typename value_type::value_type::second_type second_type;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000533
534 allocator_type& __na_;
535
536 __map_node_destructor& operator=(const __map_node_destructor&);
537
538public:
539 bool __first_constructed;
540 bool __second_constructed;
541
Howard Hinnant756c69b2010-09-22 16:48:34 +0000542 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000543 explicit __map_node_destructor(allocator_type& __na) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +0000544 : __na_(__na),
545 __first_constructed(false),
546 __second_constructed(false)
547 {}
548
Howard Hinnant74279a52010-09-04 23:28:19 +0000549#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant756c69b2010-09-22 16:48:34 +0000550 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000551 __map_node_destructor(__tree_node_destructor<allocator_type>&& __x) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +0000552 : __na_(__x.__na_),
553 __first_constructed(__x.__value_constructed),
554 __second_constructed(__x.__value_constructed)
555 {
556 __x.__value_constructed = false;
557 }
Howard Hinnant5dc89112010-09-04 23:46:48 +0000558#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +0000559
Howard Hinnant756c69b2010-09-22 16:48:34 +0000560 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000561 void operator()(pointer __p) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +0000562 {
563 if (__second_constructed)
Howard Hinnant2d0046b2013-06-19 21:29:40 +0000564 __alloc_traits::destroy(__na_, _VSTD::addressof(__p->__value_.__cc.second));
Howard Hinnantc51e1022010-05-11 19:42:16 +0000565 if (__first_constructed)
Howard Hinnant2d0046b2013-06-19 21:29:40 +0000566 __alloc_traits::destroy(__na_, _VSTD::addressof(__p->__value_.__cc.first));
Howard Hinnantc51e1022010-05-11 19:42:16 +0000567 if (__p)
568 __alloc_traits::deallocate(__na_, __p, 1);
569 }
570};
571
Howard Hinnant944510a2011-06-14 19:58:17 +0000572template <class _Key, class _Tp, class _Compare, class _Allocator>
573 class map;
574template <class _Key, class _Tp, class _Compare, class _Allocator>
575 class multimap;
576template <class _TreeIterator> class __map_const_iterator;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000577
578template <class _TreeIterator>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +0000579class _LIBCPP_TYPE_VIS_ONLY __map_iterator
Howard Hinnantc51e1022010-05-11 19:42:16 +0000580{
581 _TreeIterator __i_;
582
583 typedef typename _TreeIterator::__pointer_traits __pointer_traits;
Howard Hinnant2d0046b2013-06-19 21:29:40 +0000584 typedef const typename _TreeIterator::value_type::value_type::first_type __key_type;
585 typedef typename _TreeIterator::value_type::value_type::second_type __mapped_type;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000586public:
587 typedef bidirectional_iterator_tag iterator_category;
Howard Hinnantb2e8a422011-02-27 18:02:02 +0000588 typedef pair<__key_type, __mapped_type> value_type;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000589 typedef typename _TreeIterator::difference_type difference_type;
590 typedef value_type& reference;
591 typedef typename __pointer_traits::template
592#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
593 rebind<value_type>
594#else
595 rebind<value_type>::other
596#endif
597 pointer;
598
Howard Hinnant756c69b2010-09-22 16:48:34 +0000599 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000600 __map_iterator() _NOEXCEPT {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000601
Howard Hinnant756c69b2010-09-22 16:48:34 +0000602 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000603 __map_iterator(_TreeIterator __i) _NOEXCEPT : __i_(__i) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000604
Howard Hinnant756c69b2010-09-22 16:48:34 +0000605 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2d0046b2013-06-19 21:29:40 +0000606 reference operator*() const {return __i_->__cc;}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000607 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2d0046b2013-06-19 21:29:40 +0000608 pointer operator->() const {return pointer_traits<pointer>::pointer_to(__i_->__cc);}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000609
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 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000621 __map_iterator& operator--() {--__i_; return *this;}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000622 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000623 __map_iterator operator--(int)
624 {
625 __map_iterator __t(*this);
626 --(*this);
627 return __t;
628 }
629
Howard Hinnant756c69b2010-09-22 16:48:34 +0000630 friend _LIBCPP_INLINE_VISIBILITY
631 bool operator==(const __map_iterator& __x, const __map_iterator& __y)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000632 {return __x.__i_ == __y.__i_;}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000633 friend
634 _LIBCPP_INLINE_VISIBILITY
635 bool operator!=(const __map_iterator& __x, const __map_iterator& __y)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000636 {return __x.__i_ != __y.__i_;}
637
Howard Hinnanta37d3cf2013-08-12 18:38:34 +0000638 template <class, class, class, class> friend class _LIBCPP_TYPE_VIS_ONLY map;
639 template <class, class, class, class> friend class _LIBCPP_TYPE_VIS_ONLY multimap;
640 template <class> friend class _LIBCPP_TYPE_VIS_ONLY __map_const_iterator;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000641};
642
643template <class _TreeIterator>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +0000644class _LIBCPP_TYPE_VIS_ONLY __map_const_iterator
Howard Hinnantc51e1022010-05-11 19:42:16 +0000645{
646 _TreeIterator __i_;
647
648 typedef typename _TreeIterator::__pointer_traits __pointer_traits;
Howard Hinnant2d0046b2013-06-19 21:29:40 +0000649 typedef const typename _TreeIterator::value_type::value_type::first_type __key_type;
650 typedef typename _TreeIterator::value_type::value_type::second_type __mapped_type;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000651public:
652 typedef bidirectional_iterator_tag iterator_category;
Howard Hinnantb2e8a422011-02-27 18:02:02 +0000653 typedef pair<__key_type, __mapped_type> value_type;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000654 typedef typename _TreeIterator::difference_type difference_type;
655 typedef const value_type& reference;
656 typedef typename __pointer_traits::template
657#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
Howard Hinnant73f3c8a2011-04-11 02:18:41 +0000658 rebind<const value_type>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000659#else
Howard Hinnant73f3c8a2011-04-11 02:18:41 +0000660 rebind<const value_type>::other
Howard Hinnantc51e1022010-05-11 19:42:16 +0000661#endif
662 pointer;
663
Howard Hinnant756c69b2010-09-22 16:48:34 +0000664 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000665 __map_const_iterator() _NOEXCEPT {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000666
Howard Hinnant756c69b2010-09-22 16:48:34 +0000667 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000668 __map_const_iterator(_TreeIterator __i) _NOEXCEPT : __i_(__i) {}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000669 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000670 __map_const_iterator(
671 __map_iterator<typename _TreeIterator::__non_const_iterator> __i)
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000672 _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +0000673 : __i_(__i.__i_) {}
674
Howard Hinnant756c69b2010-09-22 16:48:34 +0000675 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2d0046b2013-06-19 21:29:40 +0000676 reference operator*() const {return __i_->__cc;}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000677 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2d0046b2013-06-19 21:29:40 +0000678 pointer operator->() const {return pointer_traits<pointer>::pointer_to(__i_->__cc);}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000679
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 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000691 __map_const_iterator& operator--() {--__i_; return *this;}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000692 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000693 __map_const_iterator operator--(int)
694 {
695 __map_const_iterator __t(*this);
696 --(*this);
697 return __t;
698 }
699
Howard Hinnant756c69b2010-09-22 16:48:34 +0000700 friend _LIBCPP_INLINE_VISIBILITY
701 bool operator==(const __map_const_iterator& __x, const __map_const_iterator& __y)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000702 {return __x.__i_ == __y.__i_;}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000703 friend _LIBCPP_INLINE_VISIBILITY
704 bool operator!=(const __map_const_iterator& __x, const __map_const_iterator& __y)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000705 {return __x.__i_ != __y.__i_;}
706
Howard Hinnanta37d3cf2013-08-12 18:38:34 +0000707 template <class, class, class, class> friend class _LIBCPP_TYPE_VIS_ONLY map;
708 template <class, class, class, class> friend class _LIBCPP_TYPE_VIS_ONLY multimap;
709 template <class, class, class> friend class _LIBCPP_TYPE_VIS_ONLY __tree_const_iterator;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000710};
711
712template <class _Key, class _Tp, class _Compare = less<_Key>,
713 class _Allocator = allocator<pair<const _Key, _Tp> > >
Howard Hinnanta37d3cf2013-08-12 18:38:34 +0000714class _LIBCPP_TYPE_VIS_ONLY map
Howard Hinnantc51e1022010-05-11 19:42:16 +0000715{
716public:
717 // types:
718 typedef _Key key_type;
719 typedef _Tp mapped_type;
720 typedef pair<const key_type, mapped_type> value_type;
Howard Hinnant2d0046b2013-06-19 21:29:40 +0000721 typedef pair<key_type, mapped_type> __nc_value_type;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000722 typedef _Compare key_compare;
723 typedef _Allocator allocator_type;
724 typedef value_type& reference;
725 typedef const value_type& const_reference;
726
Howard Hinnanta37d3cf2013-08-12 18:38:34 +0000727 class _LIBCPP_TYPE_VIS_ONLY value_compare
Howard Hinnantc51e1022010-05-11 19:42:16 +0000728 : public binary_function<value_type, value_type, bool>
729 {
730 friend class map;
731 protected:
732 key_compare comp;
733
Howard Hinnant756c69b2010-09-22 16:48:34 +0000734 _LIBCPP_INLINE_VISIBILITY value_compare(key_compare c) : comp(c) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000735 public:
Howard Hinnant756c69b2010-09-22 16:48:34 +0000736 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000737 bool operator()(const value_type& __x, const value_type& __y) const
738 {return comp(__x.first, __y.first);}
739 };
740
741private:
Howard Hinnant2d0046b2013-06-19 21:29:40 +0000742
743#if __cplusplus >= 201103L
744 union __value_type
745 {
746 typedef typename map::value_type value_type;
747 typedef typename map::__nc_value_type __nc_value_type;
748 value_type __cc;
749 __nc_value_type __nc;
750
751 template <class ..._Args>
752 __value_type(_Args&& ...__args)
753 : __cc(std::forward<_Args>(__args)...) {}
754
755 __value_type(const __value_type& __v)
756 : __cc(std::move(__v.__cc)) {}
757
758 __value_type(__value_type&& __v)
759 : __nc(std::move(__v.__nc)) {}
760
761 __value_type& operator=(const __value_type& __v)
762 {__nc = __v.__cc; return *this;}
763
764 __value_type& operator=(__value_type&& __v)
765 {__nc = std::move(__v.__nc); return *this;}
766
767 ~__value_type() {__cc.~value_type();}
Howard Hinnant2d0046b2013-06-19 21:29:40 +0000768 };
769#else
770 struct __value_type
771 {
772 typedef typename map::value_type value_type;
773 value_type __cc;
774
775 __value_type() {}
776
777 template <class _A0>
778 __value_type(const _A0& __a0)
779 : __cc(__a0) {}
780
781 template <class _A0, class _A1>
782 __value_type(const _A0& __a0, const _A1& __a1)
783 : __cc(__a0, __a1) {}
Howard Hinnant2d0046b2013-06-19 21:29:40 +0000784 };
785#endif
Howard Hinnant90b91592013-07-05 18:06:00 +0000786 typedef __map_value_compare<key_type, __value_type, key_compare> __vc;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000787 typedef typename allocator_traits<allocator_type>::template
788#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
789 rebind_alloc<__value_type>
790#else
791 rebind_alloc<__value_type>::other
792#endif
793 __allocator_type;
794 typedef __tree<__value_type, __vc, __allocator_type> __base;
795 typedef typename __base::__node_traits __node_traits;
796 typedef allocator_traits<allocator_type> __alloc_traits;
797
798 __base __tree_;
799
800public:
801 typedef typename __alloc_traits::pointer pointer;
802 typedef typename __alloc_traits::const_pointer const_pointer;
803 typedef typename __alloc_traits::size_type size_type;
804 typedef typename __alloc_traits::difference_type difference_type;
805 typedef __map_iterator<typename __base::iterator> iterator;
806 typedef __map_const_iterator<typename __base::const_iterator> const_iterator;
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000807 typedef _VSTD::reverse_iterator<iterator> reverse_iterator;
808 typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000809
Howard Hinnant756c69b2010-09-22 16:48:34 +0000810 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000811 explicit map(const key_compare& __comp = key_compare())
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000812 _NOEXCEPT_(
813 is_nothrow_default_constructible<allocator_type>::value &&
814 is_nothrow_default_constructible<key_compare>::value &&
815 is_nothrow_copy_constructible<key_compare>::value)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000816 : __tree_(__vc(__comp)) {}
817
Howard Hinnant756c69b2010-09-22 16:48:34 +0000818 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000819 explicit map(const key_compare& __comp, const allocator_type& __a)
820 : __tree_(__vc(__comp), __a) {}
821
822 template <class _InputIterator>
Howard Hinnant756c69b2010-09-22 16:48:34 +0000823 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000824 map(_InputIterator __f, _InputIterator __l,
825 const key_compare& __comp = key_compare())
826 : __tree_(__vc(__comp))
827 {
828 insert(__f, __l);
829 }
830
831 template <class _InputIterator>
Howard Hinnant756c69b2010-09-22 16:48:34 +0000832 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000833 map(_InputIterator __f, _InputIterator __l,
834 const key_compare& __comp, const allocator_type& __a)
835 : __tree_(__vc(__comp), __a)
836 {
837 insert(__f, __l);
838 }
839
Marshall Clow300abfb2013-09-11 01:15:47 +0000840#if _LIBCPP_STD_VER > 11
841 template <class _InputIterator>
842 _LIBCPP_INLINE_VISIBILITY
843 map(_InputIterator __f, _InputIterator __l, const allocator_type& __a)
844 : map(__f, __l, key_compare(), __a) {}
845#endif
846
Howard Hinnant756c69b2010-09-22 16:48:34 +0000847 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000848 map(const map& __m)
849 : __tree_(__m.__tree_)
850 {
851 insert(__m.begin(), __m.end());
852 }
853
Howard Hinnantd3a657f2011-07-01 19:24:36 +0000854 _LIBCPP_INLINE_VISIBILITY
855 map& operator=(const map& __m)
856 {
Howard Hinnant2d0046b2013-06-19 21:29:40 +0000857#if __cplusplus >= 201103L
Howard Hinnantd3a657f2011-07-01 19:24:36 +0000858 __tree_ = __m.__tree_;
Howard Hinnant2d0046b2013-06-19 21:29:40 +0000859#else
860 __tree_.clear();
861 __tree_.value_comp() = __m.__tree_.value_comp();
862 __tree_.__copy_assign_alloc(__m.__tree_);
863 insert(__m.begin(), __m.end());
864#endif
Howard Hinnantd3a657f2011-07-01 19:24:36 +0000865 return *this;
866 }
867
Howard Hinnant74279a52010-09-04 23:28:19 +0000868#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +0000869
Howard Hinnant756c69b2010-09-22 16:48:34 +0000870 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000871 map(map&& __m)
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000872 _NOEXCEPT_(is_nothrow_move_constructible<__base>::value)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000873 : __tree_(_VSTD::move(__m.__tree_))
Howard Hinnantc51e1022010-05-11 19:42:16 +0000874 {
875 }
876
877 map(map&& __m, const allocator_type& __a);
878
Howard Hinnant756c69b2010-09-22 16:48:34 +0000879 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant33711792011-08-12 21:56:02 +0000880 map& operator=(map&& __m)
881 _NOEXCEPT_(is_nothrow_move_assignable<__base>::value)
882 {
883 __tree_ = _VSTD::move(__m.__tree_);
884 return *this;
885 }
886
887#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
888
889#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
890
891 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000892 map(initializer_list<value_type> __il, const key_compare& __comp = key_compare())
893 : __tree_(__vc(__comp))
894 {
895 insert(__il.begin(), __il.end());
896 }
897
Howard Hinnant756c69b2010-09-22 16:48:34 +0000898 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000899 map(initializer_list<value_type> __il, const key_compare& __comp, const allocator_type& __a)
900 : __tree_(__vc(__comp), __a)
901 {
902 insert(__il.begin(), __il.end());
903 }
904
Marshall Clow300abfb2013-09-11 01:15:47 +0000905#if _LIBCPP_STD_VER > 11
906 _LIBCPP_INLINE_VISIBILITY
907 map(initializer_list<value_type> __il, const allocator_type& __a)
908 : map(__il, key_compare(), __a) {}
909#endif
910
Howard Hinnant756c69b2010-09-22 16:48:34 +0000911 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000912 map& operator=(initializer_list<value_type> __il)
913 {
914 __tree_.__assign_unique(__il.begin(), __il.end());
915 return *this;
916 }
917
Howard Hinnant33711792011-08-12 21:56:02 +0000918#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000919
Howard Hinnant756c69b2010-09-22 16:48:34 +0000920 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000921 explicit map(const allocator_type& __a)
922 : __tree_(__a)
923 {
924 }
925
Howard Hinnant756c69b2010-09-22 16:48:34 +0000926 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000927 map(const map& __m, const allocator_type& __a)
928 : __tree_(__m.__tree_.value_comp(), __a)
929 {
930 insert(__m.begin(), __m.end());
931 }
932
Howard Hinnant756c69b2010-09-22 16:48:34 +0000933 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000934 iterator begin() _NOEXCEPT {return __tree_.begin();}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000935 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000936 const_iterator begin() const _NOEXCEPT {return __tree_.begin();}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000937 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000938 iterator end() _NOEXCEPT {return __tree_.end();}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000939 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000940 const_iterator end() const _NOEXCEPT {return __tree_.end();}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000941
Howard Hinnant756c69b2010-09-22 16:48:34 +0000942 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000943 reverse_iterator rbegin() _NOEXCEPT {return reverse_iterator(end());}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000944 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000945 const_reverse_iterator rbegin() const _NOEXCEPT
946 {return const_reverse_iterator(end());}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000947 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000948 reverse_iterator rend() _NOEXCEPT
949 {return reverse_iterator(begin());}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000950 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000951 const_reverse_iterator rend() const _NOEXCEPT
952 {return const_reverse_iterator(begin());}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000953
Howard Hinnant756c69b2010-09-22 16:48:34 +0000954 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000955 const_iterator cbegin() const _NOEXCEPT {return begin();}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000956 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000957 const_iterator cend() const _NOEXCEPT {return end();}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000958 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000959 const_reverse_iterator crbegin() const _NOEXCEPT {return rbegin();}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000960 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000961 const_reverse_iterator crend() const _NOEXCEPT {return rend();}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000962
Howard Hinnant756c69b2010-09-22 16:48:34 +0000963 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000964 bool empty() const _NOEXCEPT {return __tree_.size() == 0;}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000965 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000966 size_type size() const _NOEXCEPT {return __tree_.size();}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000967 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000968 size_type max_size() const _NOEXCEPT {return __tree_.max_size();}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000969
970 mapped_type& operator[](const key_type& __k);
Howard Hinnant74279a52010-09-04 23:28:19 +0000971#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +0000972 mapped_type& operator[](key_type&& __k);
973#endif
974
975 mapped_type& at(const key_type& __k);
976 const mapped_type& at(const key_type& __k) const;
977
Howard Hinnant756c69b2010-09-22 16:48:34 +0000978 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000979 allocator_type get_allocator() const _NOEXCEPT {return __tree_.__alloc();}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000980 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000981 key_compare key_comp() const {return __tree_.value_comp().key_comp();}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000982 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000983 value_compare value_comp() const {return value_compare(__tree_.value_comp().key_comp());}
984
Howard Hinnant74279a52010-09-04 23:28:19 +0000985#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant74279a52010-09-04 23:28:19 +0000986#ifndef _LIBCPP_HAS_NO_VARIADICS
987
Howard Hinnant29eb9b82012-05-25 22:04:21 +0000988 template <class ..._Args>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000989 pair<iterator, bool>
Howard Hinnant29eb9b82012-05-25 22:04:21 +0000990 emplace(_Args&& ...__args);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000991
Howard Hinnant29eb9b82012-05-25 22:04:21 +0000992 template <class ..._Args>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000993 iterator
Howard Hinnant29eb9b82012-05-25 22:04:21 +0000994 emplace_hint(const_iterator __p, _Args&& ...__args);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000995
Howard Hinnant74279a52010-09-04 23:28:19 +0000996#endif // _LIBCPP_HAS_NO_VARIADICS
997
Howard Hinnantc834c512011-11-29 18:15:50 +0000998 template <class _Pp,
999 class = typename enable_if<is_constructible<value_type, _Pp>::value>::type>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001000 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc834c512011-11-29 18:15:50 +00001001 pair<iterator, bool> insert(_Pp&& __p)
1002 {return __tree_.__insert_unique(_VSTD::forward<_Pp>(__p));}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001003
Howard Hinnantc834c512011-11-29 18:15:50 +00001004 template <class _Pp,
1005 class = typename enable_if<is_constructible<value_type, _Pp>::value>::type>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001006 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc834c512011-11-29 18:15:50 +00001007 iterator insert(const_iterator __pos, _Pp&& __p)
1008 {return __tree_.__insert_unique(__pos.__i_, _VSTD::forward<_Pp>(__p));}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001009
Howard Hinnant74279a52010-09-04 23:28:19 +00001010#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +00001011
Howard Hinnant756c69b2010-09-22 16:48:34 +00001012 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001013 pair<iterator, bool>
1014 insert(const value_type& __v) {return __tree_.__insert_unique(__v);}
1015
Howard Hinnant756c69b2010-09-22 16:48:34 +00001016 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001017 iterator
1018 insert(const_iterator __p, const value_type& __v)
1019 {return __tree_.__insert_unique(__p.__i_, __v);}
1020
1021 template <class _InputIterator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001022 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001023 void insert(_InputIterator __f, _InputIterator __l)
1024 {
1025 for (const_iterator __e = cend(); __f != __l; ++__f)
1026 insert(__e.__i_, *__f);
1027 }
1028
Howard Hinnant33711792011-08-12 21:56:02 +00001029#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1030
Howard Hinnant756c69b2010-09-22 16:48:34 +00001031 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001032 void insert(initializer_list<value_type> __il)
1033 {insert(__il.begin(), __il.end());}
1034
Howard Hinnant33711792011-08-12 21:56:02 +00001035#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1036
Howard Hinnant756c69b2010-09-22 16:48:34 +00001037 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001038 iterator erase(const_iterator __p) {return __tree_.erase(__p.__i_);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001039 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001040 size_type erase(const key_type& __k)
1041 {return __tree_.__erase_unique(__k);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001042 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001043 iterator erase(const_iterator __f, const_iterator __l)
1044 {return __tree_.erase(__f.__i_, __l.__i_);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001045 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001046 void clear() _NOEXCEPT {__tree_.clear();}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001047
Howard Hinnant756c69b2010-09-22 16:48:34 +00001048 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001049 void swap(map& __m)
1050 _NOEXCEPT_(__is_nothrow_swappable<__base>::value)
1051 {__tree_.swap(__m.__tree_);}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001052
Howard Hinnant756c69b2010-09-22 16:48:34 +00001053 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001054 iterator find(const key_type& __k) {return __tree_.find(__k);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001055 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001056 const_iterator find(const key_type& __k) const {return __tree_.find(__k);}
Marshall Clowebb57322013-08-13 22:18:47 +00001057#if _LIBCPP_STD_VER > 11
1058 template <typename _K2>
1059 _LIBCPP_INLINE_VISIBILITY
1060 typename enable_if<__is_transparent<_Compare, _K2>::value,iterator>::type
1061 find(const _K2& __k) {return __tree_.find(__k);}
1062 template <typename _K2>
1063 _LIBCPP_INLINE_VISIBILITY
1064 typename enable_if<__is_transparent<_Compare, _K2>::value,const_iterator>::type
1065 find(const _K2& __k) const {return __tree_.find(__k);}
1066#endif
1067
Howard Hinnant756c69b2010-09-22 16:48:34 +00001068 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001069 size_type count(const key_type& __k) const
1070 {return __tree_.__count_unique(__k);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001071 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001072 iterator lower_bound(const key_type& __k)
1073 {return __tree_.lower_bound(__k);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001074 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001075 const_iterator lower_bound(const key_type& __k) const
1076 {return __tree_.lower_bound(__k);}
Marshall Clowebb57322013-08-13 22:18:47 +00001077#if _LIBCPP_STD_VER > 11
1078 template <typename _K2>
1079 _LIBCPP_INLINE_VISIBILITY
1080 typename enable_if<__is_transparent<_Compare, _K2>::value,iterator>::type
1081 lower_bound(const _K2& __k) {return __tree_.lower_bound(__k);}
1082
1083 template <typename _K2>
1084 _LIBCPP_INLINE_VISIBILITY
1085 typename enable_if<__is_transparent<_Compare, _K2>::value,const_iterator>::type
1086 lower_bound(const _K2& __k) const {return __tree_.lower_bound(__k);}
1087#endif
1088
Howard Hinnant756c69b2010-09-22 16:48:34 +00001089 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001090 iterator upper_bound(const key_type& __k)
1091 {return __tree_.upper_bound(__k);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001092 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001093 const_iterator upper_bound(const key_type& __k) const
1094 {return __tree_.upper_bound(__k);}
Marshall Clowebb57322013-08-13 22:18:47 +00001095#if _LIBCPP_STD_VER > 11
1096 template <typename _K2>
1097 _LIBCPP_INLINE_VISIBILITY
1098 typename enable_if<__is_transparent<_Compare, _K2>::value,iterator>::type
1099 upper_bound(const _K2& __k) {return __tree_.upper_bound(__k);}
1100 template <typename _K2>
1101 _LIBCPP_INLINE_VISIBILITY
1102 typename enable_if<__is_transparent<_Compare, _K2>::value,const_iterator>::type
1103 upper_bound(const _K2& __k) const {return __tree_.upper_bound(__k);}
1104#endif
1105
Howard Hinnant756c69b2010-09-22 16:48:34 +00001106 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001107 pair<iterator,iterator> equal_range(const key_type& __k)
1108 {return __tree_.__equal_range_unique(__k);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001109 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001110 pair<const_iterator,const_iterator> equal_range(const key_type& __k) const
1111 {return __tree_.__equal_range_unique(__k);}
Marshall Clowebb57322013-08-13 22:18:47 +00001112#if _LIBCPP_STD_VER > 11
1113 template <typename _K2>
1114 _LIBCPP_INLINE_VISIBILITY
1115 typename enable_if<__is_transparent<_Compare, _K2>::value,pair<iterator,iterator>>::type
1116 equal_range(const _K2& __k) {return __tree_.__equal_range_unique(__k);}
1117 template <typename _K2>
1118 _LIBCPP_INLINE_VISIBILITY
1119 typename enable_if<__is_transparent<_Compare, _K2>::value,pair<const_iterator,const_iterator>>::type
1120 equal_range(const _K2& __k) const {return __tree_.__equal_range_unique(__k);}
1121#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001122
1123private:
1124 typedef typename __base::__node __node;
1125 typedef typename __base::__node_allocator __node_allocator;
1126 typedef typename __base::__node_pointer __node_pointer;
1127 typedef typename __base::__node_const_pointer __node_const_pointer;
1128 typedef typename __base::__node_base_pointer __node_base_pointer;
1129 typedef typename __base::__node_base_const_pointer __node_base_const_pointer;
Howard Hinnantc834c512011-11-29 18:15:50 +00001130 typedef __map_node_destructor<__node_allocator> _Dp;
1131 typedef unique_ptr<__node, _Dp> __node_holder;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001132
Howard Hinnant74279a52010-09-04 23:28:19 +00001133#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +00001134 __node_holder __construct_node();
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001135 template <class _A0>
Howard Hinnantac7e7482013-07-04 20:59:16 +00001136 __node_holder __construct_node(_A0&& __a0);
1137 __node_holder __construct_node_with_key(key_type&& __k);
Howard Hinnant74279a52010-09-04 23:28:19 +00001138#ifndef _LIBCPP_HAS_NO_VARIADICS
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001139 template <class _A0, class _A1, class ..._Args>
1140 __node_holder __construct_node(_A0&& __a0, _A1&& __a1, _Args&& ...__args);
Howard Hinnant74279a52010-09-04 23:28:19 +00001141#endif // _LIBCPP_HAS_NO_VARIADICS
Howard Hinnantc51e1022010-05-11 19:42:16 +00001142#endif
Howard Hinnantac7e7482013-07-04 20:59:16 +00001143 __node_holder __construct_node_with_key(const key_type& __k);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001144
1145 __node_base_pointer&
1146 __find_equal_key(__node_base_pointer& __parent, const key_type& __k);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001147 __node_base_const_pointer
1148 __find_equal_key(__node_base_const_pointer& __parent, const key_type& __k) const;
1149};
1150
1151// Find place to insert if __k doesn't exist
1152// Set __parent to parent of null leaf
1153// Return reference to null leaf
1154// If __k exists, set parent to node of __k and return reference to node of __k
1155template <class _Key, class _Tp, class _Compare, class _Allocator>
1156typename map<_Key, _Tp, _Compare, _Allocator>::__node_base_pointer&
1157map<_Key, _Tp, _Compare, _Allocator>::__find_equal_key(__node_base_pointer& __parent,
1158 const key_type& __k)
1159{
1160 __node_pointer __nd = __tree_.__root();
1161 if (__nd != nullptr)
1162 {
1163 while (true)
1164 {
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001165 if (__tree_.value_comp().key_comp()(__k, __nd->__value_.__cc.first))
Howard Hinnantc51e1022010-05-11 19:42:16 +00001166 {
1167 if (__nd->__left_ != nullptr)
1168 __nd = static_cast<__node_pointer>(__nd->__left_);
1169 else
1170 {
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001171 __parent = static_cast<__node_base_pointer>(__nd);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001172 return __parent->__left_;
1173 }
1174 }
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001175 else if (__tree_.value_comp().key_comp()(__nd->__value_.__cc.first, __k))
Howard Hinnantc51e1022010-05-11 19:42:16 +00001176 {
1177 if (__nd->__right_ != nullptr)
1178 __nd = static_cast<__node_pointer>(__nd->__right_);
1179 else
1180 {
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001181 __parent = static_cast<__node_base_pointer>(__nd);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001182 return __parent->__right_;
1183 }
1184 }
1185 else
1186 {
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001187 __parent = static_cast<__node_base_pointer>(__nd);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001188 return __parent;
1189 }
1190 }
1191 }
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001192 __parent = static_cast<__node_base_pointer>(__tree_.__end_node());
Howard Hinnantc51e1022010-05-11 19:42:16 +00001193 return __parent->__left_;
1194}
1195
Howard Hinnantc51e1022010-05-11 19:42:16 +00001196// Find __k
1197// Set __parent to parent of null leaf and
1198// return reference to null leaf iv __k does not exist.
1199// If __k exists, set parent to node of __k and return reference to node of __k
1200template <class _Key, class _Tp, class _Compare, class _Allocator>
1201typename map<_Key, _Tp, _Compare, _Allocator>::__node_base_const_pointer
1202map<_Key, _Tp, _Compare, _Allocator>::__find_equal_key(__node_base_const_pointer& __parent,
1203 const key_type& __k) const
1204{
1205 __node_const_pointer __nd = __tree_.__root();
1206 if (__nd != nullptr)
1207 {
1208 while (true)
1209 {
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001210 if (__tree_.value_comp().key_comp()(__k, __nd->__value_.__cc.first))
Howard Hinnantc51e1022010-05-11 19:42:16 +00001211 {
1212 if (__nd->__left_ != nullptr)
1213 __nd = static_cast<__node_pointer>(__nd->__left_);
1214 else
1215 {
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001216 __parent = static_cast<__node_base_pointer>(__nd);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001217 return const_cast<const __node_base_const_pointer&>(__parent->__left_);
1218 }
1219 }
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001220 else if (__tree_.value_comp().key_comp()(__nd->__value_.__cc.first, __k))
Howard Hinnantc51e1022010-05-11 19:42:16 +00001221 {
1222 if (__nd->__right_ != nullptr)
1223 __nd = static_cast<__node_pointer>(__nd->__right_);
1224 else
1225 {
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001226 __parent = static_cast<__node_base_pointer>(__nd);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001227 return const_cast<const __node_base_const_pointer&>(__parent->__right_);
1228 }
1229 }
1230 else
1231 {
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001232 __parent = static_cast<__node_base_pointer>(__nd);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001233 return __parent;
1234 }
1235 }
1236 }
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001237 __parent = static_cast<__node_base_pointer>(__tree_.__end_node());
Howard Hinnantc51e1022010-05-11 19:42:16 +00001238 return const_cast<const __node_base_const_pointer&>(__parent->__left_);
1239}
1240
Howard Hinnant74279a52010-09-04 23:28:19 +00001241#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +00001242
1243template <class _Key, class _Tp, class _Compare, class _Allocator>
1244map<_Key, _Tp, _Compare, _Allocator>::map(map&& __m, const allocator_type& __a)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001245 : __tree_(_VSTD::move(__m.__tree_), __a)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001246{
1247 if (__a != __m.get_allocator())
1248 {
1249 const_iterator __e = cend();
1250 while (!__m.empty())
1251 __tree_.__insert_unique(__e.__i_,
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001252 _VSTD::move(__m.__tree_.remove(__m.begin().__i_)->__value_));
Howard Hinnantc51e1022010-05-11 19:42:16 +00001253 }
1254}
1255
1256template <class _Key, class _Tp, class _Compare, class _Allocator>
1257typename map<_Key, _Tp, _Compare, _Allocator>::__node_holder
1258map<_Key, _Tp, _Compare, _Allocator>::__construct_node()
1259{
1260 __node_allocator& __na = __tree_.__node_alloc();
Howard Hinnantc834c512011-11-29 18:15:50 +00001261 __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001262 __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__cc.first));
Howard Hinnantc51e1022010-05-11 19:42:16 +00001263 __h.get_deleter().__first_constructed = true;
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001264 __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__cc.second));
Howard Hinnantc51e1022010-05-11 19:42:16 +00001265 __h.get_deleter().__second_constructed = true;
1266 return __h;
1267}
1268
1269template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001270template <class _A0>
Howard Hinnantac7e7482013-07-04 20:59:16 +00001271typename map<_Key, _Tp, _Compare, _Allocator>::__node_holder
Howard Hinnantc51e1022010-05-11 19:42:16 +00001272map<_Key, _Tp, _Compare, _Allocator>::__construct_node(_A0&& __a0)
1273{
1274 __node_allocator& __na = __tree_.__node_alloc();
Howard Hinnantc834c512011-11-29 18:15:50 +00001275 __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001276 __node_traits::construct(__na, _VSTD::addressof(__h->__value_), _VSTD::forward<_A0>(__a0));
Howard Hinnantc51e1022010-05-11 19:42:16 +00001277 __h.get_deleter().__first_constructed = true;
1278 __h.get_deleter().__second_constructed = true;
1279 return __h;
1280}
1281
1282template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnantac7e7482013-07-04 20:59:16 +00001283typename map<_Key, _Tp, _Compare, _Allocator>::__node_holder
1284map<_Key, _Tp, _Compare, _Allocator>::__construct_node_with_key(key_type&& __k)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001285{
1286 __node_allocator& __na = __tree_.__node_alloc();
Howard Hinnantc834c512011-11-29 18:15:50 +00001287 __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
Howard Hinnantac7e7482013-07-04 20:59:16 +00001288 __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__cc.first), _VSTD::move(__k));
Howard Hinnantc51e1022010-05-11 19:42:16 +00001289 __h.get_deleter().__first_constructed = true;
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001290 __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__cc.second));
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001291 __h.get_deleter().__second_constructed = true;
Howard Hinnanta31e9682013-08-22 18:29:50 +00001292 return __h;
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001293}
1294
1295#ifndef _LIBCPP_HAS_NO_VARIADICS
1296
1297template <class _Key, class _Tp, class _Compare, class _Allocator>
1298template <class _A0, class _A1, class ..._Args>
1299typename map<_Key, _Tp, _Compare, _Allocator>::__node_holder
1300map<_Key, _Tp, _Compare, _Allocator>::__construct_node(_A0&& __a0, _A1&& __a1, _Args&& ...__args)
1301{
1302 __node_allocator& __na = __tree_.__node_alloc();
1303 __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
1304 __node_traits::construct(__na, _VSTD::addressof(__h->__value_),
1305 _VSTD::forward<_A0>(__a0), _VSTD::forward<_A1>(__a1),
1306 _VSTD::forward<_Args>(__args)...);
1307 __h.get_deleter().__first_constructed = true;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001308 __h.get_deleter().__second_constructed = true;
1309 return __h;
1310}
1311
Howard Hinnant74279a52010-09-04 23:28:19 +00001312#endif // _LIBCPP_HAS_NO_VARIADICS
1313
Howard Hinnantac7e7482013-07-04 20:59:16 +00001314#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +00001315
1316template <class _Key, class _Tp, class _Compare, class _Allocator>
1317typename map<_Key, _Tp, _Compare, _Allocator>::__node_holder
Howard Hinnantac7e7482013-07-04 20:59:16 +00001318map<_Key, _Tp, _Compare, _Allocator>::__construct_node_with_key(const key_type& __k)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001319{
1320 __node_allocator& __na = __tree_.__node_alloc();
Howard Hinnantc834c512011-11-29 18:15:50 +00001321 __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001322 __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__cc.first), __k);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001323 __h.get_deleter().__first_constructed = true;
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001324 __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__cc.second));
Howard Hinnantc51e1022010-05-11 19:42:16 +00001325 __h.get_deleter().__second_constructed = true;
Howard Hinnanta31e9682013-08-22 18:29:50 +00001326 return _VSTD::move(__h); // explicitly moved for C++03
Howard Hinnantc51e1022010-05-11 19:42:16 +00001327}
1328
Howard Hinnantc51e1022010-05-11 19:42:16 +00001329template <class _Key, class _Tp, class _Compare, class _Allocator>
1330_Tp&
1331map<_Key, _Tp, _Compare, _Allocator>::operator[](const key_type& __k)
1332{
1333 __node_base_pointer __parent;
1334 __node_base_pointer& __child = __find_equal_key(__parent, __k);
1335 __node_pointer __r = static_cast<__node_pointer>(__child);
1336 if (__child == nullptr)
1337 {
Howard Hinnantac7e7482013-07-04 20:59:16 +00001338 __node_holder __h = __construct_node_with_key(__k);
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001339 __tree_.__insert_node_at(__parent, __child, static_cast<__node_base_pointer>(__h.get()));
Howard Hinnantc51e1022010-05-11 19:42:16 +00001340 __r = __h.release();
1341 }
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001342 return __r->__value_.__cc.second;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001343}
1344
Howard Hinnant74279a52010-09-04 23:28:19 +00001345#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +00001346
1347template <class _Key, class _Tp, class _Compare, class _Allocator>
1348_Tp&
1349map<_Key, _Tp, _Compare, _Allocator>::operator[](key_type&& __k)
1350{
1351 __node_base_pointer __parent;
1352 __node_base_pointer& __child = __find_equal_key(__parent, __k);
1353 __node_pointer __r = static_cast<__node_pointer>(__child);
1354 if (__child == nullptr)
1355 {
Howard Hinnantac7e7482013-07-04 20:59:16 +00001356 __node_holder __h = __construct_node_with_key(_VSTD::move(__k));
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001357 __tree_.__insert_node_at(__parent, __child, static_cast<__node_base_pointer>(__h.get()));
Howard Hinnantc51e1022010-05-11 19:42:16 +00001358 __r = __h.release();
1359 }
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001360 return __r->__value_.__cc.second;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001361}
1362
Howard Hinnant74279a52010-09-04 23:28:19 +00001363#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +00001364
1365template <class _Key, class _Tp, class _Compare, class _Allocator>
1366_Tp&
1367map<_Key, _Tp, _Compare, _Allocator>::at(const key_type& __k)
1368{
1369 __node_base_pointer __parent;
1370 __node_base_pointer& __child = __find_equal_key(__parent, __k);
Howard Hinnant72f73582010-08-11 17:04:31 +00001371#ifndef _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +00001372 if (__child == nullptr)
1373 throw out_of_range("map::at: key not found");
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001374#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001375 return static_cast<__node_pointer>(__child)->__value_.__cc.second;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001376}
1377
1378template <class _Key, class _Tp, class _Compare, class _Allocator>
1379const _Tp&
1380map<_Key, _Tp, _Compare, _Allocator>::at(const key_type& __k) const
1381{
1382 __node_base_const_pointer __parent;
1383 __node_base_const_pointer __child = __find_equal_key(__parent, __k);
Howard Hinnant72f73582010-08-11 17:04:31 +00001384#ifndef _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +00001385 if (__child == nullptr)
1386 throw out_of_range("map::at: key not found");
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001387#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001388 return static_cast<__node_const_pointer>(__child)->__value_.__cc.second;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001389}
1390
Howard Hinnant74279a52010-09-04 23:28:19 +00001391#if !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001392
1393template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001394template <class ..._Args>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001395pair<typename map<_Key, _Tp, _Compare, _Allocator>::iterator, bool>
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001396map<_Key, _Tp, _Compare, _Allocator>::emplace(_Args&& ...__args)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001397{
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001398 __node_holder __h = __construct_node(_VSTD::forward<_Args>(__args)...);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001399 pair<iterator, bool> __r = __tree_.__node_insert_unique(__h.get());
1400 if (__r.second)
1401 __h.release();
1402 return __r;
1403}
1404
1405template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001406template <class ..._Args>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001407typename map<_Key, _Tp, _Compare, _Allocator>::iterator
1408map<_Key, _Tp, _Compare, _Allocator>::emplace_hint(const_iterator __p,
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001409 _Args&& ...__args)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001410{
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001411 __node_holder __h = __construct_node(_VSTD::forward<_Args>(__args)...);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001412 iterator __r = __tree_.__node_insert_unique(__p.__i_, __h.get());
1413 if (__r.__i_.__ptr_ == __h.get())
1414 __h.release();
1415 return __r;
1416}
1417
Howard Hinnant74279a52010-09-04 23:28:19 +00001418#endif // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001419
1420template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001421inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001422bool
1423operator==(const map<_Key, _Tp, _Compare, _Allocator>& __x,
1424 const map<_Key, _Tp, _Compare, _Allocator>& __y)
1425{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001426 return __x.size() == __y.size() && _VSTD::equal(__x.begin(), __x.end(), __y.begin());
Howard Hinnantc51e1022010-05-11 19:42:16 +00001427}
1428
1429template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001430inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001431bool
1432operator< (const map<_Key, _Tp, _Compare, _Allocator>& __x,
1433 const map<_Key, _Tp, _Compare, _Allocator>& __y)
1434{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001435 return _VSTD::lexicographical_compare(__x.begin(), __x.end(), __y.begin(), __y.end());
Howard Hinnantc51e1022010-05-11 19:42:16 +00001436}
1437
1438template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001439inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001440bool
1441operator!=(const map<_Key, _Tp, _Compare, _Allocator>& __x,
1442 const map<_Key, _Tp, _Compare, _Allocator>& __y)
1443{
1444 return !(__x == __y);
1445}
1446
1447template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001448inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001449bool
1450operator> (const map<_Key, _Tp, _Compare, _Allocator>& __x,
1451 const map<_Key, _Tp, _Compare, _Allocator>& __y)
1452{
1453 return __y < __x;
1454}
1455
1456template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001457inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001458bool
1459operator>=(const map<_Key, _Tp, _Compare, _Allocator>& __x,
1460 const map<_Key, _Tp, _Compare, _Allocator>& __y)
1461{
1462 return !(__x < __y);
1463}
1464
1465template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001466inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001467bool
1468operator<=(const map<_Key, _Tp, _Compare, _Allocator>& __x,
1469 const map<_Key, _Tp, _Compare, _Allocator>& __y)
1470{
1471 return !(__y < __x);
1472}
1473
1474template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001475inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001476void
1477swap(map<_Key, _Tp, _Compare, _Allocator>& __x,
1478 map<_Key, _Tp, _Compare, _Allocator>& __y)
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001479 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
Howard Hinnantc51e1022010-05-11 19:42:16 +00001480{
1481 __x.swap(__y);
1482}
1483
1484template <class _Key, class _Tp, class _Compare = less<_Key>,
1485 class _Allocator = allocator<pair<const _Key, _Tp> > >
Howard Hinnanta37d3cf2013-08-12 18:38:34 +00001486class _LIBCPP_TYPE_VIS_ONLY multimap
Howard Hinnantc51e1022010-05-11 19:42:16 +00001487{
1488public:
1489 // types:
1490 typedef _Key key_type;
1491 typedef _Tp mapped_type;
1492 typedef pair<const key_type, mapped_type> value_type;
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001493 typedef pair<key_type, mapped_type> __nc_value_type;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001494 typedef _Compare key_compare;
1495 typedef _Allocator allocator_type;
1496 typedef value_type& reference;
1497 typedef const value_type& const_reference;
1498
Howard Hinnanta37d3cf2013-08-12 18:38:34 +00001499 class _LIBCPP_TYPE_VIS_ONLY value_compare
Howard Hinnantc51e1022010-05-11 19:42:16 +00001500 : public binary_function<value_type, value_type, bool>
1501 {
1502 friend class multimap;
1503 protected:
1504 key_compare comp;
1505
Howard Hinnant756c69b2010-09-22 16:48:34 +00001506 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001507 value_compare(key_compare c) : comp(c) {}
1508 public:
Howard Hinnant756c69b2010-09-22 16:48:34 +00001509 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001510 bool operator()(const value_type& __x, const value_type& __y) const
1511 {return comp(__x.first, __y.first);}
1512 };
1513
1514private:
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001515#if __cplusplus >= 201103L
1516 union __value_type
1517 {
1518 typedef typename multimap::value_type value_type;
1519 typedef typename multimap::__nc_value_type __nc_value_type;
1520 value_type __cc;
1521 __nc_value_type __nc;
1522
1523 template <class ..._Args>
1524 __value_type(_Args&& ...__args)
1525 : __cc(std::forward<_Args>(__args)...) {}
1526
1527 __value_type(const __value_type& __v)
1528 : __cc(std::move(__v.__cc)) {}
1529
1530 __value_type(__value_type&& __v)
1531 : __nc(std::move(__v.__nc)) {}
1532
1533 __value_type& operator=(const __value_type& __v)
1534 {__nc = __v.__cc; return *this;}
1535
1536 __value_type& operator=(__value_type&& __v)
1537 {__nc = std::move(__v.__nc); return *this;}
1538
1539 ~__value_type() {__cc.~value_type();}
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001540 };
1541#else
1542 struct __value_type
1543 {
1544 typedef typename multimap::value_type value_type;
1545 value_type __cc;
1546
1547 __value_type() {}
1548
1549 template <class _A0>
1550 __value_type(const _A0& __a0)
1551 : __cc(__a0) {}
1552
1553 template <class _A0, class _A1>
1554 __value_type(const _A0& __a0, const _A1& __a1)
1555 : __cc(__a0, __a1) {}
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001556 };
1557#endif
Howard Hinnant90b91592013-07-05 18:06:00 +00001558 typedef __map_value_compare<key_type, __value_type, key_compare> __vc;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001559 typedef typename allocator_traits<allocator_type>::template
1560#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
1561 rebind_alloc<__value_type>
1562#else
1563 rebind_alloc<__value_type>::other
1564#endif
1565 __allocator_type;
1566 typedef __tree<__value_type, __vc, __allocator_type> __base;
1567 typedef typename __base::__node_traits __node_traits;
1568 typedef allocator_traits<allocator_type> __alloc_traits;
1569
1570 __base __tree_;
1571
1572public:
1573 typedef typename __alloc_traits::pointer pointer;
1574 typedef typename __alloc_traits::const_pointer const_pointer;
1575 typedef typename __alloc_traits::size_type size_type;
1576 typedef typename __alloc_traits::difference_type difference_type;
1577 typedef __map_iterator<typename __base::iterator> iterator;
1578 typedef __map_const_iterator<typename __base::const_iterator> const_iterator;
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001579 typedef _VSTD::reverse_iterator<iterator> reverse_iterator;
1580 typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001581
Howard Hinnant756c69b2010-09-22 16:48:34 +00001582 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001583 explicit multimap(const key_compare& __comp = key_compare())
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001584 _NOEXCEPT_(
1585 is_nothrow_default_constructible<allocator_type>::value &&
1586 is_nothrow_default_constructible<key_compare>::value &&
1587 is_nothrow_copy_constructible<key_compare>::value)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001588 : __tree_(__vc(__comp)) {}
1589
Howard Hinnant756c69b2010-09-22 16:48:34 +00001590 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001591 explicit multimap(const key_compare& __comp, const allocator_type& __a)
1592 : __tree_(__vc(__comp), __a) {}
1593
1594 template <class _InputIterator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001595 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001596 multimap(_InputIterator __f, _InputIterator __l,
1597 const key_compare& __comp = key_compare())
1598 : __tree_(__vc(__comp))
1599 {
1600 insert(__f, __l);
1601 }
1602
1603 template <class _InputIterator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001604 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001605 multimap(_InputIterator __f, _InputIterator __l,
1606 const key_compare& __comp, const allocator_type& __a)
1607 : __tree_(__vc(__comp), __a)
1608 {
1609 insert(__f, __l);
1610 }
1611
Marshall Clow300abfb2013-09-11 01:15:47 +00001612#if _LIBCPP_STD_VER > 11
1613 template <class _InputIterator>
1614 _LIBCPP_INLINE_VISIBILITY
1615 multimap(_InputIterator __f, _InputIterator __l, const allocator_type& __a)
1616 : multimap(__f, __l, key_compare(), __a) {}
1617#endif
1618
Howard Hinnant756c69b2010-09-22 16:48:34 +00001619 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001620 multimap(const multimap& __m)
1621 : __tree_(__m.__tree_.value_comp(),
1622 __alloc_traits::select_on_container_copy_construction(__m.__tree_.__alloc()))
1623 {
1624 insert(__m.begin(), __m.end());
1625 }
1626
Howard Hinnantd3a657f2011-07-01 19:24:36 +00001627 _LIBCPP_INLINE_VISIBILITY
1628 multimap& operator=(const multimap& __m)
1629 {
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001630#if __cplusplus >= 201103L
Howard Hinnantd3a657f2011-07-01 19:24:36 +00001631 __tree_ = __m.__tree_;
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001632#else
1633 __tree_.clear();
1634 __tree_.value_comp() = __m.__tree_.value_comp();
1635 __tree_.__copy_assign_alloc(__m.__tree_);
1636 insert(__m.begin(), __m.end());
1637#endif
Howard Hinnantd3a657f2011-07-01 19:24:36 +00001638 return *this;
1639 }
1640
Howard Hinnant74279a52010-09-04 23:28:19 +00001641#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +00001642
Howard Hinnant756c69b2010-09-22 16:48:34 +00001643 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001644 multimap(multimap&& __m)
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001645 _NOEXCEPT_(is_nothrow_move_constructible<__base>::value)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001646 : __tree_(_VSTD::move(__m.__tree_))
Howard Hinnantc51e1022010-05-11 19:42:16 +00001647 {
1648 }
1649
1650 multimap(multimap&& __m, const allocator_type& __a);
1651
Howard Hinnant756c69b2010-09-22 16:48:34 +00001652 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant33711792011-08-12 21:56:02 +00001653 multimap& operator=(multimap&& __m)
1654 _NOEXCEPT_(is_nothrow_move_assignable<__base>::value)
1655 {
1656 __tree_ = _VSTD::move(__m.__tree_);
1657 return *this;
1658 }
1659
1660#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
1661
1662#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1663
1664 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001665 multimap(initializer_list<value_type> __il, const key_compare& __comp = key_compare())
1666 : __tree_(__vc(__comp))
1667 {
1668 insert(__il.begin(), __il.end());
1669 }
1670
Howard Hinnant756c69b2010-09-22 16:48:34 +00001671 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001672 multimap(initializer_list<value_type> __il, const key_compare& __comp, const allocator_type& __a)
1673 : __tree_(__vc(__comp), __a)
1674 {
1675 insert(__il.begin(), __il.end());
1676 }
1677
Marshall Clow300abfb2013-09-11 01:15:47 +00001678#if _LIBCPP_STD_VER > 11
1679 _LIBCPP_INLINE_VISIBILITY
1680 multimap(initializer_list<value_type> __il, const allocator_type& __a)
1681 : multimap(__il, key_compare(), __a) {}
1682#endif
1683
Howard Hinnant756c69b2010-09-22 16:48:34 +00001684 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001685 multimap& operator=(initializer_list<value_type> __il)
1686 {
1687 __tree_.__assign_multi(__il.begin(), __il.end());
1688 return *this;
1689 }
Howard Hinnant33711792011-08-12 21:56:02 +00001690
1691#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantc51e1022010-05-11 19:42:16 +00001692
Howard Hinnant756c69b2010-09-22 16:48:34 +00001693 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001694 explicit multimap(const allocator_type& __a)
1695 : __tree_(__a)
1696 {
1697 }
1698
Howard Hinnant756c69b2010-09-22 16:48:34 +00001699 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001700 multimap(const multimap& __m, const allocator_type& __a)
1701 : __tree_(__m.__tree_.value_comp(), __a)
1702 {
1703 insert(__m.begin(), __m.end());
1704 }
1705
Howard Hinnant756c69b2010-09-22 16:48:34 +00001706 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001707 iterator begin() _NOEXCEPT {return __tree_.begin();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001708 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001709 const_iterator begin() const _NOEXCEPT {return __tree_.begin();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001710 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001711 iterator end() _NOEXCEPT {return __tree_.end();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001712 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001713 const_iterator end() const _NOEXCEPT {return __tree_.end();}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001714
Howard Hinnant756c69b2010-09-22 16:48:34 +00001715 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001716 reverse_iterator rbegin() _NOEXCEPT {return reverse_iterator(end());}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001717 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001718 const_reverse_iterator rbegin() const _NOEXCEPT
1719 {return const_reverse_iterator(end());}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001720 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001721 reverse_iterator rend() _NOEXCEPT {return reverse_iterator(begin());}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001722 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001723 const_reverse_iterator rend() const _NOEXCEPT
1724 {return const_reverse_iterator(begin());}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001725
Howard Hinnant756c69b2010-09-22 16:48:34 +00001726 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001727 const_iterator cbegin() const _NOEXCEPT {return begin();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001728 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001729 const_iterator cend() const _NOEXCEPT {return end();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001730 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001731 const_reverse_iterator crbegin() const _NOEXCEPT {return rbegin();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001732 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001733 const_reverse_iterator crend() const _NOEXCEPT {return rend();}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001734
Howard Hinnant756c69b2010-09-22 16:48:34 +00001735 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001736 bool empty() const _NOEXCEPT {return __tree_.size() == 0;}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001737 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001738 size_type size() const _NOEXCEPT {return __tree_.size();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001739 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001740 size_type max_size() const _NOEXCEPT {return __tree_.max_size();}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001741
Howard Hinnant756c69b2010-09-22 16:48:34 +00001742 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001743 allocator_type get_allocator() const _NOEXCEPT {return __tree_.__alloc();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001744 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001745 key_compare key_comp() const {return __tree_.value_comp().key_comp();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001746 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001747 value_compare value_comp() const
1748 {return value_compare(__tree_.value_comp().key_comp());}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001749
Howard Hinnant74279a52010-09-04 23:28:19 +00001750#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant74279a52010-09-04 23:28:19 +00001751#ifndef _LIBCPP_HAS_NO_VARIADICS
1752
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001753 template <class ..._Args>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001754 iterator
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001755 emplace(_Args&& ...__args);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001756
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001757 template <class ..._Args>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001758 iterator
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001759 emplace_hint(const_iterator __p, _Args&& ...__args);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001760
Howard Hinnant74279a52010-09-04 23:28:19 +00001761#endif // _LIBCPP_HAS_NO_VARIADICS
1762
Howard Hinnantc834c512011-11-29 18:15:50 +00001763 template <class _Pp,
1764 class = typename enable_if<is_constructible<value_type, _Pp>::value>::type>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001765 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc834c512011-11-29 18:15:50 +00001766 iterator insert(_Pp&& __p)
1767 {return __tree_.__insert_multi(_VSTD::forward<_Pp>(__p));}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001768
Howard Hinnantc834c512011-11-29 18:15:50 +00001769 template <class _Pp,
1770 class = typename enable_if<is_constructible<value_type, _Pp>::value>::type>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001771 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc834c512011-11-29 18:15:50 +00001772 iterator insert(const_iterator __pos, _Pp&& __p)
1773 {return __tree_.__insert_multi(__pos.__i_, _VSTD::forward<_Pp>(__p));}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001774
Howard Hinnant74279a52010-09-04 23:28:19 +00001775#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +00001776
Howard Hinnant756c69b2010-09-22 16:48:34 +00001777 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001778 iterator insert(const value_type& __v) {return __tree_.__insert_multi(__v);}
1779
Howard Hinnant756c69b2010-09-22 16:48:34 +00001780 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001781 iterator insert(const_iterator __p, const value_type& __v)
1782 {return __tree_.__insert_multi(__p.__i_, __v);}
1783
1784 template <class _InputIterator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001785 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001786 void insert(_InputIterator __f, _InputIterator __l)
1787 {
1788 for (const_iterator __e = cend(); __f != __l; ++__f)
1789 __tree_.__insert_multi(__e.__i_, *__f);
1790 }
1791
Howard Hinnant33711792011-08-12 21:56:02 +00001792#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1793
Howard Hinnant756c69b2010-09-22 16:48:34 +00001794 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001795 void insert(initializer_list<value_type> __il)
1796 {insert(__il.begin(), __il.end());}
1797
Howard Hinnant33711792011-08-12 21:56:02 +00001798#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1799
Howard Hinnant756c69b2010-09-22 16:48:34 +00001800 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001801 iterator erase(const_iterator __p) {return __tree_.erase(__p.__i_);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001802 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001803 size_type erase(const key_type& __k) {return __tree_.__erase_multi(__k);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001804 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001805 iterator erase(const_iterator __f, const_iterator __l)
1806 {return __tree_.erase(__f.__i_, __l.__i_);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001807 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001808 void clear() {__tree_.clear();}
1809
Howard Hinnant756c69b2010-09-22 16:48:34 +00001810 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001811 void swap(multimap& __m)
1812 _NOEXCEPT_(__is_nothrow_swappable<__base>::value)
1813 {__tree_.swap(__m.__tree_);}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001814
Howard Hinnant756c69b2010-09-22 16:48:34 +00001815 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001816 iterator find(const key_type& __k) {return __tree_.find(__k);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001817 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001818 const_iterator find(const key_type& __k) const {return __tree_.find(__k);}
Marshall Clowebb57322013-08-13 22:18:47 +00001819#if _LIBCPP_STD_VER > 11
1820 template <typename _K2>
1821 _LIBCPP_INLINE_VISIBILITY
1822 typename enable_if<__is_transparent<_Compare, _K2>::value,iterator>::type
1823 find(const _K2& __k) {return __tree_.find(__k);}
1824 template <typename _K2>
1825 _LIBCPP_INLINE_VISIBILITY
1826 typename enable_if<__is_transparent<_Compare, _K2>::value,const_iterator>::type
1827 find(const _K2& __k) const {return __tree_.find(__k);}
1828#endif
1829
Howard Hinnant756c69b2010-09-22 16:48:34 +00001830 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001831 size_type count(const key_type& __k) const
1832 {return __tree_.__count_multi(__k);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001833 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001834 iterator lower_bound(const key_type& __k)
1835 {return __tree_.lower_bound(__k);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001836 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001837 const_iterator lower_bound(const key_type& __k) const
1838 {return __tree_.lower_bound(__k);}
Marshall Clowebb57322013-08-13 22:18:47 +00001839#if _LIBCPP_STD_VER > 11
1840 template <typename _K2>
1841 _LIBCPP_INLINE_VISIBILITY
1842 typename enable_if<__is_transparent<_Compare, _K2>::value,iterator>::type
1843 lower_bound(const _K2& __k) {return __tree_.lower_bound(__k);}
1844
1845 template <typename _K2>
1846 _LIBCPP_INLINE_VISIBILITY
1847 typename enable_if<__is_transparent<_Compare, _K2>::value,const_iterator>::type
1848 lower_bound(const _K2& __k) const {return __tree_.lower_bound(__k);}
1849#endif
1850
Howard Hinnant756c69b2010-09-22 16:48:34 +00001851 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001852 iterator upper_bound(const key_type& __k)
1853 {return __tree_.upper_bound(__k);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001854 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001855 const_iterator upper_bound(const key_type& __k) const
1856 {return __tree_.upper_bound(__k);}
Marshall Clowebb57322013-08-13 22:18:47 +00001857#if _LIBCPP_STD_VER > 11
1858 template <typename _K2>
1859 _LIBCPP_INLINE_VISIBILITY
1860 typename enable_if<__is_transparent<_Compare, _K2>::value,iterator>::type
1861 upper_bound(const _K2& __k) {return __tree_.upper_bound(__k);}
1862 template <typename _K2>
1863 _LIBCPP_INLINE_VISIBILITY
1864 typename enable_if<__is_transparent<_Compare, _K2>::value,const_iterator>::type
1865 upper_bound(const _K2& __k) const {return __tree_.upper_bound(__k);}
1866#endif
1867
Howard Hinnant756c69b2010-09-22 16:48:34 +00001868 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001869 pair<iterator,iterator> equal_range(const key_type& __k)
1870 {return __tree_.__equal_range_multi(__k);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001871 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001872 pair<const_iterator,const_iterator> equal_range(const key_type& __k) const
1873 {return __tree_.__equal_range_multi(__k);}
Marshall Clowebb57322013-08-13 22:18:47 +00001874#if _LIBCPP_STD_VER > 11
1875 template <typename _K2>
1876 _LIBCPP_INLINE_VISIBILITY
1877 typename enable_if<__is_transparent<_Compare, _K2>::value,pair<iterator,iterator>>::type
1878 equal_range(const _K2& __k) {return __tree_.__equal_range_multi(__k);}
1879 template <typename _K2>
1880 _LIBCPP_INLINE_VISIBILITY
1881 typename enable_if<__is_transparent<_Compare, _K2>::value,pair<const_iterator,const_iterator>>::type
1882 equal_range(const _K2& __k) const {return __tree_.__equal_range_multi(__k);}
1883#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001884
1885private:
1886 typedef typename __base::__node __node;
1887 typedef typename __base::__node_allocator __node_allocator;
1888 typedef typename __base::__node_pointer __node_pointer;
1889 typedef typename __base::__node_const_pointer __node_const_pointer;
Howard Hinnantc834c512011-11-29 18:15:50 +00001890 typedef __map_node_destructor<__node_allocator> _Dp;
1891 typedef unique_ptr<__node, _Dp> __node_holder;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001892
Howard Hinnant74279a52010-09-04 23:28:19 +00001893#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +00001894 __node_holder __construct_node();
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001895 template <class _A0>
Howard Hinnantac7e7482013-07-04 20:59:16 +00001896 __node_holder
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001897 __construct_node(_A0&& __a0);
Howard Hinnant74279a52010-09-04 23:28:19 +00001898#ifndef _LIBCPP_HAS_NO_VARIADICS
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001899 template <class _A0, class _A1, class ..._Args>
1900 __node_holder __construct_node(_A0&& __a0, _A1&& __a1, _Args&& ...__args);
Howard Hinnant74279a52010-09-04 23:28:19 +00001901#endif // _LIBCPP_HAS_NO_VARIADICS
1902#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +00001903};
1904
Howard Hinnant74279a52010-09-04 23:28:19 +00001905#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +00001906
1907template <class _Key, class _Tp, class _Compare, class _Allocator>
1908multimap<_Key, _Tp, _Compare, _Allocator>::multimap(multimap&& __m, const allocator_type& __a)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001909 : __tree_(_VSTD::move(__m.__tree_), __a)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001910{
1911 if (__a != __m.get_allocator())
1912 {
1913 const_iterator __e = cend();
1914 while (!__m.empty())
1915 __tree_.__insert_multi(__e.__i_,
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001916 _VSTD::move(__m.__tree_.remove(__m.begin().__i_)->__value_));
Howard Hinnantc51e1022010-05-11 19:42:16 +00001917 }
1918}
1919
1920template <class _Key, class _Tp, class _Compare, class _Allocator>
1921typename multimap<_Key, _Tp, _Compare, _Allocator>::__node_holder
1922multimap<_Key, _Tp, _Compare, _Allocator>::__construct_node()
1923{
1924 __node_allocator& __na = __tree_.__node_alloc();
Howard Hinnantc834c512011-11-29 18:15:50 +00001925 __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001926 __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__cc.first));
Howard Hinnantc51e1022010-05-11 19:42:16 +00001927 __h.get_deleter().__first_constructed = true;
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001928 __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__cc.second));
Howard Hinnantc51e1022010-05-11 19:42:16 +00001929 __h.get_deleter().__second_constructed = true;
1930 return __h;
1931}
1932
1933template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001934template <class _A0>
Howard Hinnantac7e7482013-07-04 20:59:16 +00001935typename multimap<_Key, _Tp, _Compare, _Allocator>::__node_holder
Howard Hinnantc51e1022010-05-11 19:42:16 +00001936multimap<_Key, _Tp, _Compare, _Allocator>::__construct_node(_A0&& __a0)
1937{
1938 __node_allocator& __na = __tree_.__node_alloc();
Howard Hinnantc834c512011-11-29 18:15:50 +00001939 __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001940 __node_traits::construct(__na, _VSTD::addressof(__h->__value_), _VSTD::forward<_A0>(__a0));
Howard Hinnantc51e1022010-05-11 19:42:16 +00001941 __h.get_deleter().__first_constructed = true;
1942 __h.get_deleter().__second_constructed = true;
1943 return __h;
1944}
1945
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001946#ifndef _LIBCPP_HAS_NO_VARIADICS
1947
1948template <class _Key, class _Tp, class _Compare, class _Allocator>
1949template <class _A0, class _A1, class ..._Args>
1950typename multimap<_Key, _Tp, _Compare, _Allocator>::__node_holder
1951multimap<_Key, _Tp, _Compare, _Allocator>::__construct_node(_A0&& __a0, _A1&& __a1, _Args&& ...__args)
1952{
1953 __node_allocator& __na = __tree_.__node_alloc();
1954 __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
1955 __node_traits::construct(__na, _VSTD::addressof(__h->__value_),
1956 _VSTD::forward<_A0>(__a0), _VSTD::forward<_A1>(__a1),
1957 _VSTD::forward<_Args>(__args)...);
1958 __h.get_deleter().__first_constructed = true;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001959 __h.get_deleter().__second_constructed = true;
1960 return __h;
1961}
1962
Howard Hinnant74279a52010-09-04 23:28:19 +00001963#endif // _LIBCPP_HAS_NO_VARIADICS
1964#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +00001965
Howard Hinnant74279a52010-09-04 23:28:19 +00001966#if !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001967
1968template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001969template <class ..._Args>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001970typename multimap<_Key, _Tp, _Compare, _Allocator>::iterator
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001971multimap<_Key, _Tp, _Compare, _Allocator>::emplace(_Args&& ...__args)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001972{
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001973 __node_holder __h = __construct_node(_VSTD::forward<_Args>(__args)...);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001974 iterator __r = __tree_.__node_insert_multi(__h.get());
1975 __h.release();
1976 return __r;
1977}
1978
1979template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001980template <class ..._Args>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001981typename multimap<_Key, _Tp, _Compare, _Allocator>::iterator
1982multimap<_Key, _Tp, _Compare, _Allocator>::emplace_hint(const_iterator __p,
Howard Hinnantc51e1022010-05-11 19:42:16 +00001983 _Args&& ...__args)
1984{
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001985 __node_holder __h = __construct_node(_VSTD::forward<_Args>(__args)...);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001986 iterator __r = __tree_.__node_insert_multi(__p.__i_, __h.get());
1987 __h.release();
1988 return __r;
1989}
1990
Howard Hinnant74279a52010-09-04 23:28:19 +00001991#endif // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001992
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{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001999 return __x.size() == __y.size() && _VSTD::equal(__x.begin(), __x.end(), __y.begin());
Howard Hinnantc51e1022010-05-11 19:42:16 +00002000}
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{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00002008 return _VSTD::lexicographical_compare(__x.begin(), __x.end(), __y.begin(), __y.end());
Howard Hinnantc51e1022010-05-11 19:42:16 +00002009}
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 +00002013bool
2014operator!=(const multimap<_Key, _Tp, _Compare, _Allocator>& __x,
2015 const multimap<_Key, _Tp, _Compare, _Allocator>& __y)
2016{
2017 return !(__x == __y);
2018}
2019
2020template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00002021inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002022bool
2023operator> (const multimap<_Key, _Tp, _Compare, _Allocator>& __x,
2024 const multimap<_Key, _Tp, _Compare, _Allocator>& __y)
2025{
2026 return __y < __x;
2027}
2028
2029template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00002030inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002031bool
2032operator>=(const multimap<_Key, _Tp, _Compare, _Allocator>& __x,
2033 const multimap<_Key, _Tp, _Compare, _Allocator>& __y)
2034{
2035 return !(__x < __y);
2036}
2037
2038template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00002039inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002040bool
2041operator<=(const multimap<_Key, _Tp, _Compare, _Allocator>& __x,
2042 const multimap<_Key, _Tp, _Compare, _Allocator>& __y)
2043{
2044 return !(__y < __x);
2045}
2046
2047template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00002048inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002049void
2050swap(multimap<_Key, _Tp, _Compare, _Allocator>& __x,
2051 multimap<_Key, _Tp, _Compare, _Allocator>& __y)
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00002052 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
Howard Hinnantc51e1022010-05-11 19:42:16 +00002053{
2054 __x.swap(__y);
2055}
2056
2057_LIBCPP_END_NAMESPACE_STD
2058
2059#endif // _LIBCPP_MAP