blob: abdaa3b6b5cca62be8b75a2fd81774e3501785a9 [file] [log] [blame]
Howard Hinnantbc8d3f92010-05-11 19:42:161// -*- C++ -*-
2//===----------------------------- map ------------------------------------===//
3//
Howard Hinnantf5256e12010-05-11 21:36:014// The LLVM Compiler Infrastructure
Howard Hinnantbc8d3f92010-05-11 19:42:165//
Howard Hinnantb64f8b02010-11-16 22:09:026// This file is dual licensed under the MIT and the University of Illinois Open
7// Source Licenses. See LICENSE.TXT for details.
Howard Hinnantbc8d3f92010-05-11 19:42:168//
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 Hinnant7686add2011-06-04 14:31:5757 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 Hinnantbc8d3f92010-05-11 19:42:1662 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 Hinnant7686add2011-06-04 14:31:5771 map(map&& m)
72 noexcept(
73 is_nothrow_move_constructible<allocator_type>::value &&
74 is_nothrow_move_constructible<key_compare>::value);
Howard Hinnantbc8d3f92010-05-11 19:42:1675 explicit map(const allocator_type& a);
76 map(const map& m, const allocator_type& a);
77 map(map&& m, const allocator_type& a);
78 map(initializer_list<value_type> il, const key_compare& comp = key_compare());
79 map(initializer_list<value_type> il, const key_compare& comp, const allocator_type& a);
80 ~map();
81
82 map& operator=(const map& m);
Howard Hinnant7686add2011-06-04 14:31:5783 map& operator=(map&& m)
84 noexcept(
85 allocator_type::propagate_on_container_move_assignment::value &&
86 is_nothrow_move_assignable<allocator_type>::value &&
Howard Hinnantb2e2a8f2011-06-04 15:22:3487 is_nothrow_move_assignable<key_compare>::value);
Howard Hinnantbc8d3f92010-05-11 19:42:1688 map& operator=(initializer_list<value_type> il);
89
90 // iterators:
Howard Hinnantb2e2a8f2011-06-04 15:22:3491 iterator begin() noexcept;
92 const_iterator begin() const noexcept;
93 iterator end() noexcept;
94 const_iterator end() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:1695
Howard Hinnantb2e2a8f2011-06-04 15:22:3496 reverse_iterator rbegin() noexcept;
97 const_reverse_iterator rbegin() const noexcept;
98 reverse_iterator rend() noexcept;
99 const_reverse_iterator rend() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16100
Howard Hinnantb2e2a8f2011-06-04 15:22:34101 const_iterator cbegin() const noexcept;
102 const_iterator cend() const noexcept;
103 const_reverse_iterator crbegin() const noexcept;
104 const_reverse_iterator crend() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16105
106 // capacity:
Howard Hinnantb2e2a8f2011-06-04 15:22:34107 bool empty() const noexcept;
108 size_type size() const noexcept;
109 size_type max_size() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16110
111 // element access:
112 mapped_type& operator[](const key_type& k);
113 mapped_type& operator[](key_type&& k);
114
115 mapped_type& at(const key_type& k);
116 const mapped_type& at(const key_type& k) const;
117
118 // modifiers:
119 template <class... Args>
120 pair<iterator, bool> emplace(Args&&... args);
121 template <class... Args>
122 iterator emplace_hint(const_iterator position, Args&&... args);
123 pair<iterator, bool> insert(const value_type& v);
124 template <class P>
125 pair<iterator, bool> insert(P&& p);
126 iterator insert(const_iterator position, const value_type& v);
127 template <class P>
128 iterator insert(const_iterator position, P&& p);
129 template <class InputIterator>
130 void insert(InputIterator first, InputIterator last);
131 void insert(initializer_list<value_type> il);
132
133 iterator erase(const_iterator position);
134 size_type erase(const key_type& k);
135 iterator erase(const_iterator first, const_iterator last);
Howard Hinnantb2e2a8f2011-06-04 15:22:34136 void clear() noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16137
Howard Hinnant7686add2011-06-04 14:31:57138 void swap(map& m)
139 noexcept(
140 __is_nothrow_swappable<key_compare>::value &&
141 (!allocator_type::propagate_on_container_swap::value ||
142 __is_nothrow_swappable<allocator_type>::value));
Howard Hinnantbc8d3f92010-05-11 19:42:16143
144 // observers:
Howard Hinnantb2e2a8f2011-06-04 15:22:34145 allocator_type get_allocator() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16146 key_compare key_comp() const;
147 value_compare value_comp() const;
148
149 // map operations:
150 iterator find(const key_type& k);
151 const_iterator find(const key_type& k) const;
152 size_type count(const key_type& k) const;
153 iterator lower_bound(const key_type& k);
154 const_iterator lower_bound(const key_type& k) const;
155 iterator upper_bound(const key_type& k);
156 const_iterator upper_bound(const key_type& k) const;
157 pair<iterator,iterator> equal_range(const key_type& k);
158 pair<const_iterator,const_iterator> equal_range(const key_type& k) const;
159};
160
161template <class Key, class T, class Compare, class Allocator>
162bool
163operator==(const map<Key, T, Compare, Allocator>& x,
164 const map<Key, T, Compare, Allocator>& y);
165
166template <class Key, class T, class Compare, class Allocator>
167bool
168operator< (const map<Key, T, Compare, Allocator>& x,
169 const map<Key, T, Compare, Allocator>& y);
170
171template <class Key, class T, class Compare, class Allocator>
172bool
173operator!=(const map<Key, T, Compare, Allocator>& x,
174 const map<Key, T, Compare, Allocator>& y);
175
176template <class Key, class T, class Compare, class Allocator>
177bool
178operator> (const map<Key, T, Compare, Allocator>& x,
179 const map<Key, T, Compare, Allocator>& y);
180
181template <class Key, class T, class Compare, class Allocator>
182bool
183operator>=(const map<Key, T, Compare, Allocator>& x,
184 const map<Key, T, Compare, Allocator>& y);
185
186template <class Key, class T, class Compare, class Allocator>
187bool
188operator<=(const map<Key, T, Compare, Allocator>& x,
189 const map<Key, T, Compare, Allocator>& y);
190
191// specialized algorithms:
192template <class Key, class T, class Compare, class Allocator>
193void
Howard Hinnant7686add2011-06-04 14:31:57194swap(map<Key, T, Compare, Allocator>& x, map<Key, T, Compare, Allocator>& y)
195 noexcept(noexcept(x.swap(y)));
Howard Hinnantbc8d3f92010-05-11 19:42:16196
197template <class Key, class T, class Compare = less<Key>,
198 class Allocator = allocator<pair<const Key, T>>>
199class multimap
200{
201public:
202 // types:
203 typedef Key key_type;
204 typedef T mapped_type;
205 typedef pair<const key_type,mapped_type> value_type;
206 typedef Compare key_compare;
207 typedef Allocator allocator_type;
208 typedef typename allocator_type::reference reference;
209 typedef typename allocator_type::const_reference const_reference;
210 typedef typename allocator_type::size_type size_type;
211 typedef typename allocator_type::difference_type difference_type;
212 typedef typename allocator_type::pointer pointer;
213 typedef typename allocator_type::const_pointer const_pointer;
214
215 typedef implementation-defined iterator;
216 typedef implementation-defined const_iterator;
217 typedef std::reverse_iterator<iterator> reverse_iterator;
218 typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
219
220 class value_compare
221 : public binary_function<value_type,value_type,bool>
222 {
223 friend class multimap;
224 protected:
225 key_compare comp;
226 value_compare(key_compare c);
227 public:
228 bool operator()(const value_type& x, const value_type& y) const;
229 };
230
231 // construct/copy/destroy:
Howard Hinnant7686add2011-06-04 14:31:57232 multimap()
233 noexcept(
234 is_nothrow_default_constructible<allocator_type>::value &&
235 is_nothrow_default_constructible<key_compare>::value &&
236 is_nothrow_copy_constructible<key_compare>::value);
237 explicit multimap(const key_compare& comp);
Howard Hinnantbc8d3f92010-05-11 19:42:16238 multimap(const key_compare& comp, const allocator_type& a);
239 template <class InputIterator>
240 multimap(InputIterator first, InputIterator last, const key_compare& comp);
241 template <class InputIterator>
242 multimap(InputIterator first, InputIterator last, const key_compare& comp,
243 const allocator_type& a);
244 multimap(const multimap& m);
Howard Hinnant7686add2011-06-04 14:31:57245 multimap(multimap&& m)
246 noexcept(
247 is_nothrow_move_constructible<allocator_type>::value &&
248 is_nothrow_move_constructible<key_compare>::value);
Howard Hinnantbc8d3f92010-05-11 19:42:16249 explicit multimap(const allocator_type& a);
250 multimap(const multimap& m, const allocator_type& a);
251 multimap(multimap&& m, const allocator_type& a);
252 multimap(initializer_list<value_type> il, const key_compare& comp = key_compare());
253 multimap(initializer_list<value_type> il, const key_compare& comp,
254 const allocator_type& a);
255 ~multimap();
256
257 multimap& operator=(const multimap& m);
Howard Hinnant7686add2011-06-04 14:31:57258 multimap& operator=(multimap&& m)
259 noexcept(
260 allocator_type::propagate_on_container_move_assignment::value &&
261 is_nothrow_move_assignable<allocator_type>::value &&
Howard Hinnantb2e2a8f2011-06-04 15:22:34262 is_nothrow_move_assignable<key_compare>::value);
Howard Hinnantbc8d3f92010-05-11 19:42:16263 multimap& operator=(initializer_list<value_type> il);
264
265 // iterators:
Howard Hinnantb2e2a8f2011-06-04 15:22:34266 iterator begin() noexcept;
267 const_iterator begin() const noexcept;
268 iterator end() noexcept;
269 const_iterator end() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16270
Howard Hinnantb2e2a8f2011-06-04 15:22:34271 reverse_iterator rbegin() noexcept;
272 const_reverse_iterator rbegin() const noexcept;
273 reverse_iterator rend() noexcept;
274 const_reverse_iterator rend() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16275
Howard Hinnantb2e2a8f2011-06-04 15:22:34276 const_iterator cbegin() const noexcept;
277 const_iterator cend() const noexcept;
278 const_reverse_iterator crbegin() const noexcept;
279 const_reverse_iterator crend() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16280
281 // capacity:
Howard Hinnantb2e2a8f2011-06-04 15:22:34282 bool empty() const noexcept;
283 size_type size() const noexcept;
284 size_type max_size() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16285
286 // modifiers:
287 template <class... Args>
288 iterator emplace(Args&&... args);
289 template <class... Args>
290 iterator emplace_hint(const_iterator position, Args&&... args);
291 iterator insert(const value_type& v);
292 template <class P>
293 iterator insert(P&& p);
294 iterator insert(const_iterator position, const value_type& v);
295 template <class P>
296 iterator insert(const_iterator position, P&& p);
297 template <class InputIterator>
298 void insert(InputIterator first, InputIterator last);
299 void insert(initializer_list<value_type> il);
300
301 iterator erase(const_iterator position);
302 size_type erase(const key_type& k);
303 iterator erase(const_iterator first, const_iterator last);
Howard Hinnantb2e2a8f2011-06-04 15:22:34304 void clear() noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16305
Howard Hinnant7686add2011-06-04 14:31:57306 void swap(multimap& m)
307 noexcept(
308 __is_nothrow_swappable<key_compare>::value &&
309 (!allocator_type::propagate_on_container_swap::value ||
310 __is_nothrow_swappable<allocator_type>::value));
Howard Hinnantbc8d3f92010-05-11 19:42:16311
312 // observers:
Howard Hinnantb2e2a8f2011-06-04 15:22:34313 allocator_type get_allocator() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16314 key_compare key_comp() const;
315 value_compare value_comp() const;
316
317 // map operations:
318 iterator find(const key_type& k);
319 const_iterator find(const key_type& k) const;
320 size_type count(const key_type& k) const;
321 iterator lower_bound(const key_type& k);
322 const_iterator lower_bound(const key_type& k) const;
323 iterator upper_bound(const key_type& k);
324 const_iterator upper_bound(const key_type& k) const;
325 pair<iterator,iterator> equal_range(const key_type& k);
326 pair<const_iterator,const_iterator> equal_range(const key_type& k) const;
327};
328
329template <class Key, class T, class Compare, class Allocator>
330bool
331operator==(const multimap<Key, T, Compare, Allocator>& x,
332 const multimap<Key, T, Compare, Allocator>& y);
333
334template <class Key, class T, class Compare, class Allocator>
335bool
336operator< (const multimap<Key, T, Compare, Allocator>& x,
337 const multimap<Key, T, Compare, Allocator>& y);
338
339template <class Key, class T, class Compare, class Allocator>
340bool
341operator!=(const multimap<Key, T, Compare, Allocator>& x,
342 const multimap<Key, T, Compare, Allocator>& y);
343
344template <class Key, class T, class Compare, class Allocator>
345bool
346operator> (const multimap<Key, T, Compare, Allocator>& x,
347 const multimap<Key, T, Compare, Allocator>& y);
348
349template <class Key, class T, class Compare, class Allocator>
350bool
351operator>=(const multimap<Key, T, Compare, Allocator>& x,
352 const multimap<Key, T, Compare, Allocator>& y);
353
354template <class Key, class T, class Compare, class Allocator>
355bool
356operator<=(const multimap<Key, T, Compare, Allocator>& x,
357 const multimap<Key, T, Compare, Allocator>& y);
358
359// specialized algorithms:
360template <class Key, class T, class Compare, class Allocator>
361void
362swap(multimap<Key, T, Compare, Allocator>& x,
Howard Hinnant7686add2011-06-04 14:31:57363 multimap<Key, T, Compare, Allocator>& y)
364 noexcept(noexcept(x.swap(y)));
Howard Hinnantbc8d3f92010-05-11 19:42:16365
366} // std
367
368*/
369
370#include <__config>
371#include <__tree>
372#include <iterator>
373#include <memory>
374#include <utility>
375#include <functional>
376#include <initializer_list>
377
Howard Hinnant08e17472011-10-17 20:05:10378#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Howard Hinnantbc8d3f92010-05-11 19:42:16379#pragma GCC system_header
Howard Hinnant08e17472011-10-17 20:05:10380#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16381
382_LIBCPP_BEGIN_NAMESPACE_STD
383
384template <class _Key, class _Tp, class _Compare, bool = is_empty<_Compare>::value>
385class __map_value_compare
386 : private _Compare
387{
Howard Hinnant99968442011-11-29 18:15:50388 typedef pair<typename std::remove_const<_Key>::type, _Tp> _Pp;
Howard Hinnantbc8d3f92010-05-11 19:42:16389 typedef pair<const _Key, _Tp> _CP;
390public:
Howard Hinnant82894812010-09-22 16:48:34391 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7686add2011-06-04 14:31:57392 __map_value_compare()
393 _NOEXCEPT_(is_nothrow_default_constructible<_Compare>::value)
394 : _Compare() {}
Howard Hinnant82894812010-09-22 16:48:34395 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7686add2011-06-04 14:31:57396 __map_value_compare(_Compare c)
397 _NOEXCEPT_(is_nothrow_copy_constructible<_Compare>::value)
398 : _Compare(c) {}
Howard Hinnant82894812010-09-22 16:48:34399 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7686add2011-06-04 14:31:57400 const _Compare& key_comp() const _NOEXCEPT {return *this;}
Howard Hinnant82894812010-09-22 16:48:34401 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16402 bool operator()(const _CP& __x, const _CP& __y) const
403 {return static_cast<const _Compare&>(*this)(__x.first, __y.first);}
Howard Hinnant82894812010-09-22 16:48:34404 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant99968442011-11-29 18:15:50405 bool operator()(const _CP& __x, const _Pp& __y) const
Howard Hinnantbc8d3f92010-05-11 19:42:16406 {return static_cast<const _Compare&>(*this)(__x.first, __y.first);}
Howard Hinnant82894812010-09-22 16:48:34407 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16408 bool operator()(const _CP& __x, const _Key& __y) const
409 {return static_cast<const _Compare&>(*this)(__x.first, __y);}
Howard Hinnant82894812010-09-22 16:48:34410 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant99968442011-11-29 18:15:50411 bool operator()(const _Pp& __x, const _CP& __y) const
Howard Hinnantbc8d3f92010-05-11 19:42:16412 {return static_cast<const _Compare&>(*this)(__x.first, __y.first);}
Howard Hinnant82894812010-09-22 16:48:34413 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant99968442011-11-29 18:15:50414 bool operator()(const _Pp& __x, const _Pp& __y) const
Howard Hinnantbc8d3f92010-05-11 19:42:16415 {return static_cast<const _Compare&>(*this)(__x.first, __y.first);}
Howard Hinnant82894812010-09-22 16:48:34416 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant99968442011-11-29 18:15:50417 bool operator()(const _Pp& __x, const _Key& __y) const
Howard Hinnantbc8d3f92010-05-11 19:42:16418 {return static_cast<const _Compare&>(*this)(__x.first, __y);}
Howard Hinnant82894812010-09-22 16:48:34419 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16420 bool operator()(const _Key& __x, const _CP& __y) const
421 {return static_cast<const _Compare&>(*this)(__x, __y.first);}
Howard Hinnant82894812010-09-22 16:48:34422 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant99968442011-11-29 18:15:50423 bool operator()(const _Key& __x, const _Pp& __y) const
Howard Hinnantbc8d3f92010-05-11 19:42:16424 {return static_cast<const _Compare&>(*this)(__x, __y.first);}
Howard Hinnant82894812010-09-22 16:48:34425 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16426 bool operator()(const _Key& __x, const _Key& __y) const
427 {return static_cast<const _Compare&>(*this)(__x, __y);}
Howard Hinnantbc8d3f92010-05-11 19:42:16428};
429
430template <class _Key, class _Tp, class _Compare>
431class __map_value_compare<_Key, _Tp, _Compare, false>
432{
433 _Compare comp;
434
Howard Hinnant99968442011-11-29 18:15:50435 typedef pair<typename std::remove_const<_Key>::type, _Tp> _Pp;
Howard Hinnantbc8d3f92010-05-11 19:42:16436 typedef pair<const _Key, _Tp> _CP;
437
438public:
Howard Hinnant82894812010-09-22 16:48:34439 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7686add2011-06-04 14:31:57440 __map_value_compare()
441 _NOEXCEPT_(is_nothrow_default_constructible<_Compare>::value)
442 : comp() {}
Howard Hinnant82894812010-09-22 16:48:34443 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7686add2011-06-04 14:31:57444 __map_value_compare(_Compare c)
445 _NOEXCEPT_(is_nothrow_copy_constructible<_Compare>::value)
446 : comp(c) {}
Howard Hinnant82894812010-09-22 16:48:34447 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7686add2011-06-04 14:31:57448 const _Compare& key_comp() const _NOEXCEPT {return comp;}
Howard Hinnantbc8d3f92010-05-11 19:42:16449
Howard Hinnant82894812010-09-22 16:48:34450 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16451 bool operator()(const _CP& __x, const _CP& __y) const
452 {return comp(__x.first, __y.first);}
Howard Hinnant82894812010-09-22 16:48:34453 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant99968442011-11-29 18:15:50454 bool operator()(const _CP& __x, const _Pp& __y) const
Howard Hinnantbc8d3f92010-05-11 19:42:16455 {return comp(__x.first, __y.first);}
Howard Hinnant82894812010-09-22 16:48:34456 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16457 bool operator()(const _CP& __x, const _Key& __y) const
458 {return comp(__x.first, __y);}
Howard Hinnant82894812010-09-22 16:48:34459 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant99968442011-11-29 18:15:50460 bool operator()(const _Pp& __x, const _CP& __y) const
Howard Hinnantbc8d3f92010-05-11 19:42:16461 {return comp(__x.first, __y.first);}
Howard Hinnant82894812010-09-22 16:48:34462 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant99968442011-11-29 18:15:50463 bool operator()(const _Pp& __x, const _Pp& __y) const
Howard Hinnantbc8d3f92010-05-11 19:42:16464 {return comp(__x.first, __y.first);}
Howard Hinnant82894812010-09-22 16:48:34465 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant99968442011-11-29 18:15:50466 bool operator()(const _Pp& __x, const _Key& __y) const
Howard Hinnantbc8d3f92010-05-11 19:42:16467 {return comp(__x.first, __y);}
Howard Hinnant82894812010-09-22 16:48:34468 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16469 bool operator()(const _Key& __x, const _CP& __y) const
470 {return comp(__x, __y.first);}
Howard Hinnant82894812010-09-22 16:48:34471 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant99968442011-11-29 18:15:50472 bool operator()(const _Key& __x, const _Pp& __y) const
Howard Hinnantbc8d3f92010-05-11 19:42:16473 {return comp(__x, __y.first);}
Howard Hinnant82894812010-09-22 16:48:34474 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16475 bool operator()(const _Key& __x, const _Key& __y) const
476 {return comp(__x, __y);}
Howard Hinnantbc8d3f92010-05-11 19:42:16477};
478
479template <class _Allocator>
480class __map_node_destructor
481{
482 typedef _Allocator allocator_type;
483 typedef allocator_traits<allocator_type> __alloc_traits;
484 typedef typename __alloc_traits::value_type::value_type value_type;
485public:
486 typedef typename __alloc_traits::pointer pointer;
487private:
488 typedef typename value_type::first_type first_type;
489 typedef typename value_type::second_type second_type;
490
491 allocator_type& __na_;
492
493 __map_node_destructor& operator=(const __map_node_destructor&);
494
495public:
496 bool __first_constructed;
497 bool __second_constructed;
498
Howard Hinnant82894812010-09-22 16:48:34499 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7686add2011-06-04 14:31:57500 explicit __map_node_destructor(allocator_type& __na) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16501 : __na_(__na),
502 __first_constructed(false),
503 __second_constructed(false)
504 {}
505
Howard Hinnant73d21a42010-09-04 23:28:19506#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant82894812010-09-22 16:48:34507 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7686add2011-06-04 14:31:57508 __map_node_destructor(__tree_node_destructor<allocator_type>&& __x) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16509 : __na_(__x.__na_),
510 __first_constructed(__x.__value_constructed),
511 __second_constructed(__x.__value_constructed)
512 {
513 __x.__value_constructed = false;
514 }
Howard Hinnantbfd55302010-09-04 23:46:48515#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16516
Howard Hinnant82894812010-09-22 16:48:34517 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7686add2011-06-04 14:31:57518 void operator()(pointer __p) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16519 {
520 if (__second_constructed)
Howard Hinnant0949eed2011-06-30 21:18:19521 __alloc_traits::destroy(__na_, _VSTD::addressof(__p->__value_.second));
Howard Hinnantbc8d3f92010-05-11 19:42:16522 if (__first_constructed)
Howard Hinnant0949eed2011-06-30 21:18:19523 __alloc_traits::destroy(__na_, _VSTD::addressof(__p->__value_.first));
Howard Hinnantbc8d3f92010-05-11 19:42:16524 if (__p)
525 __alloc_traits::deallocate(__na_, __p, 1);
526 }
527};
528
Howard Hinnant2b1b2d42011-06-14 19:58:17529template <class _Key, class _Tp, class _Compare, class _Allocator>
530 class map;
531template <class _Key, class _Tp, class _Compare, class _Allocator>
532 class multimap;
533template <class _TreeIterator> class __map_const_iterator;
Howard Hinnantbc8d3f92010-05-11 19:42:16534
535template <class _TreeIterator>
Howard Hinnant82894812010-09-22 16:48:34536class _LIBCPP_VISIBLE __map_iterator
Howard Hinnantbc8d3f92010-05-11 19:42:16537{
538 _TreeIterator __i_;
539
540 typedef typename _TreeIterator::__pointer_traits __pointer_traits;
Howard Hinnantdf85e572011-02-27 18:02:02541 typedef const typename _TreeIterator::value_type::first_type __key_type;
542 typedef typename _TreeIterator::value_type::second_type __mapped_type;
Howard Hinnantbc8d3f92010-05-11 19:42:16543public:
544 typedef bidirectional_iterator_tag iterator_category;
Howard Hinnantdf85e572011-02-27 18:02:02545 typedef pair<__key_type, __mapped_type> value_type;
Howard Hinnantbc8d3f92010-05-11 19:42:16546 typedef typename _TreeIterator::difference_type difference_type;
547 typedef value_type& reference;
548 typedef typename __pointer_traits::template
549#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
550 rebind<value_type>
551#else
552 rebind<value_type>::other
553#endif
554 pointer;
555
Howard Hinnant82894812010-09-22 16:48:34556 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7686add2011-06-04 14:31:57557 __map_iterator() _NOEXCEPT {}
Howard Hinnantbc8d3f92010-05-11 19:42:16558
Howard Hinnant82894812010-09-22 16:48:34559 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7686add2011-06-04 14:31:57560 __map_iterator(_TreeIterator __i) _NOEXCEPT : __i_(__i) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16561
Howard Hinnant82894812010-09-22 16:48:34562 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16563 reference operator*() const {return *operator->();}
Howard Hinnant82894812010-09-22 16:48:34564 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16565 pointer operator->() const {return (pointer)__i_.operator->();}
566
Howard Hinnant82894812010-09-22 16:48:34567 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16568 __map_iterator& operator++() {++__i_; return *this;}
Howard Hinnant82894812010-09-22 16:48:34569 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16570 __map_iterator operator++(int)
571 {
572 __map_iterator __t(*this);
573 ++(*this);
574 return __t;
575 }
576
Howard Hinnant82894812010-09-22 16:48:34577 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16578 __map_iterator& operator--() {--__i_; return *this;}
Howard Hinnant82894812010-09-22 16:48:34579 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16580 __map_iterator operator--(int)
581 {
582 __map_iterator __t(*this);
583 --(*this);
584 return __t;
585 }
586
Howard Hinnant82894812010-09-22 16:48:34587 friend _LIBCPP_INLINE_VISIBILITY
588 bool operator==(const __map_iterator& __x, const __map_iterator& __y)
Howard Hinnantbc8d3f92010-05-11 19:42:16589 {return __x.__i_ == __y.__i_;}
Howard Hinnant82894812010-09-22 16:48:34590 friend
591 _LIBCPP_INLINE_VISIBILITY
592 bool operator!=(const __map_iterator& __x, const __map_iterator& __y)
Howard Hinnantbc8d3f92010-05-11 19:42:16593 {return __x.__i_ != __y.__i_;}
594
Howard Hinnant82894812010-09-22 16:48:34595 template <class, class, class, class> friend class _LIBCPP_VISIBLE map;
596 template <class, class, class, class> friend class _LIBCPP_VISIBLE multimap;
597 template <class> friend class _LIBCPP_VISIBLE __map_const_iterator;
Howard Hinnantbc8d3f92010-05-11 19:42:16598};
599
600template <class _TreeIterator>
Howard Hinnant82894812010-09-22 16:48:34601class _LIBCPP_VISIBLE __map_const_iterator
Howard Hinnantbc8d3f92010-05-11 19:42:16602{
603 _TreeIterator __i_;
604
605 typedef typename _TreeIterator::__pointer_traits __pointer_traits;
Howard Hinnantdf85e572011-02-27 18:02:02606 typedef const typename _TreeIterator::value_type::first_type __key_type;
607 typedef typename _TreeIterator::value_type::second_type __mapped_type;
Howard Hinnantbc8d3f92010-05-11 19:42:16608public:
609 typedef bidirectional_iterator_tag iterator_category;
Howard Hinnantdf85e572011-02-27 18:02:02610 typedef pair<__key_type, __mapped_type> value_type;
Howard Hinnantbc8d3f92010-05-11 19:42:16611 typedef typename _TreeIterator::difference_type difference_type;
612 typedef const value_type& reference;
613 typedef typename __pointer_traits::template
614#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
Howard Hinnant9dbeff92011-04-11 02:18:41615 rebind<const value_type>
Howard Hinnantbc8d3f92010-05-11 19:42:16616#else
Howard Hinnant9dbeff92011-04-11 02:18:41617 rebind<const value_type>::other
Howard Hinnantbc8d3f92010-05-11 19:42:16618#endif
619 pointer;
620
Howard Hinnant82894812010-09-22 16:48:34621 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7686add2011-06-04 14:31:57622 __map_const_iterator() _NOEXCEPT {}
Howard Hinnantbc8d3f92010-05-11 19:42:16623
Howard Hinnant82894812010-09-22 16:48:34624 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7686add2011-06-04 14:31:57625 __map_const_iterator(_TreeIterator __i) _NOEXCEPT : __i_(__i) {}
Howard Hinnant82894812010-09-22 16:48:34626 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16627 __map_const_iterator(
628 __map_iterator<typename _TreeIterator::__non_const_iterator> __i)
Howard Hinnant7686add2011-06-04 14:31:57629 _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16630 : __i_(__i.__i_) {}
631
Howard Hinnant82894812010-09-22 16:48:34632 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16633 reference operator*() const {return *operator->();}
Howard Hinnant82894812010-09-22 16:48:34634 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16635 pointer operator->() const {return (pointer)__i_.operator->();}
636
Howard Hinnant82894812010-09-22 16:48:34637 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16638 __map_const_iterator& operator++() {++__i_; return *this;}
Howard Hinnant82894812010-09-22 16:48:34639 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16640 __map_const_iterator operator++(int)
641 {
642 __map_const_iterator __t(*this);
643 ++(*this);
644 return __t;
645 }
646
Howard Hinnant82894812010-09-22 16:48:34647 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16648 __map_const_iterator& operator--() {--__i_; return *this;}
Howard Hinnant82894812010-09-22 16:48:34649 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16650 __map_const_iterator operator--(int)
651 {
652 __map_const_iterator __t(*this);
653 --(*this);
654 return __t;
655 }
656
Howard Hinnant82894812010-09-22 16:48:34657 friend _LIBCPP_INLINE_VISIBILITY
658 bool operator==(const __map_const_iterator& __x, const __map_const_iterator& __y)
Howard Hinnantbc8d3f92010-05-11 19:42:16659 {return __x.__i_ == __y.__i_;}
Howard Hinnant82894812010-09-22 16:48:34660 friend _LIBCPP_INLINE_VISIBILITY
661 bool operator!=(const __map_const_iterator& __x, const __map_const_iterator& __y)
Howard Hinnantbc8d3f92010-05-11 19:42:16662 {return __x.__i_ != __y.__i_;}
663
Howard Hinnant82894812010-09-22 16:48:34664 template <class, class, class, class> friend class _LIBCPP_VISIBLE map;
665 template <class, class, class, class> friend class _LIBCPP_VISIBLE multimap;
666 template <class, class, class> friend class _LIBCPP_VISIBLE __tree_const_iterator;
Howard Hinnantbc8d3f92010-05-11 19:42:16667};
668
669template <class _Key, class _Tp, class _Compare = less<_Key>,
670 class _Allocator = allocator<pair<const _Key, _Tp> > >
Howard Hinnant82894812010-09-22 16:48:34671class _LIBCPP_VISIBLE map
Howard Hinnantbc8d3f92010-05-11 19:42:16672{
673public:
674 // types:
675 typedef _Key key_type;
676 typedef _Tp mapped_type;
677 typedef pair<const key_type, mapped_type> value_type;
678 typedef _Compare key_compare;
679 typedef _Allocator allocator_type;
680 typedef value_type& reference;
681 typedef const value_type& const_reference;
682
Howard Hinnant82894812010-09-22 16:48:34683 class _LIBCPP_VISIBLE value_compare
Howard Hinnantbc8d3f92010-05-11 19:42:16684 : public binary_function<value_type, value_type, bool>
685 {
686 friend class map;
687 protected:
688 key_compare comp;
689
Howard Hinnant82894812010-09-22 16:48:34690 _LIBCPP_INLINE_VISIBILITY value_compare(key_compare c) : comp(c) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16691 public:
Howard Hinnant82894812010-09-22 16:48:34692 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16693 bool operator()(const value_type& __x, const value_type& __y) const
694 {return comp(__x.first, __y.first);}
695 };
696
697private:
698 typedef pair<key_type, mapped_type> __value_type;
699 typedef __map_value_compare<key_type, mapped_type, key_compare> __vc;
700 typedef typename allocator_traits<allocator_type>::template
701#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
702 rebind_alloc<__value_type>
703#else
704 rebind_alloc<__value_type>::other
705#endif
706 __allocator_type;
707 typedef __tree<__value_type, __vc, __allocator_type> __base;
708 typedef typename __base::__node_traits __node_traits;
709 typedef allocator_traits<allocator_type> __alloc_traits;
710
711 __base __tree_;
712
713public:
714 typedef typename __alloc_traits::pointer pointer;
715 typedef typename __alloc_traits::const_pointer const_pointer;
716 typedef typename __alloc_traits::size_type size_type;
717 typedef typename __alloc_traits::difference_type difference_type;
718 typedef __map_iterator<typename __base::iterator> iterator;
719 typedef __map_const_iterator<typename __base::const_iterator> const_iterator;
Howard Hinnant0949eed2011-06-30 21:18:19720 typedef _VSTD::reverse_iterator<iterator> reverse_iterator;
721 typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator;
Howard Hinnantbc8d3f92010-05-11 19:42:16722
Howard Hinnant82894812010-09-22 16:48:34723 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16724 explicit map(const key_compare& __comp = key_compare())
Howard Hinnant7686add2011-06-04 14:31:57725 _NOEXCEPT_(
726 is_nothrow_default_constructible<allocator_type>::value &&
727 is_nothrow_default_constructible<key_compare>::value &&
728 is_nothrow_copy_constructible<key_compare>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16729 : __tree_(__vc(__comp)) {}
730
Howard Hinnant82894812010-09-22 16:48:34731 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16732 explicit map(const key_compare& __comp, const allocator_type& __a)
733 : __tree_(__vc(__comp), __a) {}
734
735 template <class _InputIterator>
Howard Hinnant82894812010-09-22 16:48:34736 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16737 map(_InputIterator __f, _InputIterator __l,
738 const key_compare& __comp = key_compare())
739 : __tree_(__vc(__comp))
740 {
741 insert(__f, __l);
742 }
743
744 template <class _InputIterator>
Howard Hinnant82894812010-09-22 16:48:34745 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16746 map(_InputIterator __f, _InputIterator __l,
747 const key_compare& __comp, const allocator_type& __a)
748 : __tree_(__vc(__comp), __a)
749 {
750 insert(__f, __l);
751 }
752
Howard Hinnant82894812010-09-22 16:48:34753 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16754 map(const map& __m)
755 : __tree_(__m.__tree_)
756 {
757 insert(__m.begin(), __m.end());
758 }
759
Howard Hinnant61aa6012011-07-01 19:24:36760 _LIBCPP_INLINE_VISIBILITY
761 map& operator=(const map& __m)
762 {
763 __tree_ = __m.__tree_;
764 return *this;
765 }
766
Howard Hinnant73d21a42010-09-04 23:28:19767#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16768
Howard Hinnant82894812010-09-22 16:48:34769 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16770 map(map&& __m)
Howard Hinnant7686add2011-06-04 14:31:57771 _NOEXCEPT_(is_nothrow_move_constructible<__base>::value)
Howard Hinnant0949eed2011-06-30 21:18:19772 : __tree_(_VSTD::move(__m.__tree_))
Howard Hinnantbc8d3f92010-05-11 19:42:16773 {
774 }
775
776 map(map&& __m, const allocator_type& __a);
777
Howard Hinnant82894812010-09-22 16:48:34778 _LIBCPP_INLINE_VISIBILITY
Howard Hinnante3e32912011-08-12 21:56:02779 map& operator=(map&& __m)
780 _NOEXCEPT_(is_nothrow_move_assignable<__base>::value)
781 {
782 __tree_ = _VSTD::move(__m.__tree_);
783 return *this;
784 }
785
786#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
787
788#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
789
790 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16791 map(initializer_list<value_type> __il, const key_compare& __comp = key_compare())
792 : __tree_(__vc(__comp))
793 {
794 insert(__il.begin(), __il.end());
795 }
796
Howard Hinnant82894812010-09-22 16:48:34797 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16798 map(initializer_list<value_type> __il, const key_compare& __comp, const allocator_type& __a)
799 : __tree_(__vc(__comp), __a)
800 {
801 insert(__il.begin(), __il.end());
802 }
803
Howard Hinnant82894812010-09-22 16:48:34804 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16805 map& operator=(initializer_list<value_type> __il)
806 {
807 __tree_.__assign_unique(__il.begin(), __il.end());
808 return *this;
809 }
810
Howard Hinnante3e32912011-08-12 21:56:02811#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16812
Howard Hinnant82894812010-09-22 16:48:34813 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16814 explicit map(const allocator_type& __a)
815 : __tree_(__a)
816 {
817 }
818
Howard Hinnant82894812010-09-22 16:48:34819 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16820 map(const map& __m, const allocator_type& __a)
821 : __tree_(__m.__tree_.value_comp(), __a)
822 {
823 insert(__m.begin(), __m.end());
824 }
825
Howard Hinnant82894812010-09-22 16:48:34826 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7686add2011-06-04 14:31:57827 iterator begin() _NOEXCEPT {return __tree_.begin();}
Howard Hinnant82894812010-09-22 16:48:34828 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7686add2011-06-04 14:31:57829 const_iterator begin() const _NOEXCEPT {return __tree_.begin();}
Howard Hinnant82894812010-09-22 16:48:34830 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7686add2011-06-04 14:31:57831 iterator end() _NOEXCEPT {return __tree_.end();}
Howard Hinnant82894812010-09-22 16:48:34832 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7686add2011-06-04 14:31:57833 const_iterator end() const _NOEXCEPT {return __tree_.end();}
Howard Hinnantbc8d3f92010-05-11 19:42:16834
Howard Hinnant82894812010-09-22 16:48:34835 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7686add2011-06-04 14:31:57836 reverse_iterator rbegin() _NOEXCEPT {return reverse_iterator(end());}
Howard Hinnant82894812010-09-22 16:48:34837 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7686add2011-06-04 14:31:57838 const_reverse_iterator rbegin() const _NOEXCEPT
839 {return const_reverse_iterator(end());}
Howard Hinnant82894812010-09-22 16:48:34840 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7686add2011-06-04 14:31:57841 reverse_iterator rend() _NOEXCEPT
842 {return reverse_iterator(begin());}
Howard Hinnant82894812010-09-22 16:48:34843 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7686add2011-06-04 14:31:57844 const_reverse_iterator rend() const _NOEXCEPT
845 {return const_reverse_iterator(begin());}
Howard Hinnantbc8d3f92010-05-11 19:42:16846
Howard Hinnant82894812010-09-22 16:48:34847 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7686add2011-06-04 14:31:57848 const_iterator cbegin() const _NOEXCEPT {return begin();}
Howard Hinnant82894812010-09-22 16:48:34849 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7686add2011-06-04 14:31:57850 const_iterator cend() const _NOEXCEPT {return end();}
Howard Hinnant82894812010-09-22 16:48:34851 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7686add2011-06-04 14:31:57852 const_reverse_iterator crbegin() const _NOEXCEPT {return rbegin();}
Howard Hinnant82894812010-09-22 16:48:34853 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7686add2011-06-04 14:31:57854 const_reverse_iterator crend() const _NOEXCEPT {return rend();}
Howard Hinnantbc8d3f92010-05-11 19:42:16855
Howard Hinnant82894812010-09-22 16:48:34856 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7686add2011-06-04 14:31:57857 bool empty() const _NOEXCEPT {return __tree_.size() == 0;}
Howard Hinnant82894812010-09-22 16:48:34858 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7686add2011-06-04 14:31:57859 size_type size() const _NOEXCEPT {return __tree_.size();}
Howard Hinnant82894812010-09-22 16:48:34860 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7686add2011-06-04 14:31:57861 size_type max_size() const _NOEXCEPT {return __tree_.max_size();}
Howard Hinnantbc8d3f92010-05-11 19:42:16862
863 mapped_type& operator[](const key_type& __k);
Howard Hinnant73d21a42010-09-04 23:28:19864#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16865 mapped_type& operator[](key_type&& __k);
866#endif
867
868 mapped_type& at(const key_type& __k);
869 const mapped_type& at(const key_type& __k) const;
870
Howard Hinnant82894812010-09-22 16:48:34871 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7686add2011-06-04 14:31:57872 allocator_type get_allocator() const _NOEXCEPT {return __tree_.__alloc();}
Howard Hinnant82894812010-09-22 16:48:34873 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16874 key_compare key_comp() const {return __tree_.value_comp().key_comp();}
Howard Hinnant82894812010-09-22 16:48:34875 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16876 value_compare value_comp() const {return value_compare(__tree_.value_comp().key_comp());}
877
Howard Hinnant73d21a42010-09-04 23:28:19878#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16879
Howard Hinnant82894812010-09-22 16:48:34880 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16881 pair<iterator, bool>
882 emplace() {return __tree_.__emplace_unique();}
883
884 template <class _A0,
Howard Hinnant7604fea2011-06-19 21:45:00885 class = typename enable_if<is_constructible<value_type, _A0>::value>::type>
Howard Hinnant82894812010-09-22 16:48:34886 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16887 pair<iterator, bool>
888 emplace(_A0&& __a0)
Howard Hinnant0949eed2011-06-30 21:18:19889 {return __tree_.__emplace_unique(_VSTD::forward<_A0>(__a0));}
Howard Hinnantbc8d3f92010-05-11 19:42:16890
Howard Hinnant73d21a42010-09-04 23:28:19891#ifndef _LIBCPP_HAS_NO_VARIADICS
892
Howard Hinnantbc8d3f92010-05-11 19:42:16893 template <class _A0, class ..._Args,
Howard Hinnant7604fea2011-06-19 21:45:00894 class = typename enable_if<is_constructible<key_type, _A0>::value>::type>
Howard Hinnantbc8d3f92010-05-11 19:42:16895 pair<iterator, bool>
896 emplace(_A0&& __a0, _Args&& ...__args);
897
Howard Hinnant73d21a42010-09-04 23:28:19898#endif // _LIBCPP_HAS_NO_VARIADICS
899
Howard Hinnant82894812010-09-22 16:48:34900 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16901 iterator
902 emplace_hint(const_iterator __p)
903 {return __tree_.__emplace_hint_unique(__p.__i_);}
904
905 template <class _A0,
Howard Hinnant7604fea2011-06-19 21:45:00906 class = typename enable_if<is_constructible<value_type, _A0>::value>::type>
Howard Hinnant82894812010-09-22 16:48:34907 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16908 iterator
909 emplace_hint(const_iterator __p, _A0&& __a0)
Howard Hinnant0949eed2011-06-30 21:18:19910 {return __tree_.__emplace_hint_unique(__p.__i_, _VSTD::forward<_A0>(__a0));}
Howard Hinnantbc8d3f92010-05-11 19:42:16911
Howard Hinnant73d21a42010-09-04 23:28:19912#ifndef _LIBCPP_HAS_NO_VARIADICS
913
Howard Hinnantbc8d3f92010-05-11 19:42:16914 template <class _A0, class ..._Args,
Howard Hinnant7604fea2011-06-19 21:45:00915 class = typename enable_if<is_constructible<key_type, _A0>::value>::type>
Howard Hinnantbc8d3f92010-05-11 19:42:16916 iterator
917 emplace_hint(const_iterator __p, _A0&& __a0, _Args&& ...__args);
918
Howard Hinnant73d21a42010-09-04 23:28:19919#endif // _LIBCPP_HAS_NO_VARIADICS
920
Howard Hinnant99968442011-11-29 18:15:50921 template <class _Pp,
922 class = typename enable_if<is_constructible<value_type, _Pp>::value>::type>
Howard Hinnant82894812010-09-22 16:48:34923 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant99968442011-11-29 18:15:50924 pair<iterator, bool> insert(_Pp&& __p)
925 {return __tree_.__insert_unique(_VSTD::forward<_Pp>(__p));}
Howard Hinnantbc8d3f92010-05-11 19:42:16926
Howard Hinnant99968442011-11-29 18:15:50927 template <class _Pp,
928 class = typename enable_if<is_constructible<value_type, _Pp>::value>::type>
Howard Hinnant82894812010-09-22 16:48:34929 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant99968442011-11-29 18:15:50930 iterator insert(const_iterator __pos, _Pp&& __p)
931 {return __tree_.__insert_unique(__pos.__i_, _VSTD::forward<_Pp>(__p));}
Howard Hinnantbc8d3f92010-05-11 19:42:16932
Howard Hinnant73d21a42010-09-04 23:28:19933#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16934
Howard Hinnant82894812010-09-22 16:48:34935 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16936 pair<iterator, bool>
937 insert(const value_type& __v) {return __tree_.__insert_unique(__v);}
938
Howard Hinnant82894812010-09-22 16:48:34939 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16940 iterator
941 insert(const_iterator __p, const value_type& __v)
942 {return __tree_.__insert_unique(__p.__i_, __v);}
943
944 template <class _InputIterator>
Howard Hinnant82894812010-09-22 16:48:34945 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16946 void insert(_InputIterator __f, _InputIterator __l)
947 {
948 for (const_iterator __e = cend(); __f != __l; ++__f)
949 insert(__e.__i_, *__f);
950 }
951
Howard Hinnante3e32912011-08-12 21:56:02952#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
953
Howard Hinnant82894812010-09-22 16:48:34954 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16955 void insert(initializer_list<value_type> __il)
956 {insert(__il.begin(), __il.end());}
957
Howard Hinnante3e32912011-08-12 21:56:02958#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
959
Howard Hinnant82894812010-09-22 16:48:34960 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16961 iterator erase(const_iterator __p) {return __tree_.erase(__p.__i_);}
Howard Hinnant82894812010-09-22 16:48:34962 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16963 size_type erase(const key_type& __k)
964 {return __tree_.__erase_unique(__k);}
Howard Hinnant82894812010-09-22 16:48:34965 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16966 iterator erase(const_iterator __f, const_iterator __l)
967 {return __tree_.erase(__f.__i_, __l.__i_);}
Howard Hinnant82894812010-09-22 16:48:34968 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7686add2011-06-04 14:31:57969 void clear() _NOEXCEPT {__tree_.clear();}
Howard Hinnantbc8d3f92010-05-11 19:42:16970
Howard Hinnant82894812010-09-22 16:48:34971 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7686add2011-06-04 14:31:57972 void swap(map& __m)
973 _NOEXCEPT_(__is_nothrow_swappable<__base>::value)
974 {__tree_.swap(__m.__tree_);}
Howard Hinnantbc8d3f92010-05-11 19:42:16975
Howard Hinnant82894812010-09-22 16:48:34976 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16977 iterator find(const key_type& __k) {return __tree_.find(__k);}
Howard Hinnant82894812010-09-22 16:48:34978 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16979 const_iterator find(const key_type& __k) const {return __tree_.find(__k);}
Howard Hinnant82894812010-09-22 16:48:34980 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16981 size_type count(const key_type& __k) const
982 {return __tree_.__count_unique(__k);}
Howard Hinnant82894812010-09-22 16:48:34983 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16984 iterator lower_bound(const key_type& __k)
985 {return __tree_.lower_bound(__k);}
Howard Hinnant82894812010-09-22 16:48:34986 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16987 const_iterator lower_bound(const key_type& __k) const
988 {return __tree_.lower_bound(__k);}
Howard Hinnant82894812010-09-22 16:48:34989 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16990 iterator upper_bound(const key_type& __k)
991 {return __tree_.upper_bound(__k);}
Howard Hinnant82894812010-09-22 16:48:34992 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16993 const_iterator upper_bound(const key_type& __k) const
994 {return __tree_.upper_bound(__k);}
Howard Hinnant82894812010-09-22 16:48:34995 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16996 pair<iterator,iterator> equal_range(const key_type& __k)
997 {return __tree_.__equal_range_unique(__k);}
Howard Hinnant82894812010-09-22 16:48:34998 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16999 pair<const_iterator,const_iterator> equal_range(const key_type& __k) const
1000 {return __tree_.__equal_range_unique(__k);}
1001
1002private:
1003 typedef typename __base::__node __node;
1004 typedef typename __base::__node_allocator __node_allocator;
1005 typedef typename __base::__node_pointer __node_pointer;
1006 typedef typename __base::__node_const_pointer __node_const_pointer;
1007 typedef typename __base::__node_base_pointer __node_base_pointer;
1008 typedef typename __base::__node_base_const_pointer __node_base_const_pointer;
Howard Hinnant99968442011-11-29 18:15:501009 typedef __map_node_destructor<__node_allocator> _Dp;
1010 typedef unique_ptr<__node, _Dp> __node_holder;
Howard Hinnantbc8d3f92010-05-11 19:42:161011
Howard Hinnant73d21a42010-09-04 23:28:191012#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:161013 __node_holder __construct_node();
1014 template <class _A0,
Howard Hinnant7604fea2011-06-19 21:45:001015 class = typename enable_if<is_constructible<value_type, _A0>::value>::type>
Howard Hinnantbc8d3f92010-05-11 19:42:161016 __node_holder __construct_node(_A0&& __a0);
Howard Hinnant73d21a42010-09-04 23:28:191017#ifndef _LIBCPP_HAS_NO_VARIADICS
Howard Hinnantbc8d3f92010-05-11 19:42:161018 template <class _A0, class ..._Args,
Howard Hinnant7604fea2011-06-19 21:45:001019 class = typename enable_if<is_constructible<key_type, _A0>::value>::type>
Howard Hinnantbc8d3f92010-05-11 19:42:161020 __node_holder __construct_node(_A0&& __a0, _Args&& ...__args);
Howard Hinnant73d21a42010-09-04 23:28:191021#endif // _LIBCPP_HAS_NO_VARIADICS
1022#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:161023 __node_holder __construct_node(const key_type& __k);
1024#endif
1025
1026 __node_base_pointer&
1027 __find_equal_key(__node_base_pointer& __parent, const key_type& __k);
1028 __node_base_pointer&
1029 __find_equal_key(const_iterator __hint,
1030 __node_base_pointer& __parent, const key_type& __k);
1031 __node_base_const_pointer
1032 __find_equal_key(__node_base_const_pointer& __parent, const key_type& __k) const;
1033};
1034
1035// Find place to insert if __k doesn't exist
1036// Set __parent to parent of null leaf
1037// Return reference to null leaf
1038// If __k exists, set parent to node of __k and return reference to node of __k
1039template <class _Key, class _Tp, class _Compare, class _Allocator>
1040typename map<_Key, _Tp, _Compare, _Allocator>::__node_base_pointer&
1041map<_Key, _Tp, _Compare, _Allocator>::__find_equal_key(__node_base_pointer& __parent,
1042 const key_type& __k)
1043{
1044 __node_pointer __nd = __tree_.__root();
1045 if (__nd != nullptr)
1046 {
1047 while (true)
1048 {
1049 if (__tree_.value_comp().key_comp()(__k, __nd->__value_.first))
1050 {
1051 if (__nd->__left_ != nullptr)
1052 __nd = static_cast<__node_pointer>(__nd->__left_);
1053 else
1054 {
1055 __parent = __nd;
1056 return __parent->__left_;
1057 }
1058 }
1059 else if (__tree_.value_comp().key_comp()(__nd->__value_.first, __k))
1060 {
1061 if (__nd->__right_ != nullptr)
1062 __nd = static_cast<__node_pointer>(__nd->__right_);
1063 else
1064 {
1065 __parent = __nd;
1066 return __parent->__right_;
1067 }
1068 }
1069 else
1070 {
1071 __parent = __nd;
1072 return __parent;
1073 }
1074 }
1075 }
1076 __parent = __tree_.__end_node();
1077 return __parent->__left_;
1078}
1079
1080// Find place to insert if __k doesn't exist
1081// First check prior to __hint.
1082// Next check after __hint.
1083// Next do O(log N) search.
1084// Set __parent to parent of null leaf
1085// Return reference to null leaf
1086// If __k exists, set parent to node of __k and return reference to node of __k
1087template <class _Key, class _Tp, class _Compare, class _Allocator>
1088typename map<_Key, _Tp, _Compare, _Allocator>::__node_base_pointer&
1089map<_Key, _Tp, _Compare, _Allocator>::__find_equal_key(const_iterator __hint,
1090 __node_base_pointer& __parent,
1091 const key_type& __k)
1092{
1093 if (__hint == end() || __tree_.value_comp().key_comp()(__k, __hint->first)) // check before
1094 {
1095 // __k < *__hint
1096 const_iterator __prior = __hint;
1097 if (__prior == begin() || __tree_.value_comp().key_comp()((--__prior)->first, __k))
1098 {
1099 // *prev(__hint) < __k < *__hint
1100 if (__hint.__ptr_->__left_ == nullptr)
1101 {
1102 __parent = const_cast<__node_pointer&>(__hint.__ptr_);
1103 return __parent->__left_;
1104 }
1105 else
1106 {
1107 __parent = const_cast<__node_pointer&>(__prior.__ptr_);
1108 return __parent->__right_;
1109 }
1110 }
1111 // __k <= *prev(__hint)
1112 return __find_equal_key(__parent, __k);
1113 }
1114 else if (__tree_.value_comp().key_comp()(__hint->first, __k)) // check after
1115 {
1116 // *__hint < __k
Howard Hinnant0949eed2011-06-30 21:18:191117 const_iterator __next = _VSTD::next(__hint);
Howard Hinnantbc8d3f92010-05-11 19:42:161118 if (__next == end() || __tree_.value_comp().key_comp()(__k, __next->first))
1119 {
1120 // *__hint < __k < *next(__hint)
1121 if (__hint.__ptr_->__right_ == nullptr)
1122 {
1123 __parent = const_cast<__node_pointer&>(__hint.__ptr_);
1124 return __parent->__right_;
1125 }
1126 else
1127 {
1128 __parent = const_cast<__node_pointer&>(__next.__ptr_);
1129 return __parent->__left_;
1130 }
1131 }
1132 // *next(__hint) <= __k
1133 return __find_equal_key(__parent, __k);
1134 }
1135 // else __k == *__hint
1136 __parent = const_cast<__node_pointer&>(__hint.__ptr_);
1137 return __parent;
1138}
1139
1140// Find __k
1141// Set __parent to parent of null leaf and
1142// return reference to null leaf iv __k does not exist.
1143// If __k exists, set parent to node of __k and return reference to node of __k
1144template <class _Key, class _Tp, class _Compare, class _Allocator>
1145typename map<_Key, _Tp, _Compare, _Allocator>::__node_base_const_pointer
1146map<_Key, _Tp, _Compare, _Allocator>::__find_equal_key(__node_base_const_pointer& __parent,
1147 const key_type& __k) const
1148{
1149 __node_const_pointer __nd = __tree_.__root();
1150 if (__nd != nullptr)
1151 {
1152 while (true)
1153 {
1154 if (__tree_.value_comp().key_comp()(__k, __nd->__value_.first))
1155 {
1156 if (__nd->__left_ != nullptr)
1157 __nd = static_cast<__node_pointer>(__nd->__left_);
1158 else
1159 {
1160 __parent = __nd;
1161 return const_cast<const __node_base_const_pointer&>(__parent->__left_);
1162 }
1163 }
1164 else if (__tree_.value_comp().key_comp()(__nd->__value_.first, __k))
1165 {
1166 if (__nd->__right_ != nullptr)
1167 __nd = static_cast<__node_pointer>(__nd->__right_);
1168 else
1169 {
1170 __parent = __nd;
1171 return const_cast<const __node_base_const_pointer&>(__parent->__right_);
1172 }
1173 }
1174 else
1175 {
1176 __parent = __nd;
1177 return __parent;
1178 }
1179 }
1180 }
1181 __parent = __tree_.__end_node();
1182 return const_cast<const __node_base_const_pointer&>(__parent->__left_);
1183}
1184
Howard Hinnant73d21a42010-09-04 23:28:191185#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:161186
1187template <class _Key, class _Tp, class _Compare, class _Allocator>
1188map<_Key, _Tp, _Compare, _Allocator>::map(map&& __m, const allocator_type& __a)
Howard Hinnant0949eed2011-06-30 21:18:191189 : __tree_(_VSTD::move(__m.__tree_), __a)
Howard Hinnantbc8d3f92010-05-11 19:42:161190{
1191 if (__a != __m.get_allocator())
1192 {
1193 const_iterator __e = cend();
1194 while (!__m.empty())
1195 __tree_.__insert_unique(__e.__i_,
Howard Hinnant0949eed2011-06-30 21:18:191196 _VSTD::move(__m.__tree_.remove(__m.begin().__i_)->__value_));
Howard Hinnantbc8d3f92010-05-11 19:42:161197 }
1198}
1199
1200template <class _Key, class _Tp, class _Compare, class _Allocator>
1201typename map<_Key, _Tp, _Compare, _Allocator>::__node_holder
1202map<_Key, _Tp, _Compare, _Allocator>::__construct_node()
1203{
1204 __node_allocator& __na = __tree_.__node_alloc();
Howard Hinnant99968442011-11-29 18:15:501205 __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
Howard Hinnant0949eed2011-06-30 21:18:191206 __node_traits::construct(__na, _VSTD::addressof(__h->__value_.first));
Howard Hinnantbc8d3f92010-05-11 19:42:161207 __h.get_deleter().__first_constructed = true;
Howard Hinnant0949eed2011-06-30 21:18:191208 __node_traits::construct(__na, _VSTD::addressof(__h->__value_.second));
Howard Hinnantbc8d3f92010-05-11 19:42:161209 __h.get_deleter().__second_constructed = true;
1210 return __h;
1211}
1212
1213template <class _Key, class _Tp, class _Compare, class _Allocator>
1214template <class _A0,
1215 class>
1216typename map<_Key, _Tp, _Compare, _Allocator>::__node_holder
1217map<_Key, _Tp, _Compare, _Allocator>::__construct_node(_A0&& __a0)
1218{
1219 __node_allocator& __na = __tree_.__node_alloc();
Howard Hinnant99968442011-11-29 18:15:501220 __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
Howard Hinnant0949eed2011-06-30 21:18:191221 __node_traits::construct(__na, _VSTD::addressof(__h->__value_), _VSTD::forward<_A0>(__a0));
Howard Hinnantbc8d3f92010-05-11 19:42:161222 __h.get_deleter().__first_constructed = true;
1223 __h.get_deleter().__second_constructed = true;
1224 return __h;
1225}
1226
Howard Hinnant73d21a42010-09-04 23:28:191227#ifndef _LIBCPP_HAS_NO_VARIADICS
1228
Howard Hinnantbc8d3f92010-05-11 19:42:161229template <class _Key, class _Tp, class _Compare, class _Allocator>
1230template <class _A0, class ..._Args,
1231 class>
1232typename map<_Key, _Tp, _Compare, _Allocator>::__node_holder
1233map<_Key, _Tp, _Compare, _Allocator>::__construct_node(_A0&& __a0, _Args&& ...__args)
1234{
1235 __node_allocator& __na = __tree_.__node_alloc();
Howard Hinnant99968442011-11-29 18:15:501236 __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
Howard Hinnant0949eed2011-06-30 21:18:191237 __node_traits::construct(__na, _VSTD::addressof(__h->__value_.first), _VSTD::forward<_A0>(__a0));
Howard Hinnantbc8d3f92010-05-11 19:42:161238 __h.get_deleter().__first_constructed = true;
Howard Hinnant0949eed2011-06-30 21:18:191239 __node_traits::construct(__na, _VSTD::addressof(__h->__value_.second), _VSTD::forward<_Args>(__args)...);
Howard Hinnantbc8d3f92010-05-11 19:42:161240 __h.get_deleter().__second_constructed = true;
1241 return __h;
1242}
1243
Howard Hinnant73d21a42010-09-04 23:28:191244#endif // _LIBCPP_HAS_NO_VARIADICS
1245
1246#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:161247
1248template <class _Key, class _Tp, class _Compare, class _Allocator>
1249typename map<_Key, _Tp, _Compare, _Allocator>::__node_holder
1250map<_Key, _Tp, _Compare, _Allocator>::__construct_node(const key_type& __k)
1251{
1252 __node_allocator& __na = __tree_.__node_alloc();
Howard Hinnant99968442011-11-29 18:15:501253 __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
Howard Hinnant0949eed2011-06-30 21:18:191254 __node_traits::construct(__na, _VSTD::addressof(__h->__value_.first), __k);
Howard Hinnantbc8d3f92010-05-11 19:42:161255 __h.get_deleter().__first_constructed = true;
Howard Hinnant0949eed2011-06-30 21:18:191256 __node_traits::construct(__na, _VSTD::addressof(__h->__value_.second));
Howard Hinnantbc8d3f92010-05-11 19:42:161257 __h.get_deleter().__second_constructed = true;
Howard Hinnant0949eed2011-06-30 21:18:191258 return _VSTD::move(__h);
Howard Hinnantbc8d3f92010-05-11 19:42:161259}
1260
Howard Hinnant73d21a42010-09-04 23:28:191261#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:161262
1263template <class _Key, class _Tp, class _Compare, class _Allocator>
1264_Tp&
1265map<_Key, _Tp, _Compare, _Allocator>::operator[](const key_type& __k)
1266{
1267 __node_base_pointer __parent;
1268 __node_base_pointer& __child = __find_equal_key(__parent, __k);
1269 __node_pointer __r = static_cast<__node_pointer>(__child);
1270 if (__child == nullptr)
1271 {
1272 __node_holder __h = __construct_node(__k);
1273 __tree_.__insert_node_at(__parent, __child, __h.get());
1274 __r = __h.release();
1275 }
1276 return __r->__value_.second;
1277}
1278
Howard Hinnant73d21a42010-09-04 23:28:191279#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:161280
1281template <class _Key, class _Tp, class _Compare, class _Allocator>
1282_Tp&
1283map<_Key, _Tp, _Compare, _Allocator>::operator[](key_type&& __k)
1284{
1285 __node_base_pointer __parent;
1286 __node_base_pointer& __child = __find_equal_key(__parent, __k);
1287 __node_pointer __r = static_cast<__node_pointer>(__child);
1288 if (__child == nullptr)
1289 {
Howard Hinnant0949eed2011-06-30 21:18:191290 __node_holder __h = __construct_node(_VSTD::move(__k));
Howard Hinnantbc8d3f92010-05-11 19:42:161291 __tree_.__insert_node_at(__parent, __child, __h.get());
1292 __r = __h.release();
1293 }
1294 return __r->__value_.second;
1295}
1296
Howard Hinnant73d21a42010-09-04 23:28:191297#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:161298
1299template <class _Key, class _Tp, class _Compare, class _Allocator>
1300_Tp&
1301map<_Key, _Tp, _Compare, _Allocator>::at(const key_type& __k)
1302{
1303 __node_base_pointer __parent;
1304 __node_base_pointer& __child = __find_equal_key(__parent, __k);
Howard Hinnantd4444702010-08-11 17:04:311305#ifndef _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:161306 if (__child == nullptr)
1307 throw out_of_range("map::at: key not found");
Howard Hinnant324bb032010-08-22 00:02:431308#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:161309 return static_cast<__node_pointer>(__child)->__value_.second;
1310}
1311
1312template <class _Key, class _Tp, class _Compare, class _Allocator>
1313const _Tp&
1314map<_Key, _Tp, _Compare, _Allocator>::at(const key_type& __k) const
1315{
1316 __node_base_const_pointer __parent;
1317 __node_base_const_pointer __child = __find_equal_key(__parent, __k);
Howard Hinnantd4444702010-08-11 17:04:311318#ifndef _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:161319 if (__child == nullptr)
1320 throw out_of_range("map::at: key not found");
Howard Hinnant324bb032010-08-22 00:02:431321#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:161322 return static_cast<__node_const_pointer>(__child)->__value_.second;
1323}
1324
Howard Hinnant73d21a42010-09-04 23:28:191325#if !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
Howard Hinnantbc8d3f92010-05-11 19:42:161326
1327template <class _Key, class _Tp, class _Compare, class _Allocator>
1328template <class _A0, class ..._Args,
Howard Hinnant7604fea2011-06-19 21:45:001329 class //= typename enable_if<is_constructible<_Key, _A0>::value>::type
Howard Hinnantbc8d3f92010-05-11 19:42:161330 >
1331pair<typename map<_Key, _Tp, _Compare, _Allocator>::iterator, bool>
1332map<_Key, _Tp, _Compare, _Allocator>::emplace(_A0&& __a0, _Args&& ...__args)
1333{
Howard Hinnant0949eed2011-06-30 21:18:191334 __node_holder __h = __construct_node(_VSTD::forward<_A0>(__a0),
1335 _VSTD::forward<_Args>(__args)...);
Howard Hinnantbc8d3f92010-05-11 19:42:161336 pair<iterator, bool> __r = __tree_.__node_insert_unique(__h.get());
1337 if (__r.second)
1338 __h.release();
1339 return __r;
1340}
1341
1342template <class _Key, class _Tp, class _Compare, class _Allocator>
1343template <class _A0, class ..._Args,
Howard Hinnant7604fea2011-06-19 21:45:001344 class //= typename enable_if<is_constructible<_Key, _A0>::value>::type
Howard Hinnantbc8d3f92010-05-11 19:42:161345 >
1346typename map<_Key, _Tp, _Compare, _Allocator>::iterator
1347map<_Key, _Tp, _Compare, _Allocator>::emplace_hint(const_iterator __p,
1348 _A0&& __a0, _Args&& ...__args)
1349{
Howard Hinnant0949eed2011-06-30 21:18:191350 __node_holder __h = __construct_node(_VSTD::forward<_A0>(__a0),
1351 _VSTD::forward<_Args>(__args)...);
Howard Hinnantbc8d3f92010-05-11 19:42:161352 iterator __r = __tree_.__node_insert_unique(__p.__i_, __h.get());
1353 if (__r.__i_.__ptr_ == __h.get())
1354 __h.release();
1355 return __r;
1356}
1357
Howard Hinnant73d21a42010-09-04 23:28:191358#endif // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
Howard Hinnantbc8d3f92010-05-11 19:42:161359
1360template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant82894812010-09-22 16:48:341361inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161362bool
1363operator==(const map<_Key, _Tp, _Compare, _Allocator>& __x,
1364 const map<_Key, _Tp, _Compare, _Allocator>& __y)
1365{
Howard Hinnant0949eed2011-06-30 21:18:191366 return __x.size() == __y.size() && _VSTD::equal(__x.begin(), __x.end(), __y.begin());
Howard Hinnantbc8d3f92010-05-11 19:42:161367}
1368
1369template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant82894812010-09-22 16:48:341370inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161371bool
1372operator< (const map<_Key, _Tp, _Compare, _Allocator>& __x,
1373 const map<_Key, _Tp, _Compare, _Allocator>& __y)
1374{
Howard Hinnant0949eed2011-06-30 21:18:191375 return _VSTD::lexicographical_compare(__x.begin(), __x.end(), __y.begin(), __y.end());
Howard Hinnantbc8d3f92010-05-11 19:42:161376}
1377
1378template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant82894812010-09-22 16:48:341379inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161380bool
1381operator!=(const map<_Key, _Tp, _Compare, _Allocator>& __x,
1382 const map<_Key, _Tp, _Compare, _Allocator>& __y)
1383{
1384 return !(__x == __y);
1385}
1386
1387template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant82894812010-09-22 16:48:341388inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161389bool
1390operator> (const map<_Key, _Tp, _Compare, _Allocator>& __x,
1391 const map<_Key, _Tp, _Compare, _Allocator>& __y)
1392{
1393 return __y < __x;
1394}
1395
1396template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant82894812010-09-22 16:48:341397inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161398bool
1399operator>=(const map<_Key, _Tp, _Compare, _Allocator>& __x,
1400 const map<_Key, _Tp, _Compare, _Allocator>& __y)
1401{
1402 return !(__x < __y);
1403}
1404
1405template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant82894812010-09-22 16:48:341406inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161407bool
1408operator<=(const map<_Key, _Tp, _Compare, _Allocator>& __x,
1409 const map<_Key, _Tp, _Compare, _Allocator>& __y)
1410{
1411 return !(__y < __x);
1412}
1413
1414template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant82894812010-09-22 16:48:341415inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161416void
1417swap(map<_Key, _Tp, _Compare, _Allocator>& __x,
1418 map<_Key, _Tp, _Compare, _Allocator>& __y)
Howard Hinnant7686add2011-06-04 14:31:571419 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
Howard Hinnantbc8d3f92010-05-11 19:42:161420{
1421 __x.swap(__y);
1422}
1423
1424template <class _Key, class _Tp, class _Compare = less<_Key>,
1425 class _Allocator = allocator<pair<const _Key, _Tp> > >
Howard Hinnant82894812010-09-22 16:48:341426class _LIBCPP_VISIBLE multimap
Howard Hinnantbc8d3f92010-05-11 19:42:161427{
1428public:
1429 // types:
1430 typedef _Key key_type;
1431 typedef _Tp mapped_type;
1432 typedef pair<const key_type, mapped_type> value_type;
1433 typedef _Compare key_compare;
1434 typedef _Allocator allocator_type;
1435 typedef value_type& reference;
1436 typedef const value_type& const_reference;
1437
Howard Hinnant82894812010-09-22 16:48:341438 class _LIBCPP_VISIBLE value_compare
Howard Hinnantbc8d3f92010-05-11 19:42:161439 : public binary_function<value_type, value_type, bool>
1440 {
1441 friend class multimap;
1442 protected:
1443 key_compare comp;
1444
Howard Hinnant82894812010-09-22 16:48:341445 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161446 value_compare(key_compare c) : comp(c) {}
1447 public:
Howard Hinnant82894812010-09-22 16:48:341448 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161449 bool operator()(const value_type& __x, const value_type& __y) const
1450 {return comp(__x.first, __y.first);}
1451 };
1452
1453private:
1454 typedef pair<key_type, mapped_type> __value_type;
1455 typedef __map_value_compare<key_type, mapped_type, key_compare> __vc;
1456 typedef typename allocator_traits<allocator_type>::template
1457#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
1458 rebind_alloc<__value_type>
1459#else
1460 rebind_alloc<__value_type>::other
1461#endif
1462 __allocator_type;
1463 typedef __tree<__value_type, __vc, __allocator_type> __base;
1464 typedef typename __base::__node_traits __node_traits;
1465 typedef allocator_traits<allocator_type> __alloc_traits;
1466
1467 __base __tree_;
1468
1469public:
1470 typedef typename __alloc_traits::pointer pointer;
1471 typedef typename __alloc_traits::const_pointer const_pointer;
1472 typedef typename __alloc_traits::size_type size_type;
1473 typedef typename __alloc_traits::difference_type difference_type;
1474 typedef __map_iterator<typename __base::iterator> iterator;
1475 typedef __map_const_iterator<typename __base::const_iterator> const_iterator;
Howard Hinnant0949eed2011-06-30 21:18:191476 typedef _VSTD::reverse_iterator<iterator> reverse_iterator;
1477 typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator;
Howard Hinnantbc8d3f92010-05-11 19:42:161478
Howard Hinnant82894812010-09-22 16:48:341479 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161480 explicit multimap(const key_compare& __comp = key_compare())
Howard Hinnant7686add2011-06-04 14:31:571481 _NOEXCEPT_(
1482 is_nothrow_default_constructible<allocator_type>::value &&
1483 is_nothrow_default_constructible<key_compare>::value &&
1484 is_nothrow_copy_constructible<key_compare>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:161485 : __tree_(__vc(__comp)) {}
1486
Howard Hinnant82894812010-09-22 16:48:341487 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161488 explicit multimap(const key_compare& __comp, const allocator_type& __a)
1489 : __tree_(__vc(__comp), __a) {}
1490
1491 template <class _InputIterator>
Howard Hinnant82894812010-09-22 16:48:341492 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161493 multimap(_InputIterator __f, _InputIterator __l,
1494 const key_compare& __comp = key_compare())
1495 : __tree_(__vc(__comp))
1496 {
1497 insert(__f, __l);
1498 }
1499
1500 template <class _InputIterator>
Howard Hinnant82894812010-09-22 16:48:341501 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161502 multimap(_InputIterator __f, _InputIterator __l,
1503 const key_compare& __comp, const allocator_type& __a)
1504 : __tree_(__vc(__comp), __a)
1505 {
1506 insert(__f, __l);
1507 }
1508
Howard Hinnant82894812010-09-22 16:48:341509 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161510 multimap(const multimap& __m)
1511 : __tree_(__m.__tree_.value_comp(),
1512 __alloc_traits::select_on_container_copy_construction(__m.__tree_.__alloc()))
1513 {
1514 insert(__m.begin(), __m.end());
1515 }
1516
Howard Hinnant61aa6012011-07-01 19:24:361517 _LIBCPP_INLINE_VISIBILITY
1518 multimap& operator=(const multimap& __m)
1519 {
1520 __tree_ = __m.__tree_;
1521 return *this;
1522 }
1523
Howard Hinnant73d21a42010-09-04 23:28:191524#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:161525
Howard Hinnant82894812010-09-22 16:48:341526 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161527 multimap(multimap&& __m)
Howard Hinnant7686add2011-06-04 14:31:571528 _NOEXCEPT_(is_nothrow_move_constructible<__base>::value)
Howard Hinnant0949eed2011-06-30 21:18:191529 : __tree_(_VSTD::move(__m.__tree_))
Howard Hinnantbc8d3f92010-05-11 19:42:161530 {
1531 }
1532
1533 multimap(multimap&& __m, const allocator_type& __a);
1534
Howard Hinnant82894812010-09-22 16:48:341535 _LIBCPP_INLINE_VISIBILITY
Howard Hinnante3e32912011-08-12 21:56:021536 multimap& operator=(multimap&& __m)
1537 _NOEXCEPT_(is_nothrow_move_assignable<__base>::value)
1538 {
1539 __tree_ = _VSTD::move(__m.__tree_);
1540 return *this;
1541 }
1542
1543#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
1544
1545#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1546
1547 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161548 multimap(initializer_list<value_type> __il, const key_compare& __comp = key_compare())
1549 : __tree_(__vc(__comp))
1550 {
1551 insert(__il.begin(), __il.end());
1552 }
1553
Howard Hinnant82894812010-09-22 16:48:341554 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161555 multimap(initializer_list<value_type> __il, const key_compare& __comp, const allocator_type& __a)
1556 : __tree_(__vc(__comp), __a)
1557 {
1558 insert(__il.begin(), __il.end());
1559 }
1560
Howard Hinnant82894812010-09-22 16:48:341561 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161562 multimap& operator=(initializer_list<value_type> __il)
1563 {
1564 __tree_.__assign_multi(__il.begin(), __il.end());
1565 return *this;
1566 }
Howard Hinnante3e32912011-08-12 21:56:021567
1568#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:161569
Howard Hinnant82894812010-09-22 16:48:341570 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161571 explicit multimap(const allocator_type& __a)
1572 : __tree_(__a)
1573 {
1574 }
1575
Howard Hinnant82894812010-09-22 16:48:341576 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161577 multimap(const multimap& __m, const allocator_type& __a)
1578 : __tree_(__m.__tree_.value_comp(), __a)
1579 {
1580 insert(__m.begin(), __m.end());
1581 }
1582
Howard Hinnant82894812010-09-22 16:48:341583 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7686add2011-06-04 14:31:571584 iterator begin() _NOEXCEPT {return __tree_.begin();}
Howard Hinnant82894812010-09-22 16:48:341585 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7686add2011-06-04 14:31:571586 const_iterator begin() const _NOEXCEPT {return __tree_.begin();}
Howard Hinnant82894812010-09-22 16:48:341587 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7686add2011-06-04 14:31:571588 iterator end() _NOEXCEPT {return __tree_.end();}
Howard Hinnant82894812010-09-22 16:48:341589 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7686add2011-06-04 14:31:571590 const_iterator end() const _NOEXCEPT {return __tree_.end();}
Howard Hinnantbc8d3f92010-05-11 19:42:161591
Howard Hinnant82894812010-09-22 16:48:341592 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7686add2011-06-04 14:31:571593 reverse_iterator rbegin() _NOEXCEPT {return reverse_iterator(end());}
Howard Hinnant82894812010-09-22 16:48:341594 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7686add2011-06-04 14:31:571595 const_reverse_iterator rbegin() const _NOEXCEPT
1596 {return const_reverse_iterator(end());}
Howard Hinnant82894812010-09-22 16:48:341597 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7686add2011-06-04 14:31:571598 reverse_iterator rend() _NOEXCEPT {return reverse_iterator(begin());}
Howard Hinnant82894812010-09-22 16:48:341599 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7686add2011-06-04 14:31:571600 const_reverse_iterator rend() const _NOEXCEPT
1601 {return const_reverse_iterator(begin());}
Howard Hinnantbc8d3f92010-05-11 19:42:161602
Howard Hinnant82894812010-09-22 16:48:341603 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7686add2011-06-04 14:31:571604 const_iterator cbegin() const _NOEXCEPT {return begin();}
Howard Hinnant82894812010-09-22 16:48:341605 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7686add2011-06-04 14:31:571606 const_iterator cend() const _NOEXCEPT {return end();}
Howard Hinnant82894812010-09-22 16:48:341607 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7686add2011-06-04 14:31:571608 const_reverse_iterator crbegin() const _NOEXCEPT {return rbegin();}
Howard Hinnant82894812010-09-22 16:48:341609 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7686add2011-06-04 14:31:571610 const_reverse_iterator crend() const _NOEXCEPT {return rend();}
Howard Hinnantbc8d3f92010-05-11 19:42:161611
Howard Hinnant82894812010-09-22 16:48:341612 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7686add2011-06-04 14:31:571613 bool empty() const _NOEXCEPT {return __tree_.size() == 0;}
Howard Hinnant82894812010-09-22 16:48:341614 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7686add2011-06-04 14:31:571615 size_type size() const _NOEXCEPT {return __tree_.size();}
Howard Hinnant82894812010-09-22 16:48:341616 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7686add2011-06-04 14:31:571617 size_type max_size() const _NOEXCEPT {return __tree_.max_size();}
Howard Hinnantbc8d3f92010-05-11 19:42:161618
Howard Hinnant82894812010-09-22 16:48:341619 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7686add2011-06-04 14:31:571620 allocator_type get_allocator() const _NOEXCEPT {return __tree_.__alloc();}
Howard Hinnant82894812010-09-22 16:48:341621 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7686add2011-06-04 14:31:571622 key_compare key_comp() const {return __tree_.value_comp().key_comp();}
Howard Hinnant82894812010-09-22 16:48:341623 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7686add2011-06-04 14:31:571624 value_compare value_comp() const
1625 {return value_compare(__tree_.value_comp().key_comp());}
Howard Hinnantbc8d3f92010-05-11 19:42:161626
Howard Hinnant73d21a42010-09-04 23:28:191627#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:161628
Howard Hinnant82894812010-09-22 16:48:341629 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161630 iterator emplace() {return __tree_.__emplace_multi();}
1631
1632 template <class _A0,
Howard Hinnant7604fea2011-06-19 21:45:001633 class = typename enable_if<is_constructible<value_type, _A0>::value>::type>
Howard Hinnant82894812010-09-22 16:48:341634 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161635 iterator
1636 emplace(_A0&& __a0)
Howard Hinnant0949eed2011-06-30 21:18:191637 {return __tree_.__emplace_multi(_VSTD::forward<_A0>(__a0));}
Howard Hinnantbc8d3f92010-05-11 19:42:161638
Howard Hinnant73d21a42010-09-04 23:28:191639#ifndef _LIBCPP_HAS_NO_VARIADICS
1640
Howard Hinnantbc8d3f92010-05-11 19:42:161641 template <class _A0, class ..._Args,
Howard Hinnant7604fea2011-06-19 21:45:001642 class = typename enable_if<is_constructible<key_type, _A0>::value>::type>
Howard Hinnantbc8d3f92010-05-11 19:42:161643 iterator
1644 emplace(_A0&& __a0, _Args&& ...__args);
1645
Howard Hinnant73d21a42010-09-04 23:28:191646#endif // _LIBCPP_HAS_NO_VARIADICS
1647
Howard Hinnant82894812010-09-22 16:48:341648 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161649 iterator emplace_hint(const_iterator __p)
1650 {return __tree_.__emplace_hint_multi(__p.__i_);}
1651
1652 template <class _A0,
Howard Hinnant7604fea2011-06-19 21:45:001653 class = typename enable_if<is_constructible<value_type, _A0>::value>::type>
Howard Hinnant82894812010-09-22 16:48:341654 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161655 iterator
1656 emplace_hint(const_iterator __p, _A0&& __a0)
Howard Hinnant0949eed2011-06-30 21:18:191657 {return __tree_.__emplace_hint_multi(__p.__i_, _VSTD::forward<_A0>(__a0));}
Howard Hinnantbc8d3f92010-05-11 19:42:161658
Howard Hinnant73d21a42010-09-04 23:28:191659#ifndef _LIBCPP_HAS_NO_VARIADICS
1660
Howard Hinnantbc8d3f92010-05-11 19:42:161661 template <class _A0, class ..._Args,
Howard Hinnant7604fea2011-06-19 21:45:001662 class = typename enable_if<is_constructible<key_type, _A0>::value>::type>
Howard Hinnantbc8d3f92010-05-11 19:42:161663 iterator
1664 emplace_hint(const_iterator __p, _A0&& __a0, _Args&& ...__args);
1665
Howard Hinnant73d21a42010-09-04 23:28:191666#endif // _LIBCPP_HAS_NO_VARIADICS
1667
Howard Hinnant99968442011-11-29 18:15:501668 template <class _Pp,
1669 class = typename enable_if<is_constructible<value_type, _Pp>::value>::type>
Howard Hinnant82894812010-09-22 16:48:341670 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant99968442011-11-29 18:15:501671 iterator insert(_Pp&& __p)
1672 {return __tree_.__insert_multi(_VSTD::forward<_Pp>(__p));}
Howard Hinnantbc8d3f92010-05-11 19:42:161673
Howard Hinnant99968442011-11-29 18:15:501674 template <class _Pp,
1675 class = typename enable_if<is_constructible<value_type, _Pp>::value>::type>
Howard Hinnant82894812010-09-22 16:48:341676 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant99968442011-11-29 18:15:501677 iterator insert(const_iterator __pos, _Pp&& __p)
1678 {return __tree_.__insert_multi(__pos.__i_, _VSTD::forward<_Pp>(__p));}
Howard Hinnantbc8d3f92010-05-11 19:42:161679
Howard Hinnant73d21a42010-09-04 23:28:191680#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:161681
Howard Hinnant82894812010-09-22 16:48:341682 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161683 iterator insert(const value_type& __v) {return __tree_.__insert_multi(__v);}
1684
Howard Hinnant82894812010-09-22 16:48:341685 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161686 iterator insert(const_iterator __p, const value_type& __v)
1687 {return __tree_.__insert_multi(__p.__i_, __v);}
1688
1689 template <class _InputIterator>
Howard Hinnant82894812010-09-22 16:48:341690 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161691 void insert(_InputIterator __f, _InputIterator __l)
1692 {
1693 for (const_iterator __e = cend(); __f != __l; ++__f)
1694 __tree_.__insert_multi(__e.__i_, *__f);
1695 }
1696
Howard Hinnante3e32912011-08-12 21:56:021697#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1698
Howard Hinnant82894812010-09-22 16:48:341699 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161700 void insert(initializer_list<value_type> __il)
1701 {insert(__il.begin(), __il.end());}
1702
Howard Hinnante3e32912011-08-12 21:56:021703#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1704
Howard Hinnant82894812010-09-22 16:48:341705 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161706 iterator erase(const_iterator __p) {return __tree_.erase(__p.__i_);}
Howard Hinnant82894812010-09-22 16:48:341707 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161708 size_type erase(const key_type& __k) {return __tree_.__erase_multi(__k);}
Howard Hinnant82894812010-09-22 16:48:341709 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161710 iterator erase(const_iterator __f, const_iterator __l)
1711 {return __tree_.erase(__f.__i_, __l.__i_);}
Howard Hinnant82894812010-09-22 16:48:341712 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161713 void clear() {__tree_.clear();}
1714
Howard Hinnant82894812010-09-22 16:48:341715 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7686add2011-06-04 14:31:571716 void swap(multimap& __m)
1717 _NOEXCEPT_(__is_nothrow_swappable<__base>::value)
1718 {__tree_.swap(__m.__tree_);}
Howard Hinnantbc8d3f92010-05-11 19:42:161719
Howard Hinnant82894812010-09-22 16:48:341720 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161721 iterator find(const key_type& __k) {return __tree_.find(__k);}
Howard Hinnant82894812010-09-22 16:48:341722 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161723 const_iterator find(const key_type& __k) const {return __tree_.find(__k);}
Howard Hinnant82894812010-09-22 16:48:341724 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161725 size_type count(const key_type& __k) const
1726 {return __tree_.__count_multi(__k);}
Howard Hinnant82894812010-09-22 16:48:341727 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161728 iterator lower_bound(const key_type& __k)
1729 {return __tree_.lower_bound(__k);}
Howard Hinnant82894812010-09-22 16:48:341730 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161731 const_iterator lower_bound(const key_type& __k) const
1732 {return __tree_.lower_bound(__k);}
Howard Hinnant82894812010-09-22 16:48:341733 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161734 iterator upper_bound(const key_type& __k)
1735 {return __tree_.upper_bound(__k);}
Howard Hinnant82894812010-09-22 16:48:341736 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161737 const_iterator upper_bound(const key_type& __k) const
1738 {return __tree_.upper_bound(__k);}
Howard Hinnant82894812010-09-22 16:48:341739 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161740 pair<iterator,iterator> equal_range(const key_type& __k)
1741 {return __tree_.__equal_range_multi(__k);}
Howard Hinnant82894812010-09-22 16:48:341742 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161743 pair<const_iterator,const_iterator> equal_range(const key_type& __k) const
1744 {return __tree_.__equal_range_multi(__k);}
1745
1746private:
1747 typedef typename __base::__node __node;
1748 typedef typename __base::__node_allocator __node_allocator;
1749 typedef typename __base::__node_pointer __node_pointer;
1750 typedef typename __base::__node_const_pointer __node_const_pointer;
Howard Hinnant99968442011-11-29 18:15:501751 typedef __map_node_destructor<__node_allocator> _Dp;
1752 typedef unique_ptr<__node, _Dp> __node_holder;
Howard Hinnantbc8d3f92010-05-11 19:42:161753
Howard Hinnant73d21a42010-09-04 23:28:191754#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:161755 __node_holder __construct_node();
1756 template <class _A0,
Howard Hinnant7604fea2011-06-19 21:45:001757 class = typename enable_if<is_constructible<value_type, _A0>::value>::type>
Howard Hinnantbc8d3f92010-05-11 19:42:161758 __node_holder __construct_node(_A0&& __a0);
Howard Hinnant73d21a42010-09-04 23:28:191759#ifndef _LIBCPP_HAS_NO_VARIADICS
Howard Hinnantbc8d3f92010-05-11 19:42:161760 template <class _A0, class ..._Args,
Howard Hinnant7604fea2011-06-19 21:45:001761 class = typename enable_if<is_constructible<key_type, _A0>::value>::type>
Howard Hinnantbc8d3f92010-05-11 19:42:161762 __node_holder __construct_node(_A0&& __a0, _Args&& ...__args);
Howard Hinnant73d21a42010-09-04 23:28:191763#endif // _LIBCPP_HAS_NO_VARIADICS
1764#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:161765};
1766
Howard Hinnant73d21a42010-09-04 23:28:191767#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:161768
1769template <class _Key, class _Tp, class _Compare, class _Allocator>
1770multimap<_Key, _Tp, _Compare, _Allocator>::multimap(multimap&& __m, const allocator_type& __a)
Howard Hinnant0949eed2011-06-30 21:18:191771 : __tree_(_VSTD::move(__m.__tree_), __a)
Howard Hinnantbc8d3f92010-05-11 19:42:161772{
1773 if (__a != __m.get_allocator())
1774 {
1775 const_iterator __e = cend();
1776 while (!__m.empty())
1777 __tree_.__insert_multi(__e.__i_,
Howard Hinnant0949eed2011-06-30 21:18:191778 _VSTD::move(__m.__tree_.remove(__m.begin().__i_)->__value_));
Howard Hinnantbc8d3f92010-05-11 19:42:161779 }
1780}
1781
1782template <class _Key, class _Tp, class _Compare, class _Allocator>
1783typename multimap<_Key, _Tp, _Compare, _Allocator>::__node_holder
1784multimap<_Key, _Tp, _Compare, _Allocator>::__construct_node()
1785{
1786 __node_allocator& __na = __tree_.__node_alloc();
Howard Hinnant99968442011-11-29 18:15:501787 __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
Howard Hinnant0949eed2011-06-30 21:18:191788 __node_traits::construct(__na, _VSTD::addressof(__h->__value_.first));
Howard Hinnantbc8d3f92010-05-11 19:42:161789 __h.get_deleter().__first_constructed = true;
Howard Hinnant0949eed2011-06-30 21:18:191790 __node_traits::construct(__na, _VSTD::addressof(__h->__value_.second));
Howard Hinnantbc8d3f92010-05-11 19:42:161791 __h.get_deleter().__second_constructed = true;
1792 return __h;
1793}
1794
1795template <class _Key, class _Tp, class _Compare, class _Allocator>
1796template <class _A0,
Howard Hinnant7604fea2011-06-19 21:45:001797 class // = typename enable_if<is_constructible<value_type, _A0>::value>::type
Howard Hinnantbc8d3f92010-05-11 19:42:161798 >
1799typename multimap<_Key, _Tp, _Compare, _Allocator>::__node_holder
1800multimap<_Key, _Tp, _Compare, _Allocator>::__construct_node(_A0&& __a0)
1801{
1802 __node_allocator& __na = __tree_.__node_alloc();
Howard Hinnant99968442011-11-29 18:15:501803 __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
Howard Hinnant0949eed2011-06-30 21:18:191804 __node_traits::construct(__na, _VSTD::addressof(__h->__value_), _VSTD::forward<_A0>(__a0));
Howard Hinnantbc8d3f92010-05-11 19:42:161805 __h.get_deleter().__first_constructed = true;
1806 __h.get_deleter().__second_constructed = true;
1807 return __h;
1808}
1809
Howard Hinnant73d21a42010-09-04 23:28:191810#ifndef _LIBCPP_HAS_NO_VARIADICS
1811
Howard Hinnantbc8d3f92010-05-11 19:42:161812template <class _Key, class _Tp, class _Compare, class _Allocator>
1813template <class _A0, class ..._Args,
Howard Hinnant7604fea2011-06-19 21:45:001814 class // = typename enable_if<is_constructible<key_type, _A0>::value>::type
Howard Hinnantbc8d3f92010-05-11 19:42:161815 >
1816typename multimap<_Key, _Tp, _Compare, _Allocator>::__node_holder
1817multimap<_Key, _Tp, _Compare, _Allocator>::__construct_node(_A0&& __a0, _Args&& ...__args)
1818{
1819 __node_allocator& __na = __tree_.__node_alloc();
Howard Hinnant99968442011-11-29 18:15:501820 __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
Howard Hinnant0949eed2011-06-30 21:18:191821 __node_traits::construct(__na, _VSTD::addressof(__h->__value_.first), _VSTD::forward<_A0>(__a0));
Howard Hinnantbc8d3f92010-05-11 19:42:161822 __h.get_deleter().__first_constructed = true;
Howard Hinnant0949eed2011-06-30 21:18:191823 __node_traits::construct(__na, _VSTD::addressof(__h->__value_.second), _VSTD::forward<_Args>(__args)...);
Howard Hinnantbc8d3f92010-05-11 19:42:161824 __h.get_deleter().__second_constructed = true;
1825 return __h;
1826}
1827
Howard Hinnant73d21a42010-09-04 23:28:191828#endif // _LIBCPP_HAS_NO_VARIADICS
1829#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:161830
Howard Hinnant73d21a42010-09-04 23:28:191831#if !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
Howard Hinnantbc8d3f92010-05-11 19:42:161832
1833template <class _Key, class _Tp, class _Compare, class _Allocator>
1834template <class _A0, class ..._Args,
Howard Hinnant7604fea2011-06-19 21:45:001835 class //= typename enable_if<is_constructible<_Key, _A0>::value>::type
Howard Hinnantbc8d3f92010-05-11 19:42:161836 >
1837typename multimap<_Key, _Tp, _Compare, _Allocator>::iterator
1838multimap<_Key, _Tp, _Compare, _Allocator>::emplace(_A0&& __a0, _Args&& ...__args)
1839{
Howard Hinnant0949eed2011-06-30 21:18:191840 __node_holder __h = __construct_node(_VSTD::forward<_A0>(__a0),
1841 _VSTD::forward<_Args>(__args)...);
Howard Hinnantbc8d3f92010-05-11 19:42:161842 iterator __r = __tree_.__node_insert_multi(__h.get());
1843 __h.release();
1844 return __r;
1845}
1846
1847template <class _Key, class _Tp, class _Compare, class _Allocator>
1848template <class _A0, class ..._Args,
Howard Hinnant7604fea2011-06-19 21:45:001849 class //= typename enable_if<is_constructible<_Key, _A0>::value>::type
Howard Hinnantbc8d3f92010-05-11 19:42:161850 >
1851typename multimap<_Key, _Tp, _Compare, _Allocator>::iterator
1852multimap<_Key, _Tp, _Compare, _Allocator>::emplace_hint(const_iterator __p,
1853 _A0&& __a0,
1854 _Args&& ...__args)
1855{
Howard Hinnant0949eed2011-06-30 21:18:191856 __node_holder __h = __construct_node(_VSTD::forward<_A0>(__a0),
1857 _VSTD::forward<_Args>(__args)...);
Howard Hinnantbc8d3f92010-05-11 19:42:161858 iterator __r = __tree_.__node_insert_multi(__p.__i_, __h.get());
1859 __h.release();
1860 return __r;
1861}
1862
Howard Hinnant73d21a42010-09-04 23:28:191863#endif // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
Howard Hinnantbc8d3f92010-05-11 19:42:161864
1865template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant82894812010-09-22 16:48:341866inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161867bool
1868operator==(const multimap<_Key, _Tp, _Compare, _Allocator>& __x,
1869 const multimap<_Key, _Tp, _Compare, _Allocator>& __y)
1870{
Howard Hinnant0949eed2011-06-30 21:18:191871 return __x.size() == __y.size() && _VSTD::equal(__x.begin(), __x.end(), __y.begin());
Howard Hinnantbc8d3f92010-05-11 19:42:161872}
1873
1874template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant82894812010-09-22 16:48:341875inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161876bool
1877operator< (const multimap<_Key, _Tp, _Compare, _Allocator>& __x,
1878 const multimap<_Key, _Tp, _Compare, _Allocator>& __y)
1879{
Howard Hinnant0949eed2011-06-30 21:18:191880 return _VSTD::lexicographical_compare(__x.begin(), __x.end(), __y.begin(), __y.end());
Howard Hinnantbc8d3f92010-05-11 19:42:161881}
1882
1883template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant82894812010-09-22 16:48:341884inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161885bool
1886operator!=(const multimap<_Key, _Tp, _Compare, _Allocator>& __x,
1887 const multimap<_Key, _Tp, _Compare, _Allocator>& __y)
1888{
1889 return !(__x == __y);
1890}
1891
1892template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant82894812010-09-22 16:48:341893inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161894bool
1895operator> (const multimap<_Key, _Tp, _Compare, _Allocator>& __x,
1896 const multimap<_Key, _Tp, _Compare, _Allocator>& __y)
1897{
1898 return __y < __x;
1899}
1900
1901template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant82894812010-09-22 16:48:341902inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161903bool
1904operator>=(const multimap<_Key, _Tp, _Compare, _Allocator>& __x,
1905 const multimap<_Key, _Tp, _Compare, _Allocator>& __y)
1906{
1907 return !(__x < __y);
1908}
1909
1910template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant82894812010-09-22 16:48:341911inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161912bool
1913operator<=(const multimap<_Key, _Tp, _Compare, _Allocator>& __x,
1914 const multimap<_Key, _Tp, _Compare, _Allocator>& __y)
1915{
1916 return !(__y < __x);
1917}
1918
1919template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant82894812010-09-22 16:48:341920inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161921void
1922swap(multimap<_Key, _Tp, _Compare, _Allocator>& __x,
1923 multimap<_Key, _Tp, _Compare, _Allocator>& __y)
Howard Hinnant7686add2011-06-04 14:31:571924 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
Howard Hinnantbc8d3f92010-05-11 19:42:161925{
1926 __x.swap(__y);
1927}
1928
1929_LIBCPP_END_NAMESPACE_STD
1930
1931#endif // _LIBCPP_MAP