blob: 3a077587c025d47da9a881bb8da4457da4329801 [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
Howard Hinnant9b128e02013-07-05 18:06:00384template <class _Key, class _CP, class _Compare, bool = is_empty<_Compare>::value
Howard Hinnantd4cf2152011-12-11 20:31:33385#if __has_feature(is_final)
386 && !__is_final(_Compare)
387#endif
388 >
Howard Hinnantbc8d3f92010-05-11 19:42:16389class __map_value_compare
390 : private _Compare
391{
Howard Hinnantbc8d3f92010-05-11 19:42:16392public:
Howard Hinnant82894812010-09-22 16:48:34393 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7686add2011-06-04 14:31:57394 __map_value_compare()
395 _NOEXCEPT_(is_nothrow_default_constructible<_Compare>::value)
396 : _Compare() {}
Howard Hinnant82894812010-09-22 16:48:34397 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7686add2011-06-04 14:31:57398 __map_value_compare(_Compare c)
399 _NOEXCEPT_(is_nothrow_copy_constructible<_Compare>::value)
400 : _Compare(c) {}
Howard Hinnant82894812010-09-22 16:48:34401 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7686add2011-06-04 14:31:57402 const _Compare& key_comp() const _NOEXCEPT {return *this;}
Howard Hinnant82894812010-09-22 16:48:34403 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16404 bool operator()(const _CP& __x, const _CP& __y) const
Howard Hinnant9b128e02013-07-05 18:06:00405 {return static_cast<const _Compare&>(*this)(__x.__cc.first, __y.__cc.first);}
Howard Hinnant82894812010-09-22 16:48:34406 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16407 bool operator()(const _CP& __x, const _Key& __y) const
Howard Hinnant9b128e02013-07-05 18:06:00408 {return static_cast<const _Compare&>(*this)(__x.__cc.first, __y);}
Howard Hinnant82894812010-09-22 16:48:34409 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16410 bool operator()(const _Key& __x, const _CP& __y) const
Howard Hinnant9b128e02013-07-05 18:06:00411 {return static_cast<const _Compare&>(*this)(__x, __y.__cc.first);}
Howard Hinnantbc8d3f92010-05-11 19:42:16412};
413
Howard Hinnant9b128e02013-07-05 18:06:00414template <class _Key, class _CP, class _Compare>
415class __map_value_compare<_Key, _CP, _Compare, false>
Howard Hinnantbc8d3f92010-05-11 19:42:16416{
417 _Compare comp;
418
Howard Hinnantbc8d3f92010-05-11 19:42:16419public:
Howard Hinnant82894812010-09-22 16:48:34420 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7686add2011-06-04 14:31:57421 __map_value_compare()
422 _NOEXCEPT_(is_nothrow_default_constructible<_Compare>::value)
423 : comp() {}
Howard Hinnant82894812010-09-22 16:48:34424 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7686add2011-06-04 14:31:57425 __map_value_compare(_Compare c)
426 _NOEXCEPT_(is_nothrow_copy_constructible<_Compare>::value)
427 : comp(c) {}
Howard Hinnant82894812010-09-22 16:48:34428 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7686add2011-06-04 14:31:57429 const _Compare& key_comp() const _NOEXCEPT {return comp;}
Howard Hinnantbc8d3f92010-05-11 19:42:16430
Howard Hinnant82894812010-09-22 16:48:34431 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16432 bool operator()(const _CP& __x, const _CP& __y) const
Howard Hinnant9b128e02013-07-05 18:06:00433 {return comp(__x.__cc.first, __y.__cc.first);}
Howard Hinnant82894812010-09-22 16:48:34434 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16435 bool operator()(const _CP& __x, const _Key& __y) const
Howard Hinnant9b128e02013-07-05 18:06:00436 {return comp(__x.__cc.first, __y);}
Howard Hinnant82894812010-09-22 16:48:34437 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16438 bool operator()(const _Key& __x, const _CP& __y) const
Howard Hinnant9b128e02013-07-05 18:06:00439 {return comp(__x, __y.__cc.first);}
Howard Hinnantbc8d3f92010-05-11 19:42:16440};
441
442template <class _Allocator>
443class __map_node_destructor
444{
445 typedef _Allocator allocator_type;
446 typedef allocator_traits<allocator_type> __alloc_traits;
447 typedef typename __alloc_traits::value_type::value_type value_type;
448public:
449 typedef typename __alloc_traits::pointer pointer;
450private:
Howard Hinnant70342b92013-06-19 21:29:40451 typedef typename value_type::value_type::first_type first_type;
452 typedef typename value_type::value_type::second_type second_type;
Howard Hinnantbc8d3f92010-05-11 19:42:16453
454 allocator_type& __na_;
455
456 __map_node_destructor& operator=(const __map_node_destructor&);
457
458public:
459 bool __first_constructed;
460 bool __second_constructed;
461
Howard Hinnant82894812010-09-22 16:48:34462 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7686add2011-06-04 14:31:57463 explicit __map_node_destructor(allocator_type& __na) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16464 : __na_(__na),
465 __first_constructed(false),
466 __second_constructed(false)
467 {}
468
Howard Hinnant73d21a42010-09-04 23:28:19469#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant82894812010-09-22 16:48:34470 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7686add2011-06-04 14:31:57471 __map_node_destructor(__tree_node_destructor<allocator_type>&& __x) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16472 : __na_(__x.__na_),
473 __first_constructed(__x.__value_constructed),
474 __second_constructed(__x.__value_constructed)
475 {
476 __x.__value_constructed = false;
477 }
Howard Hinnantbfd55302010-09-04 23:46:48478#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16479
Howard Hinnant82894812010-09-22 16:48:34480 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7686add2011-06-04 14:31:57481 void operator()(pointer __p) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16482 {
483 if (__second_constructed)
Howard Hinnant70342b92013-06-19 21:29:40484 __alloc_traits::destroy(__na_, _VSTD::addressof(__p->__value_.__cc.second));
Howard Hinnantbc8d3f92010-05-11 19:42:16485 if (__first_constructed)
Howard Hinnant70342b92013-06-19 21:29:40486 __alloc_traits::destroy(__na_, _VSTD::addressof(__p->__value_.__cc.first));
Howard Hinnantbc8d3f92010-05-11 19:42:16487 if (__p)
488 __alloc_traits::deallocate(__na_, __p, 1);
489 }
490};
491
Howard Hinnant2b1b2d42011-06-14 19:58:17492template <class _Key, class _Tp, class _Compare, class _Allocator>
493 class map;
494template <class _Key, class _Tp, class _Compare, class _Allocator>
495 class multimap;
496template <class _TreeIterator> class __map_const_iterator;
Howard Hinnantbc8d3f92010-05-11 19:42:16497
498template <class _TreeIterator>
Howard Hinnant0f678bd2013-08-12 18:38:34499class _LIBCPP_TYPE_VIS_ONLY __map_iterator
Howard Hinnantbc8d3f92010-05-11 19:42:16500{
501 _TreeIterator __i_;
502
503 typedef typename _TreeIterator::__pointer_traits __pointer_traits;
Howard Hinnant70342b92013-06-19 21:29:40504 typedef const typename _TreeIterator::value_type::value_type::first_type __key_type;
505 typedef typename _TreeIterator::value_type::value_type::second_type __mapped_type;
Howard Hinnantbc8d3f92010-05-11 19:42:16506public:
507 typedef bidirectional_iterator_tag iterator_category;
Howard Hinnantdf85e572011-02-27 18:02:02508 typedef pair<__key_type, __mapped_type> value_type;
Howard Hinnantbc8d3f92010-05-11 19:42:16509 typedef typename _TreeIterator::difference_type difference_type;
510 typedef value_type& reference;
511 typedef typename __pointer_traits::template
512#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
513 rebind<value_type>
514#else
515 rebind<value_type>::other
516#endif
517 pointer;
518
Howard Hinnant82894812010-09-22 16:48:34519 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7686add2011-06-04 14:31:57520 __map_iterator() _NOEXCEPT {}
Howard Hinnantbc8d3f92010-05-11 19:42:16521
Howard Hinnant82894812010-09-22 16:48:34522 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7686add2011-06-04 14:31:57523 __map_iterator(_TreeIterator __i) _NOEXCEPT : __i_(__i) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16524
Howard Hinnant82894812010-09-22 16:48:34525 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant70342b92013-06-19 21:29:40526 reference operator*() const {return __i_->__cc;}
Howard Hinnant82894812010-09-22 16:48:34527 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant70342b92013-06-19 21:29:40528 pointer operator->() const {return pointer_traits<pointer>::pointer_to(__i_->__cc);}
Howard Hinnantbc8d3f92010-05-11 19:42:16529
Howard Hinnant82894812010-09-22 16:48:34530 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16531 __map_iterator& operator++() {++__i_; return *this;}
Howard Hinnant82894812010-09-22 16:48:34532 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16533 __map_iterator operator++(int)
534 {
535 __map_iterator __t(*this);
536 ++(*this);
537 return __t;
538 }
539
Howard Hinnant82894812010-09-22 16:48:34540 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16541 __map_iterator& operator--() {--__i_; return *this;}
Howard Hinnant82894812010-09-22 16:48:34542 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16543 __map_iterator operator--(int)
544 {
545 __map_iterator __t(*this);
546 --(*this);
547 return __t;
548 }
549
Howard Hinnant82894812010-09-22 16:48:34550 friend _LIBCPP_INLINE_VISIBILITY
551 bool operator==(const __map_iterator& __x, const __map_iterator& __y)
Howard Hinnantbc8d3f92010-05-11 19:42:16552 {return __x.__i_ == __y.__i_;}
Howard Hinnant82894812010-09-22 16:48:34553 friend
554 _LIBCPP_INLINE_VISIBILITY
555 bool operator!=(const __map_iterator& __x, const __map_iterator& __y)
Howard Hinnantbc8d3f92010-05-11 19:42:16556 {return __x.__i_ != __y.__i_;}
557
Howard Hinnant0f678bd2013-08-12 18:38:34558 template <class, class, class, class> friend class _LIBCPP_TYPE_VIS_ONLY map;
559 template <class, class, class, class> friend class _LIBCPP_TYPE_VIS_ONLY multimap;
560 template <class> friend class _LIBCPP_TYPE_VIS_ONLY __map_const_iterator;
Howard Hinnantbc8d3f92010-05-11 19:42:16561};
562
563template <class _TreeIterator>
Howard Hinnant0f678bd2013-08-12 18:38:34564class _LIBCPP_TYPE_VIS_ONLY __map_const_iterator
Howard Hinnantbc8d3f92010-05-11 19:42:16565{
566 _TreeIterator __i_;
567
568 typedef typename _TreeIterator::__pointer_traits __pointer_traits;
Howard Hinnant70342b92013-06-19 21:29:40569 typedef const typename _TreeIterator::value_type::value_type::first_type __key_type;
570 typedef typename _TreeIterator::value_type::value_type::second_type __mapped_type;
Howard Hinnantbc8d3f92010-05-11 19:42:16571public:
572 typedef bidirectional_iterator_tag iterator_category;
Howard Hinnantdf85e572011-02-27 18:02:02573 typedef pair<__key_type, __mapped_type> value_type;
Howard Hinnantbc8d3f92010-05-11 19:42:16574 typedef typename _TreeIterator::difference_type difference_type;
575 typedef const value_type& reference;
576 typedef typename __pointer_traits::template
577#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
Howard Hinnant9dbeff92011-04-11 02:18:41578 rebind<const value_type>
Howard Hinnantbc8d3f92010-05-11 19:42:16579#else
Howard Hinnant9dbeff92011-04-11 02:18:41580 rebind<const value_type>::other
Howard Hinnantbc8d3f92010-05-11 19:42:16581#endif
582 pointer;
583
Howard Hinnant82894812010-09-22 16:48:34584 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7686add2011-06-04 14:31:57585 __map_const_iterator() _NOEXCEPT {}
Howard Hinnantbc8d3f92010-05-11 19:42:16586
Howard Hinnant82894812010-09-22 16:48:34587 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7686add2011-06-04 14:31:57588 __map_const_iterator(_TreeIterator __i) _NOEXCEPT : __i_(__i) {}
Howard Hinnant82894812010-09-22 16:48:34589 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16590 __map_const_iterator(
591 __map_iterator<typename _TreeIterator::__non_const_iterator> __i)
Howard Hinnant7686add2011-06-04 14:31:57592 _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16593 : __i_(__i.__i_) {}
594
Howard Hinnant82894812010-09-22 16:48:34595 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant70342b92013-06-19 21:29:40596 reference operator*() const {return __i_->__cc;}
Howard Hinnant82894812010-09-22 16:48:34597 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant70342b92013-06-19 21:29:40598 pointer operator->() const {return pointer_traits<pointer>::pointer_to(__i_->__cc);}
Howard Hinnantbc8d3f92010-05-11 19:42:16599
Howard Hinnant82894812010-09-22 16:48:34600 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16601 __map_const_iterator& operator++() {++__i_; return *this;}
Howard Hinnant82894812010-09-22 16:48:34602 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16603 __map_const_iterator operator++(int)
604 {
605 __map_const_iterator __t(*this);
606 ++(*this);
607 return __t;
608 }
609
Howard Hinnant82894812010-09-22 16:48:34610 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16611 __map_const_iterator& operator--() {--__i_; return *this;}
Howard Hinnant82894812010-09-22 16:48:34612 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16613 __map_const_iterator operator--(int)
614 {
615 __map_const_iterator __t(*this);
616 --(*this);
617 return __t;
618 }
619
Howard Hinnant82894812010-09-22 16:48:34620 friend _LIBCPP_INLINE_VISIBILITY
621 bool operator==(const __map_const_iterator& __x, const __map_const_iterator& __y)
Howard Hinnantbc8d3f92010-05-11 19:42:16622 {return __x.__i_ == __y.__i_;}
Howard Hinnant82894812010-09-22 16:48:34623 friend _LIBCPP_INLINE_VISIBILITY
624 bool operator!=(const __map_const_iterator& __x, const __map_const_iterator& __y)
Howard Hinnantbc8d3f92010-05-11 19:42:16625 {return __x.__i_ != __y.__i_;}
626
Howard Hinnant0f678bd2013-08-12 18:38:34627 template <class, class, class, class> friend class _LIBCPP_TYPE_VIS_ONLY map;
628 template <class, class, class, class> friend class _LIBCPP_TYPE_VIS_ONLY multimap;
629 template <class, class, class> friend class _LIBCPP_TYPE_VIS_ONLY __tree_const_iterator;
Howard Hinnantbc8d3f92010-05-11 19:42:16630};
631
632template <class _Key, class _Tp, class _Compare = less<_Key>,
633 class _Allocator = allocator<pair<const _Key, _Tp> > >
Howard Hinnant0f678bd2013-08-12 18:38:34634class _LIBCPP_TYPE_VIS_ONLY map
Howard Hinnantbc8d3f92010-05-11 19:42:16635{
636public:
637 // types:
638 typedef _Key key_type;
639 typedef _Tp mapped_type;
640 typedef pair<const key_type, mapped_type> value_type;
Howard Hinnant70342b92013-06-19 21:29:40641 typedef pair<key_type, mapped_type> __nc_value_type;
Howard Hinnantbc8d3f92010-05-11 19:42:16642 typedef _Compare key_compare;
643 typedef _Allocator allocator_type;
644 typedef value_type& reference;
645 typedef const value_type& const_reference;
646
Howard Hinnant0f678bd2013-08-12 18:38:34647 class _LIBCPP_TYPE_VIS_ONLY value_compare
Howard Hinnantbc8d3f92010-05-11 19:42:16648 : public binary_function<value_type, value_type, bool>
649 {
650 friend class map;
651 protected:
652 key_compare comp;
653
Howard Hinnant82894812010-09-22 16:48:34654 _LIBCPP_INLINE_VISIBILITY value_compare(key_compare c) : comp(c) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16655 public:
Howard Hinnant82894812010-09-22 16:48:34656 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16657 bool operator()(const value_type& __x, const value_type& __y) const
658 {return comp(__x.first, __y.first);}
659 };
660
661private:
Howard Hinnant70342b92013-06-19 21:29:40662
663#if __cplusplus >= 201103L
664 union __value_type
665 {
666 typedef typename map::value_type value_type;
667 typedef typename map::__nc_value_type __nc_value_type;
668 value_type __cc;
669 __nc_value_type __nc;
670
671 template <class ..._Args>
672 __value_type(_Args&& ...__args)
673 : __cc(std::forward<_Args>(__args)...) {}
674
675 __value_type(const __value_type& __v)
676 : __cc(std::move(__v.__cc)) {}
677
678 __value_type(__value_type&& __v)
679 : __nc(std::move(__v.__nc)) {}
680
681 __value_type& operator=(const __value_type& __v)
682 {__nc = __v.__cc; return *this;}
683
684 __value_type& operator=(__value_type&& __v)
685 {__nc = std::move(__v.__nc); return *this;}
686
687 ~__value_type() {__cc.~value_type();}
Howard Hinnant70342b92013-06-19 21:29:40688 };
689#else
690 struct __value_type
691 {
692 typedef typename map::value_type value_type;
693 value_type __cc;
694
695 __value_type() {}
696
697 template <class _A0>
698 __value_type(const _A0& __a0)
699 : __cc(__a0) {}
700
701 template <class _A0, class _A1>
702 __value_type(const _A0& __a0, const _A1& __a1)
703 : __cc(__a0, __a1) {}
Howard Hinnant70342b92013-06-19 21:29:40704 };
705#endif
Howard Hinnant9b128e02013-07-05 18:06:00706 typedef __map_value_compare<key_type, __value_type, key_compare> __vc;
Howard Hinnantbc8d3f92010-05-11 19:42:16707 typedef typename allocator_traits<allocator_type>::template
708#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
709 rebind_alloc<__value_type>
710#else
711 rebind_alloc<__value_type>::other
712#endif
713 __allocator_type;
714 typedef __tree<__value_type, __vc, __allocator_type> __base;
715 typedef typename __base::__node_traits __node_traits;
716 typedef allocator_traits<allocator_type> __alloc_traits;
717
718 __base __tree_;
719
720public:
721 typedef typename __alloc_traits::pointer pointer;
722 typedef typename __alloc_traits::const_pointer const_pointer;
723 typedef typename __alloc_traits::size_type size_type;
724 typedef typename __alloc_traits::difference_type difference_type;
725 typedef __map_iterator<typename __base::iterator> iterator;
726 typedef __map_const_iterator<typename __base::const_iterator> const_iterator;
Howard Hinnant0949eed2011-06-30 21:18:19727 typedef _VSTD::reverse_iterator<iterator> reverse_iterator;
728 typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator;
Howard Hinnantbc8d3f92010-05-11 19:42:16729
Howard Hinnant82894812010-09-22 16:48:34730 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16731 explicit map(const key_compare& __comp = key_compare())
Howard Hinnant7686add2011-06-04 14:31:57732 _NOEXCEPT_(
733 is_nothrow_default_constructible<allocator_type>::value &&
734 is_nothrow_default_constructible<key_compare>::value &&
735 is_nothrow_copy_constructible<key_compare>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16736 : __tree_(__vc(__comp)) {}
737
Howard Hinnant82894812010-09-22 16:48:34738 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16739 explicit map(const key_compare& __comp, const allocator_type& __a)
740 : __tree_(__vc(__comp), __a) {}
741
742 template <class _InputIterator>
Howard Hinnant82894812010-09-22 16:48:34743 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16744 map(_InputIterator __f, _InputIterator __l,
745 const key_compare& __comp = key_compare())
746 : __tree_(__vc(__comp))
747 {
748 insert(__f, __l);
749 }
750
751 template <class _InputIterator>
Howard Hinnant82894812010-09-22 16:48:34752 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16753 map(_InputIterator __f, _InputIterator __l,
754 const key_compare& __comp, const allocator_type& __a)
755 : __tree_(__vc(__comp), __a)
756 {
757 insert(__f, __l);
758 }
759
Howard Hinnant82894812010-09-22 16:48:34760 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16761 map(const map& __m)
762 : __tree_(__m.__tree_)
763 {
764 insert(__m.begin(), __m.end());
765 }
766
Howard Hinnant61aa6012011-07-01 19:24:36767 _LIBCPP_INLINE_VISIBILITY
768 map& operator=(const map& __m)
769 {
Howard Hinnant70342b92013-06-19 21:29:40770#if __cplusplus >= 201103L
Howard Hinnant61aa6012011-07-01 19:24:36771 __tree_ = __m.__tree_;
Howard Hinnant70342b92013-06-19 21:29:40772#else
773 __tree_.clear();
774 __tree_.value_comp() = __m.__tree_.value_comp();
775 __tree_.__copy_assign_alloc(__m.__tree_);
776 insert(__m.begin(), __m.end());
777#endif
Howard Hinnant61aa6012011-07-01 19:24:36778 return *this;
779 }
780
Howard Hinnant73d21a42010-09-04 23:28:19781#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16782
Howard Hinnant82894812010-09-22 16:48:34783 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16784 map(map&& __m)
Howard Hinnant7686add2011-06-04 14:31:57785 _NOEXCEPT_(is_nothrow_move_constructible<__base>::value)
Howard Hinnant0949eed2011-06-30 21:18:19786 : __tree_(_VSTD::move(__m.__tree_))
Howard Hinnantbc8d3f92010-05-11 19:42:16787 {
788 }
789
790 map(map&& __m, const allocator_type& __a);
791
Howard Hinnant82894812010-09-22 16:48:34792 _LIBCPP_INLINE_VISIBILITY
Howard Hinnante3e32912011-08-12 21:56:02793 map& operator=(map&& __m)
794 _NOEXCEPT_(is_nothrow_move_assignable<__base>::value)
795 {
796 __tree_ = _VSTD::move(__m.__tree_);
797 return *this;
798 }
799
800#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
801
802#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
803
804 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16805 map(initializer_list<value_type> __il, const key_compare& __comp = key_compare())
806 : __tree_(__vc(__comp))
807 {
808 insert(__il.begin(), __il.end());
809 }
810
Howard Hinnant82894812010-09-22 16:48:34811 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16812 map(initializer_list<value_type> __il, const key_compare& __comp, const allocator_type& __a)
813 : __tree_(__vc(__comp), __a)
814 {
815 insert(__il.begin(), __il.end());
816 }
817
Howard Hinnant82894812010-09-22 16:48:34818 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16819 map& operator=(initializer_list<value_type> __il)
820 {
821 __tree_.__assign_unique(__il.begin(), __il.end());
822 return *this;
823 }
824
Howard Hinnante3e32912011-08-12 21:56:02825#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16826
Howard Hinnant82894812010-09-22 16:48:34827 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16828 explicit map(const allocator_type& __a)
829 : __tree_(__a)
830 {
831 }
832
Howard Hinnant82894812010-09-22 16:48:34833 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16834 map(const map& __m, const allocator_type& __a)
835 : __tree_(__m.__tree_.value_comp(), __a)
836 {
837 insert(__m.begin(), __m.end());
838 }
839
Howard Hinnant82894812010-09-22 16:48:34840 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7686add2011-06-04 14:31:57841 iterator begin() _NOEXCEPT {return __tree_.begin();}
Howard Hinnant82894812010-09-22 16:48:34842 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7686add2011-06-04 14:31:57843 const_iterator begin() const _NOEXCEPT {return __tree_.begin();}
Howard Hinnant82894812010-09-22 16:48:34844 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7686add2011-06-04 14:31:57845 iterator end() _NOEXCEPT {return __tree_.end();}
Howard Hinnant82894812010-09-22 16:48:34846 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7686add2011-06-04 14:31:57847 const_iterator end() const _NOEXCEPT {return __tree_.end();}
Howard Hinnantbc8d3f92010-05-11 19:42:16848
Howard Hinnant82894812010-09-22 16:48:34849 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7686add2011-06-04 14:31:57850 reverse_iterator rbegin() _NOEXCEPT {return reverse_iterator(end());}
Howard Hinnant82894812010-09-22 16:48:34851 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7686add2011-06-04 14:31:57852 const_reverse_iterator rbegin() const _NOEXCEPT
853 {return const_reverse_iterator(end());}
Howard Hinnant82894812010-09-22 16:48:34854 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7686add2011-06-04 14:31:57855 reverse_iterator rend() _NOEXCEPT
856 {return reverse_iterator(begin());}
Howard Hinnant82894812010-09-22 16:48:34857 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7686add2011-06-04 14:31:57858 const_reverse_iterator rend() const _NOEXCEPT
859 {return const_reverse_iterator(begin());}
Howard Hinnantbc8d3f92010-05-11 19:42:16860
Howard Hinnant82894812010-09-22 16:48:34861 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7686add2011-06-04 14:31:57862 const_iterator cbegin() const _NOEXCEPT {return begin();}
Howard Hinnant82894812010-09-22 16:48:34863 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7686add2011-06-04 14:31:57864 const_iterator cend() const _NOEXCEPT {return end();}
Howard Hinnant82894812010-09-22 16:48:34865 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7686add2011-06-04 14:31:57866 const_reverse_iterator crbegin() const _NOEXCEPT {return rbegin();}
Howard Hinnant82894812010-09-22 16:48:34867 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7686add2011-06-04 14:31:57868 const_reverse_iterator crend() const _NOEXCEPT {return rend();}
Howard Hinnantbc8d3f92010-05-11 19:42:16869
Howard Hinnant82894812010-09-22 16:48:34870 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7686add2011-06-04 14:31:57871 bool empty() const _NOEXCEPT {return __tree_.size() == 0;}
Howard Hinnant82894812010-09-22 16:48:34872 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7686add2011-06-04 14:31:57873 size_type size() const _NOEXCEPT {return __tree_.size();}
Howard Hinnant82894812010-09-22 16:48:34874 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7686add2011-06-04 14:31:57875 size_type max_size() const _NOEXCEPT {return __tree_.max_size();}
Howard Hinnantbc8d3f92010-05-11 19:42:16876
877 mapped_type& operator[](const key_type& __k);
Howard Hinnant73d21a42010-09-04 23:28:19878#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16879 mapped_type& operator[](key_type&& __k);
880#endif
881
882 mapped_type& at(const key_type& __k);
883 const mapped_type& at(const key_type& __k) const;
884
Howard Hinnant82894812010-09-22 16:48:34885 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7686add2011-06-04 14:31:57886 allocator_type get_allocator() const _NOEXCEPT {return __tree_.__alloc();}
Howard Hinnant82894812010-09-22 16:48:34887 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16888 key_compare key_comp() const {return __tree_.value_comp().key_comp();}
Howard Hinnant82894812010-09-22 16:48:34889 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16890 value_compare value_comp() const {return value_compare(__tree_.value_comp().key_comp());}
891
Howard Hinnant73d21a42010-09-04 23:28:19892#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant73d21a42010-09-04 23:28:19893#ifndef _LIBCPP_HAS_NO_VARIADICS
894
Howard Hinnant635ce1d2012-05-25 22:04:21895 template <class ..._Args>
Howard Hinnantbc8d3f92010-05-11 19:42:16896 pair<iterator, bool>
Howard Hinnant635ce1d2012-05-25 22:04:21897 emplace(_Args&& ...__args);
Howard Hinnantbc8d3f92010-05-11 19:42:16898
Howard Hinnant635ce1d2012-05-25 22:04:21899 template <class ..._Args>
Howard Hinnantbc8d3f92010-05-11 19:42:16900 iterator
Howard Hinnant635ce1d2012-05-25 22:04:21901 emplace_hint(const_iterator __p, _Args&& ...__args);
Howard Hinnantbc8d3f92010-05-11 19:42:16902
Howard Hinnant73d21a42010-09-04 23:28:19903#endif // _LIBCPP_HAS_NO_VARIADICS
904
Howard Hinnant99968442011-11-29 18:15:50905 template <class _Pp,
906 class = typename enable_if<is_constructible<value_type, _Pp>::value>::type>
Howard Hinnant82894812010-09-22 16:48:34907 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant99968442011-11-29 18:15:50908 pair<iterator, bool> insert(_Pp&& __p)
909 {return __tree_.__insert_unique(_VSTD::forward<_Pp>(__p));}
Howard Hinnantbc8d3f92010-05-11 19:42:16910
Howard Hinnant99968442011-11-29 18:15:50911 template <class _Pp,
912 class = typename enable_if<is_constructible<value_type, _Pp>::value>::type>
Howard Hinnant82894812010-09-22 16:48:34913 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant99968442011-11-29 18:15:50914 iterator insert(const_iterator __pos, _Pp&& __p)
915 {return __tree_.__insert_unique(__pos.__i_, _VSTD::forward<_Pp>(__p));}
Howard Hinnantbc8d3f92010-05-11 19:42:16916
Howard Hinnant73d21a42010-09-04 23:28:19917#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16918
Howard Hinnant82894812010-09-22 16:48:34919 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16920 pair<iterator, bool>
921 insert(const value_type& __v) {return __tree_.__insert_unique(__v);}
922
Howard Hinnant82894812010-09-22 16:48:34923 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16924 iterator
925 insert(const_iterator __p, const value_type& __v)
926 {return __tree_.__insert_unique(__p.__i_, __v);}
927
928 template <class _InputIterator>
Howard Hinnant82894812010-09-22 16:48:34929 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16930 void insert(_InputIterator __f, _InputIterator __l)
931 {
932 for (const_iterator __e = cend(); __f != __l; ++__f)
933 insert(__e.__i_, *__f);
934 }
935
Howard Hinnante3e32912011-08-12 21:56:02936#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
937
Howard Hinnant82894812010-09-22 16:48:34938 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16939 void insert(initializer_list<value_type> __il)
940 {insert(__il.begin(), __il.end());}
941
Howard Hinnante3e32912011-08-12 21:56:02942#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
943
Howard Hinnant82894812010-09-22 16:48:34944 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16945 iterator erase(const_iterator __p) {return __tree_.erase(__p.__i_);}
Howard Hinnant82894812010-09-22 16:48:34946 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16947 size_type erase(const key_type& __k)
948 {return __tree_.__erase_unique(__k);}
Howard Hinnant82894812010-09-22 16:48:34949 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16950 iterator erase(const_iterator __f, const_iterator __l)
951 {return __tree_.erase(__f.__i_, __l.__i_);}
Howard Hinnant82894812010-09-22 16:48:34952 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7686add2011-06-04 14:31:57953 void clear() _NOEXCEPT {__tree_.clear();}
Howard Hinnantbc8d3f92010-05-11 19:42:16954
Howard Hinnant82894812010-09-22 16:48:34955 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7686add2011-06-04 14:31:57956 void swap(map& __m)
957 _NOEXCEPT_(__is_nothrow_swappable<__base>::value)
958 {__tree_.swap(__m.__tree_);}
Howard Hinnantbc8d3f92010-05-11 19:42:16959
Howard Hinnant82894812010-09-22 16:48:34960 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16961 iterator find(const key_type& __k) {return __tree_.find(__k);}
Howard Hinnant82894812010-09-22 16:48:34962 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16963 const_iterator find(const key_type& __k) const {return __tree_.find(__k);}
Howard Hinnant82894812010-09-22 16:48:34964 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16965 size_type count(const key_type& __k) const
966 {return __tree_.__count_unique(__k);}
Howard Hinnant82894812010-09-22 16:48:34967 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16968 iterator lower_bound(const key_type& __k)
969 {return __tree_.lower_bound(__k);}
Howard Hinnant82894812010-09-22 16:48:34970 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16971 const_iterator lower_bound(const key_type& __k) const
972 {return __tree_.lower_bound(__k);}
Howard Hinnant82894812010-09-22 16:48:34973 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16974 iterator upper_bound(const key_type& __k)
975 {return __tree_.upper_bound(__k);}
Howard Hinnant82894812010-09-22 16:48:34976 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16977 const_iterator upper_bound(const key_type& __k) const
978 {return __tree_.upper_bound(__k);}
Howard Hinnant82894812010-09-22 16:48:34979 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16980 pair<iterator,iterator> equal_range(const key_type& __k)
981 {return __tree_.__equal_range_unique(__k);}
Howard Hinnant82894812010-09-22 16:48:34982 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16983 pair<const_iterator,const_iterator> equal_range(const key_type& __k) const
984 {return __tree_.__equal_range_unique(__k);}
985
986private:
987 typedef typename __base::__node __node;
988 typedef typename __base::__node_allocator __node_allocator;
989 typedef typename __base::__node_pointer __node_pointer;
990 typedef typename __base::__node_const_pointer __node_const_pointer;
991 typedef typename __base::__node_base_pointer __node_base_pointer;
992 typedef typename __base::__node_base_const_pointer __node_base_const_pointer;
Howard Hinnant99968442011-11-29 18:15:50993 typedef __map_node_destructor<__node_allocator> _Dp;
994 typedef unique_ptr<__node, _Dp> __node_holder;
Howard Hinnantbc8d3f92010-05-11 19:42:16995
Howard Hinnant73d21a42010-09-04 23:28:19996#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16997 __node_holder __construct_node();
Howard Hinnant635ce1d2012-05-25 22:04:21998 template <class _A0>
Howard Hinnantb66e1c32013-07-04 20:59:16999 __node_holder __construct_node(_A0&& __a0);
1000 __node_holder __construct_node_with_key(key_type&& __k);
Howard Hinnant73d21a42010-09-04 23:28:191001#ifndef _LIBCPP_HAS_NO_VARIADICS
Howard Hinnant635ce1d2012-05-25 22:04:211002 template <class _A0, class _A1, class ..._Args>
1003 __node_holder __construct_node(_A0&& __a0, _A1&& __a1, _Args&& ...__args);
Howard Hinnant73d21a42010-09-04 23:28:191004#endif // _LIBCPP_HAS_NO_VARIADICS
Howard Hinnantbc8d3f92010-05-11 19:42:161005#endif
Howard Hinnantb66e1c32013-07-04 20:59:161006 __node_holder __construct_node_with_key(const key_type& __k);
Howard Hinnantbc8d3f92010-05-11 19:42:161007
1008 __node_base_pointer&
1009 __find_equal_key(__node_base_pointer& __parent, const key_type& __k);
Howard Hinnantbc8d3f92010-05-11 19:42:161010 __node_base_const_pointer
1011 __find_equal_key(__node_base_const_pointer& __parent, const key_type& __k) const;
1012};
1013
1014// Find place to insert if __k doesn't exist
1015// Set __parent to parent of null leaf
1016// Return reference to null leaf
1017// If __k exists, set parent to node of __k and return reference to node of __k
1018template <class _Key, class _Tp, class _Compare, class _Allocator>
1019typename map<_Key, _Tp, _Compare, _Allocator>::__node_base_pointer&
1020map<_Key, _Tp, _Compare, _Allocator>::__find_equal_key(__node_base_pointer& __parent,
1021 const key_type& __k)
1022{
1023 __node_pointer __nd = __tree_.__root();
1024 if (__nd != nullptr)
1025 {
1026 while (true)
1027 {
Howard Hinnant70342b92013-06-19 21:29:401028 if (__tree_.value_comp().key_comp()(__k, __nd->__value_.__cc.first))
Howard Hinnantbc8d3f92010-05-11 19:42:161029 {
1030 if (__nd->__left_ != nullptr)
1031 __nd = static_cast<__node_pointer>(__nd->__left_);
1032 else
1033 {
Howard Hinnant70342b92013-06-19 21:29:401034 __parent = static_cast<__node_base_pointer>(__nd);
Howard Hinnantbc8d3f92010-05-11 19:42:161035 return __parent->__left_;
1036 }
1037 }
Howard Hinnant70342b92013-06-19 21:29:401038 else if (__tree_.value_comp().key_comp()(__nd->__value_.__cc.first, __k))
Howard Hinnantbc8d3f92010-05-11 19:42:161039 {
1040 if (__nd->__right_ != nullptr)
1041 __nd = static_cast<__node_pointer>(__nd->__right_);
1042 else
1043 {
Howard Hinnant70342b92013-06-19 21:29:401044 __parent = static_cast<__node_base_pointer>(__nd);
Howard Hinnantbc8d3f92010-05-11 19:42:161045 return __parent->__right_;
1046 }
1047 }
1048 else
1049 {
Howard Hinnant70342b92013-06-19 21:29:401050 __parent = static_cast<__node_base_pointer>(__nd);
Howard Hinnantbc8d3f92010-05-11 19:42:161051 return __parent;
1052 }
1053 }
1054 }
Howard Hinnant70342b92013-06-19 21:29:401055 __parent = static_cast<__node_base_pointer>(__tree_.__end_node());
Howard Hinnantbc8d3f92010-05-11 19:42:161056 return __parent->__left_;
1057}
1058
Howard Hinnantbc8d3f92010-05-11 19:42:161059// Find __k
1060// Set __parent to parent of null leaf and
1061// return reference to null leaf iv __k does not exist.
1062// If __k exists, set parent to node of __k and return reference to node of __k
1063template <class _Key, class _Tp, class _Compare, class _Allocator>
1064typename map<_Key, _Tp, _Compare, _Allocator>::__node_base_const_pointer
1065map<_Key, _Tp, _Compare, _Allocator>::__find_equal_key(__node_base_const_pointer& __parent,
1066 const key_type& __k) const
1067{
1068 __node_const_pointer __nd = __tree_.__root();
1069 if (__nd != nullptr)
1070 {
1071 while (true)
1072 {
Howard Hinnant70342b92013-06-19 21:29:401073 if (__tree_.value_comp().key_comp()(__k, __nd->__value_.__cc.first))
Howard Hinnantbc8d3f92010-05-11 19:42:161074 {
1075 if (__nd->__left_ != nullptr)
1076 __nd = static_cast<__node_pointer>(__nd->__left_);
1077 else
1078 {
Howard Hinnant70342b92013-06-19 21:29:401079 __parent = static_cast<__node_base_pointer>(__nd);
Howard Hinnantbc8d3f92010-05-11 19:42:161080 return const_cast<const __node_base_const_pointer&>(__parent->__left_);
1081 }
1082 }
Howard Hinnant70342b92013-06-19 21:29:401083 else if (__tree_.value_comp().key_comp()(__nd->__value_.__cc.first, __k))
Howard Hinnantbc8d3f92010-05-11 19:42:161084 {
1085 if (__nd->__right_ != nullptr)
1086 __nd = static_cast<__node_pointer>(__nd->__right_);
1087 else
1088 {
Howard Hinnant70342b92013-06-19 21:29:401089 __parent = static_cast<__node_base_pointer>(__nd);
Howard Hinnantbc8d3f92010-05-11 19:42:161090 return const_cast<const __node_base_const_pointer&>(__parent->__right_);
1091 }
1092 }
1093 else
1094 {
Howard Hinnant70342b92013-06-19 21:29:401095 __parent = static_cast<__node_base_pointer>(__nd);
Howard Hinnantbc8d3f92010-05-11 19:42:161096 return __parent;
1097 }
1098 }
1099 }
Howard Hinnant70342b92013-06-19 21:29:401100 __parent = static_cast<__node_base_pointer>(__tree_.__end_node());
Howard Hinnantbc8d3f92010-05-11 19:42:161101 return const_cast<const __node_base_const_pointer&>(__parent->__left_);
1102}
1103
Howard Hinnant73d21a42010-09-04 23:28:191104#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:161105
1106template <class _Key, class _Tp, class _Compare, class _Allocator>
1107map<_Key, _Tp, _Compare, _Allocator>::map(map&& __m, const allocator_type& __a)
Howard Hinnant0949eed2011-06-30 21:18:191108 : __tree_(_VSTD::move(__m.__tree_), __a)
Howard Hinnantbc8d3f92010-05-11 19:42:161109{
1110 if (__a != __m.get_allocator())
1111 {
1112 const_iterator __e = cend();
1113 while (!__m.empty())
1114 __tree_.__insert_unique(__e.__i_,
Howard Hinnant0949eed2011-06-30 21:18:191115 _VSTD::move(__m.__tree_.remove(__m.begin().__i_)->__value_));
Howard Hinnantbc8d3f92010-05-11 19:42:161116 }
1117}
1118
1119template <class _Key, class _Tp, class _Compare, class _Allocator>
1120typename map<_Key, _Tp, _Compare, _Allocator>::__node_holder
1121map<_Key, _Tp, _Compare, _Allocator>::__construct_node()
1122{
1123 __node_allocator& __na = __tree_.__node_alloc();
Howard Hinnant99968442011-11-29 18:15:501124 __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
Howard Hinnant70342b92013-06-19 21:29:401125 __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__cc.first));
Howard Hinnantbc8d3f92010-05-11 19:42:161126 __h.get_deleter().__first_constructed = true;
Howard Hinnant70342b92013-06-19 21:29:401127 __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__cc.second));
Howard Hinnantbc8d3f92010-05-11 19:42:161128 __h.get_deleter().__second_constructed = true;
1129 return __h;
1130}
1131
1132template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant635ce1d2012-05-25 22:04:211133template <class _A0>
Howard Hinnantb66e1c32013-07-04 20:59:161134typename map<_Key, _Tp, _Compare, _Allocator>::__node_holder
Howard Hinnantbc8d3f92010-05-11 19:42:161135map<_Key, _Tp, _Compare, _Allocator>::__construct_node(_A0&& __a0)
1136{
1137 __node_allocator& __na = __tree_.__node_alloc();
Howard Hinnant99968442011-11-29 18:15:501138 __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
Howard Hinnant0949eed2011-06-30 21:18:191139 __node_traits::construct(__na, _VSTD::addressof(__h->__value_), _VSTD::forward<_A0>(__a0));
Howard Hinnantbc8d3f92010-05-11 19:42:161140 __h.get_deleter().__first_constructed = true;
1141 __h.get_deleter().__second_constructed = true;
1142 return __h;
1143}
1144
Howard Hinnantbc8d3f92010-05-11 19:42:161145template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnantb66e1c32013-07-04 20:59:161146typename map<_Key, _Tp, _Compare, _Allocator>::__node_holder
1147map<_Key, _Tp, _Compare, _Allocator>::__construct_node_with_key(key_type&& __k)
Howard Hinnantbc8d3f92010-05-11 19:42:161148{
1149 __node_allocator& __na = __tree_.__node_alloc();
Howard Hinnant99968442011-11-29 18:15:501150 __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
Howard Hinnantb66e1c32013-07-04 20:59:161151 __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__cc.first), _VSTD::move(__k));
Howard Hinnantbc8d3f92010-05-11 19:42:161152 __h.get_deleter().__first_constructed = true;
Howard Hinnant70342b92013-06-19 21:29:401153 __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__cc.second));
Howard Hinnant635ce1d2012-05-25 22:04:211154 __h.get_deleter().__second_constructed = true;
Howard Hinnantb66e1c32013-07-04 20:59:161155 return _VSTD::move(__h);
Howard Hinnant635ce1d2012-05-25 22:04:211156}
1157
1158#ifndef _LIBCPP_HAS_NO_VARIADICS
1159
1160template <class _Key, class _Tp, class _Compare, class _Allocator>
1161template <class _A0, class _A1, class ..._Args>
1162typename map<_Key, _Tp, _Compare, _Allocator>::__node_holder
1163map<_Key, _Tp, _Compare, _Allocator>::__construct_node(_A0&& __a0, _A1&& __a1, _Args&& ...__args)
1164{
1165 __node_allocator& __na = __tree_.__node_alloc();
1166 __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
1167 __node_traits::construct(__na, _VSTD::addressof(__h->__value_),
1168 _VSTD::forward<_A0>(__a0), _VSTD::forward<_A1>(__a1),
1169 _VSTD::forward<_Args>(__args)...);
1170 __h.get_deleter().__first_constructed = true;
Howard Hinnantbc8d3f92010-05-11 19:42:161171 __h.get_deleter().__second_constructed = true;
1172 return __h;
1173}
1174
Howard Hinnant73d21a42010-09-04 23:28:191175#endif // _LIBCPP_HAS_NO_VARIADICS
1176
Howard Hinnantb66e1c32013-07-04 20:59:161177#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:161178
1179template <class _Key, class _Tp, class _Compare, class _Allocator>
1180typename map<_Key, _Tp, _Compare, _Allocator>::__node_holder
Howard Hinnantb66e1c32013-07-04 20:59:161181map<_Key, _Tp, _Compare, _Allocator>::__construct_node_with_key(const key_type& __k)
Howard Hinnantbc8d3f92010-05-11 19:42:161182{
1183 __node_allocator& __na = __tree_.__node_alloc();
Howard Hinnant99968442011-11-29 18:15:501184 __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
Howard Hinnant70342b92013-06-19 21:29:401185 __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__cc.first), __k);
Howard Hinnantbc8d3f92010-05-11 19:42:161186 __h.get_deleter().__first_constructed = true;
Howard Hinnant70342b92013-06-19 21:29:401187 __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__cc.second));
Howard Hinnantbc8d3f92010-05-11 19:42:161188 __h.get_deleter().__second_constructed = true;
Howard Hinnant0949eed2011-06-30 21:18:191189 return _VSTD::move(__h);
Howard Hinnantbc8d3f92010-05-11 19:42:161190}
1191
Howard Hinnantbc8d3f92010-05-11 19:42:161192template <class _Key, class _Tp, class _Compare, class _Allocator>
1193_Tp&
1194map<_Key, _Tp, _Compare, _Allocator>::operator[](const key_type& __k)
1195{
1196 __node_base_pointer __parent;
1197 __node_base_pointer& __child = __find_equal_key(__parent, __k);
1198 __node_pointer __r = static_cast<__node_pointer>(__child);
1199 if (__child == nullptr)
1200 {
Howard Hinnantb66e1c32013-07-04 20:59:161201 __node_holder __h = __construct_node_with_key(__k);
Howard Hinnant70342b92013-06-19 21:29:401202 __tree_.__insert_node_at(__parent, __child, static_cast<__node_base_pointer>(__h.get()));
Howard Hinnantbc8d3f92010-05-11 19:42:161203 __r = __h.release();
1204 }
Howard Hinnant70342b92013-06-19 21:29:401205 return __r->__value_.__cc.second;
Howard Hinnantbc8d3f92010-05-11 19:42:161206}
1207
Howard Hinnant73d21a42010-09-04 23:28:191208#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:161209
1210template <class _Key, class _Tp, class _Compare, class _Allocator>
1211_Tp&
1212map<_Key, _Tp, _Compare, _Allocator>::operator[](key_type&& __k)
1213{
1214 __node_base_pointer __parent;
1215 __node_base_pointer& __child = __find_equal_key(__parent, __k);
1216 __node_pointer __r = static_cast<__node_pointer>(__child);
1217 if (__child == nullptr)
1218 {
Howard Hinnantb66e1c32013-07-04 20:59:161219 __node_holder __h = __construct_node_with_key(_VSTD::move(__k));
Howard Hinnant70342b92013-06-19 21:29:401220 __tree_.__insert_node_at(__parent, __child, static_cast<__node_base_pointer>(__h.get()));
Howard Hinnantbc8d3f92010-05-11 19:42:161221 __r = __h.release();
1222 }
Howard Hinnant70342b92013-06-19 21:29:401223 return __r->__value_.__cc.second;
Howard Hinnantbc8d3f92010-05-11 19:42:161224}
1225
Howard Hinnant73d21a42010-09-04 23:28:191226#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:161227
1228template <class _Key, class _Tp, class _Compare, class _Allocator>
1229_Tp&
1230map<_Key, _Tp, _Compare, _Allocator>::at(const key_type& __k)
1231{
1232 __node_base_pointer __parent;
1233 __node_base_pointer& __child = __find_equal_key(__parent, __k);
Howard Hinnantd4444702010-08-11 17:04:311234#ifndef _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:161235 if (__child == nullptr)
1236 throw out_of_range("map::at: key not found");
Howard Hinnant324bb032010-08-22 00:02:431237#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant70342b92013-06-19 21:29:401238 return static_cast<__node_pointer>(__child)->__value_.__cc.second;
Howard Hinnantbc8d3f92010-05-11 19:42:161239}
1240
1241template <class _Key, class _Tp, class _Compare, class _Allocator>
1242const _Tp&
1243map<_Key, _Tp, _Compare, _Allocator>::at(const key_type& __k) const
1244{
1245 __node_base_const_pointer __parent;
1246 __node_base_const_pointer __child = __find_equal_key(__parent, __k);
Howard Hinnantd4444702010-08-11 17:04:311247#ifndef _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:161248 if (__child == nullptr)
1249 throw out_of_range("map::at: key not found");
Howard Hinnant324bb032010-08-22 00:02:431250#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant70342b92013-06-19 21:29:401251 return static_cast<__node_const_pointer>(__child)->__value_.__cc.second;
Howard Hinnantbc8d3f92010-05-11 19:42:161252}
1253
Howard Hinnant73d21a42010-09-04 23:28:191254#if !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
Howard Hinnantbc8d3f92010-05-11 19:42:161255
1256template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant635ce1d2012-05-25 22:04:211257template <class ..._Args>
Howard Hinnantbc8d3f92010-05-11 19:42:161258pair<typename map<_Key, _Tp, _Compare, _Allocator>::iterator, bool>
Howard Hinnant635ce1d2012-05-25 22:04:211259map<_Key, _Tp, _Compare, _Allocator>::emplace(_Args&& ...__args)
Howard Hinnantbc8d3f92010-05-11 19:42:161260{
Howard Hinnant635ce1d2012-05-25 22:04:211261 __node_holder __h = __construct_node(_VSTD::forward<_Args>(__args)...);
Howard Hinnantbc8d3f92010-05-11 19:42:161262 pair<iterator, bool> __r = __tree_.__node_insert_unique(__h.get());
1263 if (__r.second)
1264 __h.release();
1265 return __r;
1266}
1267
1268template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant635ce1d2012-05-25 22:04:211269template <class ..._Args>
Howard Hinnantbc8d3f92010-05-11 19:42:161270typename map<_Key, _Tp, _Compare, _Allocator>::iterator
1271map<_Key, _Tp, _Compare, _Allocator>::emplace_hint(const_iterator __p,
Howard Hinnant635ce1d2012-05-25 22:04:211272 _Args&& ...__args)
Howard Hinnantbc8d3f92010-05-11 19:42:161273{
Howard Hinnant635ce1d2012-05-25 22:04:211274 __node_holder __h = __construct_node(_VSTD::forward<_Args>(__args)...);
Howard Hinnantbc8d3f92010-05-11 19:42:161275 iterator __r = __tree_.__node_insert_unique(__p.__i_, __h.get());
1276 if (__r.__i_.__ptr_ == __h.get())
1277 __h.release();
1278 return __r;
1279}
1280
Howard Hinnant73d21a42010-09-04 23:28:191281#endif // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
Howard Hinnantbc8d3f92010-05-11 19:42:161282
1283template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant82894812010-09-22 16:48:341284inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161285bool
1286operator==(const map<_Key, _Tp, _Compare, _Allocator>& __x,
1287 const map<_Key, _Tp, _Compare, _Allocator>& __y)
1288{
Howard Hinnant0949eed2011-06-30 21:18:191289 return __x.size() == __y.size() && _VSTD::equal(__x.begin(), __x.end(), __y.begin());
Howard Hinnantbc8d3f92010-05-11 19:42:161290}
1291
1292template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant82894812010-09-22 16:48:341293inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161294bool
1295operator< (const map<_Key, _Tp, _Compare, _Allocator>& __x,
1296 const map<_Key, _Tp, _Compare, _Allocator>& __y)
1297{
Howard Hinnant0949eed2011-06-30 21:18:191298 return _VSTD::lexicographical_compare(__x.begin(), __x.end(), __y.begin(), __y.end());
Howard Hinnantbc8d3f92010-05-11 19:42:161299}
1300
1301template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant82894812010-09-22 16:48:341302inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161303bool
1304operator!=(const map<_Key, _Tp, _Compare, _Allocator>& __x,
1305 const map<_Key, _Tp, _Compare, _Allocator>& __y)
1306{
1307 return !(__x == __y);
1308}
1309
1310template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant82894812010-09-22 16:48:341311inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161312bool
1313operator> (const map<_Key, _Tp, _Compare, _Allocator>& __x,
1314 const map<_Key, _Tp, _Compare, _Allocator>& __y)
1315{
1316 return __y < __x;
1317}
1318
1319template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant82894812010-09-22 16:48:341320inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161321bool
1322operator>=(const map<_Key, _Tp, _Compare, _Allocator>& __x,
1323 const map<_Key, _Tp, _Compare, _Allocator>& __y)
1324{
1325 return !(__x < __y);
1326}
1327
1328template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant82894812010-09-22 16:48:341329inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161330bool
1331operator<=(const map<_Key, _Tp, _Compare, _Allocator>& __x,
1332 const map<_Key, _Tp, _Compare, _Allocator>& __y)
1333{
1334 return !(__y < __x);
1335}
1336
1337template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant82894812010-09-22 16:48:341338inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161339void
1340swap(map<_Key, _Tp, _Compare, _Allocator>& __x,
1341 map<_Key, _Tp, _Compare, _Allocator>& __y)
Howard Hinnant7686add2011-06-04 14:31:571342 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
Howard Hinnantbc8d3f92010-05-11 19:42:161343{
1344 __x.swap(__y);
1345}
1346
1347template <class _Key, class _Tp, class _Compare = less<_Key>,
1348 class _Allocator = allocator<pair<const _Key, _Tp> > >
Howard Hinnant0f678bd2013-08-12 18:38:341349class _LIBCPP_TYPE_VIS_ONLY multimap
Howard Hinnantbc8d3f92010-05-11 19:42:161350{
1351public:
1352 // types:
1353 typedef _Key key_type;
1354 typedef _Tp mapped_type;
1355 typedef pair<const key_type, mapped_type> value_type;
Howard Hinnant70342b92013-06-19 21:29:401356 typedef pair<key_type, mapped_type> __nc_value_type;
Howard Hinnantbc8d3f92010-05-11 19:42:161357 typedef _Compare key_compare;
1358 typedef _Allocator allocator_type;
1359 typedef value_type& reference;
1360 typedef const value_type& const_reference;
1361
Howard Hinnant0f678bd2013-08-12 18:38:341362 class _LIBCPP_TYPE_VIS_ONLY value_compare
Howard Hinnantbc8d3f92010-05-11 19:42:161363 : public binary_function<value_type, value_type, bool>
1364 {
1365 friend class multimap;
1366 protected:
1367 key_compare comp;
1368
Howard Hinnant82894812010-09-22 16:48:341369 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161370 value_compare(key_compare c) : comp(c) {}
1371 public:
Howard Hinnant82894812010-09-22 16:48:341372 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161373 bool operator()(const value_type& __x, const value_type& __y) const
1374 {return comp(__x.first, __y.first);}
1375 };
1376
1377private:
Howard Hinnant70342b92013-06-19 21:29:401378#if __cplusplus >= 201103L
1379 union __value_type
1380 {
1381 typedef typename multimap::value_type value_type;
1382 typedef typename multimap::__nc_value_type __nc_value_type;
1383 value_type __cc;
1384 __nc_value_type __nc;
1385
1386 template <class ..._Args>
1387 __value_type(_Args&& ...__args)
1388 : __cc(std::forward<_Args>(__args)...) {}
1389
1390 __value_type(const __value_type& __v)
1391 : __cc(std::move(__v.__cc)) {}
1392
1393 __value_type(__value_type&& __v)
1394 : __nc(std::move(__v.__nc)) {}
1395
1396 __value_type& operator=(const __value_type& __v)
1397 {__nc = __v.__cc; return *this;}
1398
1399 __value_type& operator=(__value_type&& __v)
1400 {__nc = std::move(__v.__nc); return *this;}
1401
1402 ~__value_type() {__cc.~value_type();}
Howard Hinnant70342b92013-06-19 21:29:401403 };
1404#else
1405 struct __value_type
1406 {
1407 typedef typename multimap::value_type value_type;
1408 value_type __cc;
1409
1410 __value_type() {}
1411
1412 template <class _A0>
1413 __value_type(const _A0& __a0)
1414 : __cc(__a0) {}
1415
1416 template <class _A0, class _A1>
1417 __value_type(const _A0& __a0, const _A1& __a1)
1418 : __cc(__a0, __a1) {}
Howard Hinnant70342b92013-06-19 21:29:401419 };
1420#endif
Howard Hinnant9b128e02013-07-05 18:06:001421 typedef __map_value_compare<key_type, __value_type, key_compare> __vc;
Howard Hinnantbc8d3f92010-05-11 19:42:161422 typedef typename allocator_traits<allocator_type>::template
1423#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
1424 rebind_alloc<__value_type>
1425#else
1426 rebind_alloc<__value_type>::other
1427#endif
1428 __allocator_type;
1429 typedef __tree<__value_type, __vc, __allocator_type> __base;
1430 typedef typename __base::__node_traits __node_traits;
1431 typedef allocator_traits<allocator_type> __alloc_traits;
1432
1433 __base __tree_;
1434
1435public:
1436 typedef typename __alloc_traits::pointer pointer;
1437 typedef typename __alloc_traits::const_pointer const_pointer;
1438 typedef typename __alloc_traits::size_type size_type;
1439 typedef typename __alloc_traits::difference_type difference_type;
1440 typedef __map_iterator<typename __base::iterator> iterator;
1441 typedef __map_const_iterator<typename __base::const_iterator> const_iterator;
Howard Hinnant0949eed2011-06-30 21:18:191442 typedef _VSTD::reverse_iterator<iterator> reverse_iterator;
1443 typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator;
Howard Hinnantbc8d3f92010-05-11 19:42:161444
Howard Hinnant82894812010-09-22 16:48:341445 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161446 explicit multimap(const key_compare& __comp = key_compare())
Howard Hinnant7686add2011-06-04 14:31:571447 _NOEXCEPT_(
1448 is_nothrow_default_constructible<allocator_type>::value &&
1449 is_nothrow_default_constructible<key_compare>::value &&
1450 is_nothrow_copy_constructible<key_compare>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:161451 : __tree_(__vc(__comp)) {}
1452
Howard Hinnant82894812010-09-22 16:48:341453 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161454 explicit multimap(const key_compare& __comp, const allocator_type& __a)
1455 : __tree_(__vc(__comp), __a) {}
1456
1457 template <class _InputIterator>
Howard Hinnant82894812010-09-22 16:48:341458 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161459 multimap(_InputIterator __f, _InputIterator __l,
1460 const key_compare& __comp = key_compare())
1461 : __tree_(__vc(__comp))
1462 {
1463 insert(__f, __l);
1464 }
1465
1466 template <class _InputIterator>
Howard Hinnant82894812010-09-22 16:48:341467 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161468 multimap(_InputIterator __f, _InputIterator __l,
1469 const key_compare& __comp, const allocator_type& __a)
1470 : __tree_(__vc(__comp), __a)
1471 {
1472 insert(__f, __l);
1473 }
1474
Howard Hinnant82894812010-09-22 16:48:341475 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161476 multimap(const multimap& __m)
1477 : __tree_(__m.__tree_.value_comp(),
1478 __alloc_traits::select_on_container_copy_construction(__m.__tree_.__alloc()))
1479 {
1480 insert(__m.begin(), __m.end());
1481 }
1482
Howard Hinnant61aa6012011-07-01 19:24:361483 _LIBCPP_INLINE_VISIBILITY
1484 multimap& operator=(const multimap& __m)
1485 {
Howard Hinnant70342b92013-06-19 21:29:401486#if __cplusplus >= 201103L
Howard Hinnant61aa6012011-07-01 19:24:361487 __tree_ = __m.__tree_;
Howard Hinnant70342b92013-06-19 21:29:401488#else
1489 __tree_.clear();
1490 __tree_.value_comp() = __m.__tree_.value_comp();
1491 __tree_.__copy_assign_alloc(__m.__tree_);
1492 insert(__m.begin(), __m.end());
1493#endif
Howard Hinnant61aa6012011-07-01 19:24:361494 return *this;
1495 }
1496
Howard Hinnant73d21a42010-09-04 23:28:191497#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:161498
Howard Hinnant82894812010-09-22 16:48:341499 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161500 multimap(multimap&& __m)
Howard Hinnant7686add2011-06-04 14:31:571501 _NOEXCEPT_(is_nothrow_move_constructible<__base>::value)
Howard Hinnant0949eed2011-06-30 21:18:191502 : __tree_(_VSTD::move(__m.__tree_))
Howard Hinnantbc8d3f92010-05-11 19:42:161503 {
1504 }
1505
1506 multimap(multimap&& __m, const allocator_type& __a);
1507
Howard Hinnant82894812010-09-22 16:48:341508 _LIBCPP_INLINE_VISIBILITY
Howard Hinnante3e32912011-08-12 21:56:021509 multimap& operator=(multimap&& __m)
1510 _NOEXCEPT_(is_nothrow_move_assignable<__base>::value)
1511 {
1512 __tree_ = _VSTD::move(__m.__tree_);
1513 return *this;
1514 }
1515
1516#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
1517
1518#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1519
1520 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161521 multimap(initializer_list<value_type> __il, const key_compare& __comp = key_compare())
1522 : __tree_(__vc(__comp))
1523 {
1524 insert(__il.begin(), __il.end());
1525 }
1526
Howard Hinnant82894812010-09-22 16:48:341527 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161528 multimap(initializer_list<value_type> __il, const key_compare& __comp, const allocator_type& __a)
1529 : __tree_(__vc(__comp), __a)
1530 {
1531 insert(__il.begin(), __il.end());
1532 }
1533
Howard Hinnant82894812010-09-22 16:48:341534 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161535 multimap& operator=(initializer_list<value_type> __il)
1536 {
1537 __tree_.__assign_multi(__il.begin(), __il.end());
1538 return *this;
1539 }
Howard Hinnante3e32912011-08-12 21:56:021540
1541#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:161542
Howard Hinnant82894812010-09-22 16:48:341543 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161544 explicit multimap(const allocator_type& __a)
1545 : __tree_(__a)
1546 {
1547 }
1548
Howard Hinnant82894812010-09-22 16:48:341549 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161550 multimap(const multimap& __m, const allocator_type& __a)
1551 : __tree_(__m.__tree_.value_comp(), __a)
1552 {
1553 insert(__m.begin(), __m.end());
1554 }
1555
Howard Hinnant82894812010-09-22 16:48:341556 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7686add2011-06-04 14:31:571557 iterator begin() _NOEXCEPT {return __tree_.begin();}
Howard Hinnant82894812010-09-22 16:48:341558 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7686add2011-06-04 14:31:571559 const_iterator begin() const _NOEXCEPT {return __tree_.begin();}
Howard Hinnant82894812010-09-22 16:48:341560 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7686add2011-06-04 14:31:571561 iterator end() _NOEXCEPT {return __tree_.end();}
Howard Hinnant82894812010-09-22 16:48:341562 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7686add2011-06-04 14:31:571563 const_iterator end() const _NOEXCEPT {return __tree_.end();}
Howard Hinnantbc8d3f92010-05-11 19:42:161564
Howard Hinnant82894812010-09-22 16:48:341565 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7686add2011-06-04 14:31:571566 reverse_iterator rbegin() _NOEXCEPT {return reverse_iterator(end());}
Howard Hinnant82894812010-09-22 16:48:341567 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7686add2011-06-04 14:31:571568 const_reverse_iterator rbegin() const _NOEXCEPT
1569 {return const_reverse_iterator(end());}
Howard Hinnant82894812010-09-22 16:48:341570 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7686add2011-06-04 14:31:571571 reverse_iterator rend() _NOEXCEPT {return reverse_iterator(begin());}
Howard Hinnant82894812010-09-22 16:48:341572 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7686add2011-06-04 14:31:571573 const_reverse_iterator rend() const _NOEXCEPT
1574 {return const_reverse_iterator(begin());}
Howard Hinnantbc8d3f92010-05-11 19:42:161575
Howard Hinnant82894812010-09-22 16:48:341576 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7686add2011-06-04 14:31:571577 const_iterator cbegin() const _NOEXCEPT {return begin();}
Howard Hinnant82894812010-09-22 16:48:341578 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7686add2011-06-04 14:31:571579 const_iterator cend() const _NOEXCEPT {return end();}
Howard Hinnant82894812010-09-22 16:48:341580 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7686add2011-06-04 14:31:571581 const_reverse_iterator crbegin() const _NOEXCEPT {return rbegin();}
Howard Hinnant82894812010-09-22 16:48:341582 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7686add2011-06-04 14:31:571583 const_reverse_iterator crend() const _NOEXCEPT {return rend();}
Howard Hinnantbc8d3f92010-05-11 19:42:161584
Howard Hinnant82894812010-09-22 16:48:341585 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7686add2011-06-04 14:31:571586 bool empty() const _NOEXCEPT {return __tree_.size() == 0;}
Howard Hinnant82894812010-09-22 16:48:341587 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7686add2011-06-04 14:31:571588 size_type size() const _NOEXCEPT {return __tree_.size();}
Howard Hinnant82894812010-09-22 16:48:341589 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7686add2011-06-04 14:31:571590 size_type max_size() const _NOEXCEPT {return __tree_.max_size();}
Howard Hinnantbc8d3f92010-05-11 19:42:161591
Howard Hinnant82894812010-09-22 16:48:341592 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7686add2011-06-04 14:31:571593 allocator_type get_allocator() const _NOEXCEPT {return __tree_.__alloc();}
Howard Hinnant82894812010-09-22 16:48:341594 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7686add2011-06-04 14:31:571595 key_compare key_comp() const {return __tree_.value_comp().key_comp();}
Howard Hinnant82894812010-09-22 16:48:341596 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7686add2011-06-04 14:31:571597 value_compare value_comp() const
1598 {return value_compare(__tree_.value_comp().key_comp());}
Howard Hinnantbc8d3f92010-05-11 19:42:161599
Howard Hinnant73d21a42010-09-04 23:28:191600#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant73d21a42010-09-04 23:28:191601#ifndef _LIBCPP_HAS_NO_VARIADICS
1602
Howard Hinnant635ce1d2012-05-25 22:04:211603 template <class ..._Args>
Howard Hinnantbc8d3f92010-05-11 19:42:161604 iterator
Howard Hinnant635ce1d2012-05-25 22:04:211605 emplace(_Args&& ...__args);
Howard Hinnantbc8d3f92010-05-11 19:42:161606
Howard Hinnant635ce1d2012-05-25 22:04:211607 template <class ..._Args>
Howard Hinnantbc8d3f92010-05-11 19:42:161608 iterator
Howard Hinnant635ce1d2012-05-25 22:04:211609 emplace_hint(const_iterator __p, _Args&& ...__args);
Howard Hinnantbc8d3f92010-05-11 19:42:161610
Howard Hinnant73d21a42010-09-04 23:28:191611#endif // _LIBCPP_HAS_NO_VARIADICS
1612
Howard Hinnant99968442011-11-29 18:15:501613 template <class _Pp,
1614 class = typename enable_if<is_constructible<value_type, _Pp>::value>::type>
Howard Hinnant82894812010-09-22 16:48:341615 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant99968442011-11-29 18:15:501616 iterator insert(_Pp&& __p)
1617 {return __tree_.__insert_multi(_VSTD::forward<_Pp>(__p));}
Howard Hinnantbc8d3f92010-05-11 19:42:161618
Howard Hinnant99968442011-11-29 18:15:501619 template <class _Pp,
1620 class = typename enable_if<is_constructible<value_type, _Pp>::value>::type>
Howard Hinnant82894812010-09-22 16:48:341621 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant99968442011-11-29 18:15:501622 iterator insert(const_iterator __pos, _Pp&& __p)
1623 {return __tree_.__insert_multi(__pos.__i_, _VSTD::forward<_Pp>(__p));}
Howard Hinnantbc8d3f92010-05-11 19:42:161624
Howard Hinnant73d21a42010-09-04 23:28:191625#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:161626
Howard Hinnant82894812010-09-22 16:48:341627 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161628 iterator insert(const value_type& __v) {return __tree_.__insert_multi(__v);}
1629
Howard Hinnant82894812010-09-22 16:48:341630 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161631 iterator insert(const_iterator __p, const value_type& __v)
1632 {return __tree_.__insert_multi(__p.__i_, __v);}
1633
1634 template <class _InputIterator>
Howard Hinnant82894812010-09-22 16:48:341635 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161636 void insert(_InputIterator __f, _InputIterator __l)
1637 {
1638 for (const_iterator __e = cend(); __f != __l; ++__f)
1639 __tree_.__insert_multi(__e.__i_, *__f);
1640 }
1641
Howard Hinnante3e32912011-08-12 21:56:021642#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1643
Howard Hinnant82894812010-09-22 16:48:341644 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161645 void insert(initializer_list<value_type> __il)
1646 {insert(__il.begin(), __il.end());}
1647
Howard Hinnante3e32912011-08-12 21:56:021648#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1649
Howard Hinnant82894812010-09-22 16:48:341650 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161651 iterator erase(const_iterator __p) {return __tree_.erase(__p.__i_);}
Howard Hinnant82894812010-09-22 16:48:341652 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161653 size_type erase(const key_type& __k) {return __tree_.__erase_multi(__k);}
Howard Hinnant82894812010-09-22 16:48:341654 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161655 iterator erase(const_iterator __f, const_iterator __l)
1656 {return __tree_.erase(__f.__i_, __l.__i_);}
Howard Hinnant82894812010-09-22 16:48:341657 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161658 void clear() {__tree_.clear();}
1659
Howard Hinnant82894812010-09-22 16:48:341660 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7686add2011-06-04 14:31:571661 void swap(multimap& __m)
1662 _NOEXCEPT_(__is_nothrow_swappable<__base>::value)
1663 {__tree_.swap(__m.__tree_);}
Howard Hinnantbc8d3f92010-05-11 19:42:161664
Howard Hinnant82894812010-09-22 16:48:341665 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161666 iterator find(const key_type& __k) {return __tree_.find(__k);}
Howard Hinnant82894812010-09-22 16:48:341667 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161668 const_iterator find(const key_type& __k) const {return __tree_.find(__k);}
Howard Hinnant82894812010-09-22 16:48:341669 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161670 size_type count(const key_type& __k) const
1671 {return __tree_.__count_multi(__k);}
Howard Hinnant82894812010-09-22 16:48:341672 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161673 iterator lower_bound(const key_type& __k)
1674 {return __tree_.lower_bound(__k);}
Howard Hinnant82894812010-09-22 16:48:341675 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161676 const_iterator lower_bound(const key_type& __k) const
1677 {return __tree_.lower_bound(__k);}
Howard Hinnant82894812010-09-22 16:48:341678 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161679 iterator upper_bound(const key_type& __k)
1680 {return __tree_.upper_bound(__k);}
Howard Hinnant82894812010-09-22 16:48:341681 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161682 const_iterator upper_bound(const key_type& __k) const
1683 {return __tree_.upper_bound(__k);}
Howard Hinnant82894812010-09-22 16:48:341684 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161685 pair<iterator,iterator> equal_range(const key_type& __k)
1686 {return __tree_.__equal_range_multi(__k);}
Howard Hinnant82894812010-09-22 16:48:341687 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161688 pair<const_iterator,const_iterator> equal_range(const key_type& __k) const
1689 {return __tree_.__equal_range_multi(__k);}
1690
1691private:
1692 typedef typename __base::__node __node;
1693 typedef typename __base::__node_allocator __node_allocator;
1694 typedef typename __base::__node_pointer __node_pointer;
1695 typedef typename __base::__node_const_pointer __node_const_pointer;
Howard Hinnant99968442011-11-29 18:15:501696 typedef __map_node_destructor<__node_allocator> _Dp;
1697 typedef unique_ptr<__node, _Dp> __node_holder;
Howard Hinnantbc8d3f92010-05-11 19:42:161698
Howard Hinnant73d21a42010-09-04 23:28:191699#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:161700 __node_holder __construct_node();
Howard Hinnant635ce1d2012-05-25 22:04:211701 template <class _A0>
Howard Hinnantb66e1c32013-07-04 20:59:161702 __node_holder
Howard Hinnant635ce1d2012-05-25 22:04:211703 __construct_node(_A0&& __a0);
Howard Hinnant73d21a42010-09-04 23:28:191704#ifndef _LIBCPP_HAS_NO_VARIADICS
Howard Hinnant635ce1d2012-05-25 22:04:211705 template <class _A0, class _A1, class ..._Args>
1706 __node_holder __construct_node(_A0&& __a0, _A1&& __a1, _Args&& ...__args);
Howard Hinnant73d21a42010-09-04 23:28:191707#endif // _LIBCPP_HAS_NO_VARIADICS
1708#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:161709};
1710
Howard Hinnant73d21a42010-09-04 23:28:191711#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:161712
1713template <class _Key, class _Tp, class _Compare, class _Allocator>
1714multimap<_Key, _Tp, _Compare, _Allocator>::multimap(multimap&& __m, const allocator_type& __a)
Howard Hinnant0949eed2011-06-30 21:18:191715 : __tree_(_VSTD::move(__m.__tree_), __a)
Howard Hinnantbc8d3f92010-05-11 19:42:161716{
1717 if (__a != __m.get_allocator())
1718 {
1719 const_iterator __e = cend();
1720 while (!__m.empty())
1721 __tree_.__insert_multi(__e.__i_,
Howard Hinnant0949eed2011-06-30 21:18:191722 _VSTD::move(__m.__tree_.remove(__m.begin().__i_)->__value_));
Howard Hinnantbc8d3f92010-05-11 19:42:161723 }
1724}
1725
1726template <class _Key, class _Tp, class _Compare, class _Allocator>
1727typename multimap<_Key, _Tp, _Compare, _Allocator>::__node_holder
1728multimap<_Key, _Tp, _Compare, _Allocator>::__construct_node()
1729{
1730 __node_allocator& __na = __tree_.__node_alloc();
Howard Hinnant99968442011-11-29 18:15:501731 __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
Howard Hinnant70342b92013-06-19 21:29:401732 __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__cc.first));
Howard Hinnantbc8d3f92010-05-11 19:42:161733 __h.get_deleter().__first_constructed = true;
Howard Hinnant70342b92013-06-19 21:29:401734 __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__cc.second));
Howard Hinnantbc8d3f92010-05-11 19:42:161735 __h.get_deleter().__second_constructed = true;
1736 return __h;
1737}
1738
1739template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant635ce1d2012-05-25 22:04:211740template <class _A0>
Howard Hinnantb66e1c32013-07-04 20:59:161741typename multimap<_Key, _Tp, _Compare, _Allocator>::__node_holder
Howard Hinnantbc8d3f92010-05-11 19:42:161742multimap<_Key, _Tp, _Compare, _Allocator>::__construct_node(_A0&& __a0)
1743{
1744 __node_allocator& __na = __tree_.__node_alloc();
Howard Hinnant99968442011-11-29 18:15:501745 __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
Howard Hinnant0949eed2011-06-30 21:18:191746 __node_traits::construct(__na, _VSTD::addressof(__h->__value_), _VSTD::forward<_A0>(__a0));
Howard Hinnantbc8d3f92010-05-11 19:42:161747 __h.get_deleter().__first_constructed = true;
1748 __h.get_deleter().__second_constructed = true;
1749 return __h;
1750}
1751
Howard Hinnant635ce1d2012-05-25 22:04:211752#ifndef _LIBCPP_HAS_NO_VARIADICS
1753
1754template <class _Key, class _Tp, class _Compare, class _Allocator>
1755template <class _A0, class _A1, class ..._Args>
1756typename multimap<_Key, _Tp, _Compare, _Allocator>::__node_holder
1757multimap<_Key, _Tp, _Compare, _Allocator>::__construct_node(_A0&& __a0, _A1&& __a1, _Args&& ...__args)
1758{
1759 __node_allocator& __na = __tree_.__node_alloc();
1760 __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
1761 __node_traits::construct(__na, _VSTD::addressof(__h->__value_),
1762 _VSTD::forward<_A0>(__a0), _VSTD::forward<_A1>(__a1),
1763 _VSTD::forward<_Args>(__args)...);
1764 __h.get_deleter().__first_constructed = true;
Howard Hinnantbc8d3f92010-05-11 19:42:161765 __h.get_deleter().__second_constructed = true;
1766 return __h;
1767}
1768
Howard Hinnant73d21a42010-09-04 23:28:191769#endif // _LIBCPP_HAS_NO_VARIADICS
1770#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:161771
Howard Hinnant73d21a42010-09-04 23:28:191772#if !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
Howard Hinnantbc8d3f92010-05-11 19:42:161773
1774template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant635ce1d2012-05-25 22:04:211775template <class ..._Args>
Howard Hinnantbc8d3f92010-05-11 19:42:161776typename multimap<_Key, _Tp, _Compare, _Allocator>::iterator
Howard Hinnant635ce1d2012-05-25 22:04:211777multimap<_Key, _Tp, _Compare, _Allocator>::emplace(_Args&& ...__args)
Howard Hinnantbc8d3f92010-05-11 19:42:161778{
Howard Hinnant635ce1d2012-05-25 22:04:211779 __node_holder __h = __construct_node(_VSTD::forward<_Args>(__args)...);
Howard Hinnantbc8d3f92010-05-11 19:42:161780 iterator __r = __tree_.__node_insert_multi(__h.get());
1781 __h.release();
1782 return __r;
1783}
1784
1785template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant635ce1d2012-05-25 22:04:211786template <class ..._Args>
Howard Hinnantbc8d3f92010-05-11 19:42:161787typename multimap<_Key, _Tp, _Compare, _Allocator>::iterator
1788multimap<_Key, _Tp, _Compare, _Allocator>::emplace_hint(const_iterator __p,
Howard Hinnantbc8d3f92010-05-11 19:42:161789 _Args&& ...__args)
1790{
Howard Hinnant635ce1d2012-05-25 22:04:211791 __node_holder __h = __construct_node(_VSTD::forward<_Args>(__args)...);
Howard Hinnantbc8d3f92010-05-11 19:42:161792 iterator __r = __tree_.__node_insert_multi(__p.__i_, __h.get());
1793 __h.release();
1794 return __r;
1795}
1796
Howard Hinnant73d21a42010-09-04 23:28:191797#endif // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
Howard Hinnantbc8d3f92010-05-11 19:42:161798
1799template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant82894812010-09-22 16:48:341800inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161801bool
1802operator==(const multimap<_Key, _Tp, _Compare, _Allocator>& __x,
1803 const multimap<_Key, _Tp, _Compare, _Allocator>& __y)
1804{
Howard Hinnant0949eed2011-06-30 21:18:191805 return __x.size() == __y.size() && _VSTD::equal(__x.begin(), __x.end(), __y.begin());
Howard Hinnantbc8d3f92010-05-11 19:42:161806}
1807
1808template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant82894812010-09-22 16:48:341809inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161810bool
1811operator< (const multimap<_Key, _Tp, _Compare, _Allocator>& __x,
1812 const multimap<_Key, _Tp, _Compare, _Allocator>& __y)
1813{
Howard Hinnant0949eed2011-06-30 21:18:191814 return _VSTD::lexicographical_compare(__x.begin(), __x.end(), __y.begin(), __y.end());
Howard Hinnantbc8d3f92010-05-11 19:42:161815}
1816
1817template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant82894812010-09-22 16:48:341818inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161819bool
1820operator!=(const multimap<_Key, _Tp, _Compare, _Allocator>& __x,
1821 const multimap<_Key, _Tp, _Compare, _Allocator>& __y)
1822{
1823 return !(__x == __y);
1824}
1825
1826template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant82894812010-09-22 16:48:341827inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161828bool
1829operator> (const multimap<_Key, _Tp, _Compare, _Allocator>& __x,
1830 const multimap<_Key, _Tp, _Compare, _Allocator>& __y)
1831{
1832 return __y < __x;
1833}
1834
1835template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant82894812010-09-22 16:48:341836inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161837bool
1838operator>=(const multimap<_Key, _Tp, _Compare, _Allocator>& __x,
1839 const multimap<_Key, _Tp, _Compare, _Allocator>& __y)
1840{
1841 return !(__x < __y);
1842}
1843
1844template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant82894812010-09-22 16:48:341845inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161846bool
1847operator<=(const multimap<_Key, _Tp, _Compare, _Allocator>& __x,
1848 const multimap<_Key, _Tp, _Compare, _Allocator>& __y)
1849{
1850 return !(__y < __x);
1851}
1852
1853template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant82894812010-09-22 16:48:341854inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161855void
1856swap(multimap<_Key, _Tp, _Compare, _Allocator>& __x,
1857 multimap<_Key, _Tp, _Compare, _Allocator>& __y)
Howard Hinnant7686add2011-06-04 14:31:571858 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
Howard Hinnantbc8d3f92010-05-11 19:42:161859{
1860 __x.swap(__y);
1861}
1862
1863_LIBCPP_END_NAMESPACE_STD
1864
1865#endif // _LIBCPP_MAP