blob: 953743a6c7409cfac32df8da7e99e79d53eb1af5 [file] [log] [blame]
Howard Hinnantc51e1022010-05-11 19:42:16 +00001// -*- C++ -*-
2//===----------------------------- map ------------------------------------===//
3//
Howard Hinnantc566dc32010-05-11 21:36:01 +00004// The LLVM Compiler Infrastructure
Howard Hinnantc51e1022010-05-11 19:42:16 +00005//
Howard Hinnantee11c312010-11-16 22:09:02 +00006// This file is dual licensed under the MIT and the University of Illinois Open
7// Source Licenses. See LICENSE.TXT for details.
Howard Hinnantc51e1022010-05-11 19:42:16 +00008//
9//===----------------------------------------------------------------------===//
10
11#ifndef _LIBCPP_MAP
12#define _LIBCPP_MAP
13
14/*
15
16 map synopsis
17
18namespace std
19{
20
21template <class Key, class T, class Compare = less<Key>,
22 class Allocator = allocator<pair<const Key, T>>>
23class map
24{
25public:
26 // types:
27 typedef Key key_type;
28 typedef T mapped_type;
29 typedef pair<const key_type, mapped_type> value_type;
30 typedef Compare key_compare;
31 typedef Allocator allocator_type;
32 typedef typename allocator_type::reference reference;
33 typedef typename allocator_type::const_reference const_reference;
34 typedef typename allocator_type::pointer pointer;
35 typedef typename allocator_type::const_pointer const_pointer;
36 typedef typename allocator_type::size_type size_type;
37 typedef typename allocator_type::difference_type difference_type;
38
39 typedef implementation-defined iterator;
40 typedef implementation-defined const_iterator;
41 typedef std::reverse_iterator<iterator> reverse_iterator;
42 typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
43
44 class value_compare
45 : public binary_function<value_type, value_type, bool>
46 {
47 friend class map;
48 protected:
49 key_compare comp;
50
51 value_compare(key_compare c);
52 public:
53 bool operator()(const value_type& x, const value_type& y) const;
54 };
55
56 // construct/copy/destroy:
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +000057 map()
58 noexcept(
59 is_nothrow_default_constructible<allocator_type>::value &&
60 is_nothrow_default_constructible<key_compare>::value &&
61 is_nothrow_copy_constructible<key_compare>::value);
Howard Hinnantc51e1022010-05-11 19:42:16 +000062 explicit map(const key_compare& comp);
63 map(const key_compare& comp, const allocator_type& a);
64 template <class InputIterator>
65 map(InputIterator first, InputIterator last,
66 const key_compare& comp = key_compare());
67 template <class InputIterator>
68 map(InputIterator first, InputIterator last,
69 const key_compare& comp, const allocator_type& a);
70 map(const map& m);
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +000071 map(map&& m)
72 noexcept(
73 is_nothrow_move_constructible<allocator_type>::value &&
74 is_nothrow_move_constructible<key_compare>::value);
Howard Hinnantc51e1022010-05-11 19:42:16 +000075 explicit map(const allocator_type& a);
76 map(const map& m, const allocator_type& a);
77 map(map&& m, const allocator_type& a);
78 map(initializer_list<value_type> il, const key_compare& comp = key_compare());
79 map(initializer_list<value_type> il, const key_compare& comp, const allocator_type& a);
80 ~map();
81
82 map& operator=(const map& m);
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +000083 map& operator=(map&& m)
84 noexcept(
85 allocator_type::propagate_on_container_move_assignment::value &&
86 is_nothrow_move_assignable<allocator_type>::value &&
Howard Hinnantf95f4f52011-06-04 15:22:34 +000087 is_nothrow_move_assignable<key_compare>::value);
Howard Hinnantc51e1022010-05-11 19:42:16 +000088 map& operator=(initializer_list<value_type> il);
89
90 // iterators:
Howard Hinnantf95f4f52011-06-04 15:22:34 +000091 iterator begin() noexcept;
92 const_iterator begin() const noexcept;
93 iterator end() noexcept;
94 const_iterator end() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +000095
Howard Hinnantf95f4f52011-06-04 15:22:34 +000096 reverse_iterator rbegin() noexcept;
97 const_reverse_iterator rbegin() const noexcept;
98 reverse_iterator rend() noexcept;
99 const_reverse_iterator rend() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000100
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000101 const_iterator cbegin() const noexcept;
102 const_iterator cend() const noexcept;
103 const_reverse_iterator crbegin() const noexcept;
104 const_reverse_iterator crend() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000105
106 // capacity:
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000107 bool empty() const noexcept;
108 size_type size() const noexcept;
109 size_type max_size() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000110
111 // element access:
112 mapped_type& operator[](const key_type& k);
113 mapped_type& operator[](key_type&& k);
114
115 mapped_type& at(const key_type& k);
116 const mapped_type& at(const key_type& k) const;
117
118 // modifiers:
119 template <class... Args>
120 pair<iterator, bool> emplace(Args&&... args);
121 template <class... Args>
122 iterator emplace_hint(const_iterator position, Args&&... args);
123 pair<iterator, bool> insert(const value_type& v);
124 template <class P>
125 pair<iterator, bool> insert(P&& p);
126 iterator insert(const_iterator position, const value_type& v);
127 template <class P>
128 iterator insert(const_iterator position, P&& p);
129 template <class InputIterator>
130 void insert(InputIterator first, InputIterator last);
131 void insert(initializer_list<value_type> il);
132
133 iterator erase(const_iterator position);
134 size_type erase(const key_type& k);
135 iterator erase(const_iterator first, const_iterator last);
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000136 void clear() noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000137
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000138 void swap(map& m)
139 noexcept(
140 __is_nothrow_swappable<key_compare>::value &&
141 (!allocator_type::propagate_on_container_swap::value ||
142 __is_nothrow_swappable<allocator_type>::value));
Howard Hinnantc51e1022010-05-11 19:42:16 +0000143
144 // observers:
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000145 allocator_type get_allocator() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000146 key_compare key_comp() const;
147 value_compare value_comp() const;
148
149 // map operations:
150 iterator find(const key_type& k);
151 const_iterator find(const key_type& k) const;
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 Hinnant2f1ea9c2011-06-04 14:31:57 +0000194swap(map<Key, T, Compare, Allocator>& x, map<Key, T, Compare, Allocator>& y)
195 noexcept(noexcept(x.swap(y)));
Howard Hinnantc51e1022010-05-11 19:42:16 +0000196
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 Hinnant2f1ea9c2011-06-04 14:31:57 +0000232 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 Hinnantc51e1022010-05-11 19:42:16 +0000238 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 Hinnant2f1ea9c2011-06-04 14:31:57 +0000245 multimap(multimap&& m)
246 noexcept(
247 is_nothrow_move_constructible<allocator_type>::value &&
248 is_nothrow_move_constructible<key_compare>::value);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000249 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 Hinnant2f1ea9c2011-06-04 14:31:57 +0000258 multimap& operator=(multimap&& m)
259 noexcept(
260 allocator_type::propagate_on_container_move_assignment::value &&
261 is_nothrow_move_assignable<allocator_type>::value &&
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000262 is_nothrow_move_assignable<key_compare>::value);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000263 multimap& operator=(initializer_list<value_type> il);
264
265 // iterators:
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000266 iterator begin() noexcept;
267 const_iterator begin() const noexcept;
268 iterator end() noexcept;
269 const_iterator end() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000270
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000271 reverse_iterator rbegin() noexcept;
272 const_reverse_iterator rbegin() const noexcept;
273 reverse_iterator rend() noexcept;
274 const_reverse_iterator rend() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000275
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000276 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 Hinnantc51e1022010-05-11 19:42:16 +0000280
281 // capacity:
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000282 bool empty() const noexcept;
283 size_type size() const noexcept;
284 size_type max_size() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000285
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 Hinnantf95f4f52011-06-04 15:22:34 +0000304 void clear() noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000305
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000306 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 Hinnantc51e1022010-05-11 19:42:16 +0000311
312 // observers:
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000313 allocator_type get_allocator() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000314 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 Hinnant2f1ea9c2011-06-04 14:31:57 +0000363 multimap<Key, T, Compare, Allocator>& y)
364 noexcept(noexcept(x.swap(y)));
Howard Hinnantc51e1022010-05-11 19:42:16 +0000365
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 Hinnantaaaa52b2011-10-17 20:05:10 +0000378#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000379#pragma GCC system_header
Howard Hinnantaaaa52b2011-10-17 20:05:10 +0000380#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000381
382_LIBCPP_BEGIN_NAMESPACE_STD
383
Howard Hinnant90b91592013-07-05 18:06:00 +0000384template <class _Key, class _CP, class _Compare, bool = is_empty<_Compare>::value
Howard Hinnantd0aabf82011-12-11 20:31:33 +0000385#if __has_feature(is_final)
386 && !__is_final(_Compare)
387#endif
388 >
Howard Hinnantc51e1022010-05-11 19:42:16 +0000389class __map_value_compare
390 : private _Compare
391{
Howard Hinnantc51e1022010-05-11 19:42:16 +0000392public:
Howard Hinnant756c69b2010-09-22 16:48:34 +0000393 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000394 __map_value_compare()
395 _NOEXCEPT_(is_nothrow_default_constructible<_Compare>::value)
396 : _Compare() {}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000397 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000398 __map_value_compare(_Compare c)
399 _NOEXCEPT_(is_nothrow_copy_constructible<_Compare>::value)
400 : _Compare(c) {}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000401 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000402 const _Compare& key_comp() const _NOEXCEPT {return *this;}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000403 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000404 bool operator()(const _CP& __x, const _CP& __y) const
Howard Hinnant90b91592013-07-05 18:06:00 +0000405 {return static_cast<const _Compare&>(*this)(__x.__cc.first, __y.__cc.first);}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000406 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000407 bool operator()(const _CP& __x, const _Key& __y) const
Howard Hinnant90b91592013-07-05 18:06:00 +0000408 {return static_cast<const _Compare&>(*this)(__x.__cc.first, __y);}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000409 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000410 bool operator()(const _Key& __x, const _CP& __y) const
Howard Hinnant90b91592013-07-05 18:06:00 +0000411 {return static_cast<const _Compare&>(*this)(__x, __y.__cc.first);}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000412};
413
Howard Hinnant90b91592013-07-05 18:06:00 +0000414template <class _Key, class _CP, class _Compare>
415class __map_value_compare<_Key, _CP, _Compare, false>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000416{
417 _Compare comp;
418
Howard Hinnantc51e1022010-05-11 19:42:16 +0000419public:
Howard Hinnant756c69b2010-09-22 16:48:34 +0000420 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000421 __map_value_compare()
422 _NOEXCEPT_(is_nothrow_default_constructible<_Compare>::value)
423 : comp() {}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000424 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000425 __map_value_compare(_Compare c)
426 _NOEXCEPT_(is_nothrow_copy_constructible<_Compare>::value)
427 : comp(c) {}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000428 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000429 const _Compare& key_comp() const _NOEXCEPT {return comp;}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000430
Howard Hinnant756c69b2010-09-22 16:48:34 +0000431 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000432 bool operator()(const _CP& __x, const _CP& __y) const
Howard Hinnant90b91592013-07-05 18:06:00 +0000433 {return comp(__x.__cc.first, __y.__cc.first);}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000434 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000435 bool operator()(const _CP& __x, const _Key& __y) const
Howard Hinnant90b91592013-07-05 18:06:00 +0000436 {return comp(__x.__cc.first, __y);}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000437 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000438 bool operator()(const _Key& __x, const _CP& __y) const
Howard Hinnant90b91592013-07-05 18:06:00 +0000439 {return comp(__x, __y.__cc.first);}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000440};
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 Hinnant2d0046b2013-06-19 21:29:40 +0000451 typedef typename value_type::value_type::first_type first_type;
452 typedef typename value_type::value_type::second_type second_type;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000453
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 Hinnant756c69b2010-09-22 16:48:34 +0000462 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000463 explicit __map_node_destructor(allocator_type& __na) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +0000464 : __na_(__na),
465 __first_constructed(false),
466 __second_constructed(false)
467 {}
468
Howard Hinnant74279a52010-09-04 23:28:19 +0000469#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant756c69b2010-09-22 16:48:34 +0000470 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000471 __map_node_destructor(__tree_node_destructor<allocator_type>&& __x) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +0000472 : __na_(__x.__na_),
473 __first_constructed(__x.__value_constructed),
474 __second_constructed(__x.__value_constructed)
475 {
476 __x.__value_constructed = false;
477 }
Howard Hinnant5dc89112010-09-04 23:46:48 +0000478#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +0000479
Howard Hinnant756c69b2010-09-22 16:48:34 +0000480 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000481 void operator()(pointer __p) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +0000482 {
483 if (__second_constructed)
Howard Hinnant2d0046b2013-06-19 21:29:40 +0000484 __alloc_traits::destroy(__na_, _VSTD::addressof(__p->__value_.__cc.second));
Howard Hinnantc51e1022010-05-11 19:42:16 +0000485 if (__first_constructed)
Howard Hinnant2d0046b2013-06-19 21:29:40 +0000486 __alloc_traits::destroy(__na_, _VSTD::addressof(__p->__value_.__cc.first));
Howard Hinnantc51e1022010-05-11 19:42:16 +0000487 if (__p)
488 __alloc_traits::deallocate(__na_, __p, 1);
489 }
490};
491
Howard Hinnant944510a2011-06-14 19:58:17 +0000492template <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 Hinnantc51e1022010-05-11 19:42:16 +0000497
498template <class _TreeIterator>
Howard Hinnant8331b762013-03-06 23:30:19 +0000499class _LIBCPP_TYPE_VIS __map_iterator
Howard Hinnantc51e1022010-05-11 19:42:16 +0000500{
501 _TreeIterator __i_;
502
503 typedef typename _TreeIterator::__pointer_traits __pointer_traits;
Howard Hinnant2d0046b2013-06-19 21:29:40 +0000504 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 Hinnantc51e1022010-05-11 19:42:16 +0000506public:
507 typedef bidirectional_iterator_tag iterator_category;
Howard Hinnantb2e8a422011-02-27 18:02:02 +0000508 typedef pair<__key_type, __mapped_type> value_type;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000509 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 Hinnant756c69b2010-09-22 16:48:34 +0000519 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000520 __map_iterator() _NOEXCEPT {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000521
Howard Hinnant756c69b2010-09-22 16:48:34 +0000522 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000523 __map_iterator(_TreeIterator __i) _NOEXCEPT : __i_(__i) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000524
Howard Hinnant756c69b2010-09-22 16:48:34 +0000525 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2d0046b2013-06-19 21:29:40 +0000526 reference operator*() const {return __i_->__cc;}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000527 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2d0046b2013-06-19 21:29:40 +0000528 pointer operator->() const {return pointer_traits<pointer>::pointer_to(__i_->__cc);}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000529
Howard Hinnant756c69b2010-09-22 16:48:34 +0000530 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000531 __map_iterator& operator++() {++__i_; return *this;}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000532 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000533 __map_iterator operator++(int)
534 {
535 __map_iterator __t(*this);
536 ++(*this);
537 return __t;
538 }
539
Howard Hinnant756c69b2010-09-22 16:48:34 +0000540 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000541 __map_iterator& operator--() {--__i_; return *this;}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000542 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000543 __map_iterator operator--(int)
544 {
545 __map_iterator __t(*this);
546 --(*this);
547 return __t;
548 }
549
Howard Hinnant756c69b2010-09-22 16:48:34 +0000550 friend _LIBCPP_INLINE_VISIBILITY
551 bool operator==(const __map_iterator& __x, const __map_iterator& __y)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000552 {return __x.__i_ == __y.__i_;}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000553 friend
554 _LIBCPP_INLINE_VISIBILITY
555 bool operator!=(const __map_iterator& __x, const __map_iterator& __y)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000556 {return __x.__i_ != __y.__i_;}
557
Howard Hinnant8331b762013-03-06 23:30:19 +0000558 template <class, class, class, class> friend class _LIBCPP_TYPE_VIS map;
559 template <class, class, class, class> friend class _LIBCPP_TYPE_VIS multimap;
560 template <class> friend class _LIBCPP_TYPE_VIS __map_const_iterator;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000561};
562
563template <class _TreeIterator>
Howard Hinnant8331b762013-03-06 23:30:19 +0000564class _LIBCPP_TYPE_VIS __map_const_iterator
Howard Hinnantc51e1022010-05-11 19:42:16 +0000565{
566 _TreeIterator __i_;
567
568 typedef typename _TreeIterator::__pointer_traits __pointer_traits;
Howard Hinnant2d0046b2013-06-19 21:29:40 +0000569 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 Hinnantc51e1022010-05-11 19:42:16 +0000571public:
572 typedef bidirectional_iterator_tag iterator_category;
Howard Hinnantb2e8a422011-02-27 18:02:02 +0000573 typedef pair<__key_type, __mapped_type> value_type;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000574 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 Hinnant73f3c8a2011-04-11 02:18:41 +0000578 rebind<const value_type>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000579#else
Howard Hinnant73f3c8a2011-04-11 02:18:41 +0000580 rebind<const value_type>::other
Howard Hinnantc51e1022010-05-11 19:42:16 +0000581#endif
582 pointer;
583
Howard Hinnant756c69b2010-09-22 16:48:34 +0000584 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000585 __map_const_iterator() _NOEXCEPT {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000586
Howard Hinnant756c69b2010-09-22 16:48:34 +0000587 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000588 __map_const_iterator(_TreeIterator __i) _NOEXCEPT : __i_(__i) {}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000589 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000590 __map_const_iterator(
591 __map_iterator<typename _TreeIterator::__non_const_iterator> __i)
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000592 _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +0000593 : __i_(__i.__i_) {}
594
Howard Hinnant756c69b2010-09-22 16:48:34 +0000595 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2d0046b2013-06-19 21:29:40 +0000596 reference operator*() const {return __i_->__cc;}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000597 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2d0046b2013-06-19 21:29:40 +0000598 pointer operator->() const {return pointer_traits<pointer>::pointer_to(__i_->__cc);}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000599
Howard Hinnant756c69b2010-09-22 16:48:34 +0000600 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000601 __map_const_iterator& operator++() {++__i_; return *this;}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000602 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000603 __map_const_iterator operator++(int)
604 {
605 __map_const_iterator __t(*this);
606 ++(*this);
607 return __t;
608 }
609
Howard Hinnant756c69b2010-09-22 16:48:34 +0000610 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000611 __map_const_iterator& operator--() {--__i_; return *this;}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000612 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000613 __map_const_iterator operator--(int)
614 {
615 __map_const_iterator __t(*this);
616 --(*this);
617 return __t;
618 }
619
Howard Hinnant756c69b2010-09-22 16:48:34 +0000620 friend _LIBCPP_INLINE_VISIBILITY
621 bool operator==(const __map_const_iterator& __x, const __map_const_iterator& __y)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000622 {return __x.__i_ == __y.__i_;}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000623 friend _LIBCPP_INLINE_VISIBILITY
624 bool operator!=(const __map_const_iterator& __x, const __map_const_iterator& __y)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000625 {return __x.__i_ != __y.__i_;}
626
Howard Hinnant8331b762013-03-06 23:30:19 +0000627 template <class, class, class, class> friend class _LIBCPP_TYPE_VIS map;
628 template <class, class, class, class> friend class _LIBCPP_TYPE_VIS multimap;
629 template <class, class, class> friend class _LIBCPP_TYPE_VIS __tree_const_iterator;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000630};
631
632template <class _Key, class _Tp, class _Compare = less<_Key>,
633 class _Allocator = allocator<pair<const _Key, _Tp> > >
Howard Hinnant8331b762013-03-06 23:30:19 +0000634class _LIBCPP_TYPE_VIS map
Howard Hinnantc51e1022010-05-11 19:42:16 +0000635{
636public:
637 // types:
638 typedef _Key key_type;
639 typedef _Tp mapped_type;
640 typedef pair<const key_type, mapped_type> value_type;
Howard Hinnant2d0046b2013-06-19 21:29:40 +0000641 typedef pair<key_type, mapped_type> __nc_value_type;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000642 typedef _Compare key_compare;
643 typedef _Allocator allocator_type;
644 typedef value_type& reference;
645 typedef const value_type& const_reference;
646
Howard Hinnant8331b762013-03-06 23:30:19 +0000647 class _LIBCPP_TYPE_VIS value_compare
Howard Hinnantc51e1022010-05-11 19:42:16 +0000648 : public binary_function<value_type, value_type, bool>
649 {
650 friend class map;
651 protected:
652 key_compare comp;
653
Howard Hinnant756c69b2010-09-22 16:48:34 +0000654 _LIBCPP_INLINE_VISIBILITY value_compare(key_compare c) : comp(c) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000655 public:
Howard Hinnant756c69b2010-09-22 16:48:34 +0000656 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000657 bool operator()(const value_type& __x, const value_type& __y) const
658 {return comp(__x.first, __y.first);}
659 };
660
661private:
Howard Hinnant2d0046b2013-06-19 21:29:40 +0000662
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 Hinnant2d0046b2013-06-19 21:29:40 +0000688 };
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 Hinnant2d0046b2013-06-19 21:29:40 +0000704 };
705#endif
Howard Hinnant90b91592013-07-05 18:06:00 +0000706 typedef __map_value_compare<key_type, __value_type, key_compare> __vc;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000707 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 Hinnantb1ad5a82011-06-30 21:18:19 +0000727 typedef _VSTD::reverse_iterator<iterator> reverse_iterator;
728 typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000729
Howard Hinnant756c69b2010-09-22 16:48:34 +0000730 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000731 explicit map(const key_compare& __comp = key_compare())
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000732 _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 Hinnantc51e1022010-05-11 19:42:16 +0000736 : __tree_(__vc(__comp)) {}
737
Howard Hinnant756c69b2010-09-22 16:48:34 +0000738 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000739 explicit map(const key_compare& __comp, const allocator_type& __a)
740 : __tree_(__vc(__comp), __a) {}
741
742 template <class _InputIterator>
Howard Hinnant756c69b2010-09-22 16:48:34 +0000743 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000744 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 Hinnant756c69b2010-09-22 16:48:34 +0000752 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000753 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 Hinnant756c69b2010-09-22 16:48:34 +0000760 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000761 map(const map& __m)
762 : __tree_(__m.__tree_)
763 {
764 insert(__m.begin(), __m.end());
765 }
766
Howard Hinnantd3a657f2011-07-01 19:24:36 +0000767 _LIBCPP_INLINE_VISIBILITY
768 map& operator=(const map& __m)
769 {
Howard Hinnant2d0046b2013-06-19 21:29:40 +0000770#if __cplusplus >= 201103L
Howard Hinnantd3a657f2011-07-01 19:24:36 +0000771 __tree_ = __m.__tree_;
Howard Hinnant2d0046b2013-06-19 21:29:40 +0000772#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 Hinnantd3a657f2011-07-01 19:24:36 +0000778 return *this;
779 }
780
Howard Hinnant74279a52010-09-04 23:28:19 +0000781#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +0000782
Howard Hinnant756c69b2010-09-22 16:48:34 +0000783 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000784 map(map&& __m)
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000785 _NOEXCEPT_(is_nothrow_move_constructible<__base>::value)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000786 : __tree_(_VSTD::move(__m.__tree_))
Howard Hinnantc51e1022010-05-11 19:42:16 +0000787 {
788 }
789
790 map(map&& __m, const allocator_type& __a);
791
Howard Hinnant756c69b2010-09-22 16:48:34 +0000792 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant33711792011-08-12 21:56:02 +0000793 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 Hinnantc51e1022010-05-11 19:42:16 +0000805 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 Hinnant756c69b2010-09-22 16:48:34 +0000811 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000812 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 Hinnant756c69b2010-09-22 16:48:34 +0000818 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000819 map& operator=(initializer_list<value_type> __il)
820 {
821 __tree_.__assign_unique(__il.begin(), __il.end());
822 return *this;
823 }
824
Howard Hinnant33711792011-08-12 21:56:02 +0000825#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000826
Howard Hinnant756c69b2010-09-22 16:48:34 +0000827 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000828 explicit map(const allocator_type& __a)
829 : __tree_(__a)
830 {
831 }
832
Howard Hinnant756c69b2010-09-22 16:48:34 +0000833 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000834 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 Hinnant756c69b2010-09-22 16:48:34 +0000840 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000841 iterator begin() _NOEXCEPT {return __tree_.begin();}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000842 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000843 const_iterator begin() const _NOEXCEPT {return __tree_.begin();}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000844 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000845 iterator end() _NOEXCEPT {return __tree_.end();}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000846 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000847 const_iterator end() const _NOEXCEPT {return __tree_.end();}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000848
Howard Hinnant756c69b2010-09-22 16:48:34 +0000849 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000850 reverse_iterator rbegin() _NOEXCEPT {return reverse_iterator(end());}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000851 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000852 const_reverse_iterator rbegin() const _NOEXCEPT
853 {return const_reverse_iterator(end());}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000854 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000855 reverse_iterator rend() _NOEXCEPT
856 {return reverse_iterator(begin());}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000857 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000858 const_reverse_iterator rend() const _NOEXCEPT
859 {return const_reverse_iterator(begin());}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000860
Howard Hinnant756c69b2010-09-22 16:48:34 +0000861 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000862 const_iterator cbegin() const _NOEXCEPT {return begin();}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000863 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000864 const_iterator cend() const _NOEXCEPT {return end();}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000865 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000866 const_reverse_iterator crbegin() const _NOEXCEPT {return rbegin();}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000867 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000868 const_reverse_iterator crend() const _NOEXCEPT {return rend();}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000869
Howard Hinnant756c69b2010-09-22 16:48:34 +0000870 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000871 bool empty() const _NOEXCEPT {return __tree_.size() == 0;}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000872 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000873 size_type size() const _NOEXCEPT {return __tree_.size();}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000874 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000875 size_type max_size() const _NOEXCEPT {return __tree_.max_size();}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000876
877 mapped_type& operator[](const key_type& __k);
Howard Hinnant74279a52010-09-04 23:28:19 +0000878#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +0000879 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 Hinnant756c69b2010-09-22 16:48:34 +0000885 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000886 allocator_type get_allocator() const _NOEXCEPT {return __tree_.__alloc();}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000887 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000888 key_compare key_comp() const {return __tree_.value_comp().key_comp();}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000889 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000890 value_compare value_comp() const {return value_compare(__tree_.value_comp().key_comp());}
891
Howard Hinnant74279a52010-09-04 23:28:19 +0000892#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant74279a52010-09-04 23:28:19 +0000893#ifndef _LIBCPP_HAS_NO_VARIADICS
894
Howard Hinnant29eb9b82012-05-25 22:04:21 +0000895 template <class ..._Args>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000896 pair<iterator, bool>
Howard Hinnant29eb9b82012-05-25 22:04:21 +0000897 emplace(_Args&& ...__args);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000898
Howard Hinnant29eb9b82012-05-25 22:04:21 +0000899 template <class ..._Args>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000900 iterator
Howard Hinnant29eb9b82012-05-25 22:04:21 +0000901 emplace_hint(const_iterator __p, _Args&& ...__args);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000902
Howard Hinnant74279a52010-09-04 23:28:19 +0000903#endif // _LIBCPP_HAS_NO_VARIADICS
904
Howard Hinnantc834c512011-11-29 18:15:50 +0000905 template <class _Pp,
906 class = typename enable_if<is_constructible<value_type, _Pp>::value>::type>
Howard Hinnant756c69b2010-09-22 16:48:34 +0000907 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc834c512011-11-29 18:15:50 +0000908 pair<iterator, bool> insert(_Pp&& __p)
909 {return __tree_.__insert_unique(_VSTD::forward<_Pp>(__p));}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000910
Howard Hinnantc834c512011-11-29 18:15:50 +0000911 template <class _Pp,
912 class = typename enable_if<is_constructible<value_type, _Pp>::value>::type>
Howard Hinnant756c69b2010-09-22 16:48:34 +0000913 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc834c512011-11-29 18:15:50 +0000914 iterator insert(const_iterator __pos, _Pp&& __p)
915 {return __tree_.__insert_unique(__pos.__i_, _VSTD::forward<_Pp>(__p));}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000916
Howard Hinnant74279a52010-09-04 23:28:19 +0000917#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +0000918
Howard Hinnant756c69b2010-09-22 16:48:34 +0000919 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000920 pair<iterator, bool>
921 insert(const value_type& __v) {return __tree_.__insert_unique(__v);}
922
Howard Hinnant756c69b2010-09-22 16:48:34 +0000923 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000924 iterator
925 insert(const_iterator __p, const value_type& __v)
926 {return __tree_.__insert_unique(__p.__i_, __v);}
927
928 template <class _InputIterator>
Howard Hinnant756c69b2010-09-22 16:48:34 +0000929 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000930 void insert(_InputIterator __f, _InputIterator __l)
931 {
932 for (const_iterator __e = cend(); __f != __l; ++__f)
933 insert(__e.__i_, *__f);
934 }
935
Howard Hinnant33711792011-08-12 21:56:02 +0000936#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
937
Howard Hinnant756c69b2010-09-22 16:48:34 +0000938 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000939 void insert(initializer_list<value_type> __il)
940 {insert(__il.begin(), __il.end());}
941
Howard Hinnant33711792011-08-12 21:56:02 +0000942#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
943
Howard Hinnant756c69b2010-09-22 16:48:34 +0000944 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000945 iterator erase(const_iterator __p) {return __tree_.erase(__p.__i_);}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000946 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000947 size_type erase(const key_type& __k)
948 {return __tree_.__erase_unique(__k);}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000949 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000950 iterator erase(const_iterator __f, const_iterator __l)
951 {return __tree_.erase(__f.__i_, __l.__i_);}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000952 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000953 void clear() _NOEXCEPT {__tree_.clear();}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000954
Howard Hinnant756c69b2010-09-22 16:48:34 +0000955 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000956 void swap(map& __m)
957 _NOEXCEPT_(__is_nothrow_swappable<__base>::value)
958 {__tree_.swap(__m.__tree_);}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000959
Howard Hinnant756c69b2010-09-22 16:48:34 +0000960 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000961 iterator find(const key_type& __k) {return __tree_.find(__k);}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000962 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000963 const_iterator find(const key_type& __k) const {return __tree_.find(__k);}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000964 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000965 size_type count(const key_type& __k) const
966 {return __tree_.__count_unique(__k);}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000967 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000968 iterator lower_bound(const key_type& __k)
969 {return __tree_.lower_bound(__k);}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000970 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000971 const_iterator lower_bound(const key_type& __k) const
972 {return __tree_.lower_bound(__k);}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000973 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000974 iterator upper_bound(const key_type& __k)
975 {return __tree_.upper_bound(__k);}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000976 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000977 const_iterator upper_bound(const key_type& __k) const
978 {return __tree_.upper_bound(__k);}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000979 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000980 pair<iterator,iterator> equal_range(const key_type& __k)
981 {return __tree_.__equal_range_unique(__k);}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000982 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000983 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 Hinnantc834c512011-11-29 18:15:50 +0000993 typedef __map_node_destructor<__node_allocator> _Dp;
994 typedef unique_ptr<__node, _Dp> __node_holder;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000995
Howard Hinnant74279a52010-09-04 23:28:19 +0000996#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +0000997 __node_holder __construct_node();
Howard Hinnant29eb9b82012-05-25 22:04:21 +0000998 template <class _A0>
Howard Hinnantac7e7482013-07-04 20:59:16 +0000999 __node_holder __construct_node(_A0&& __a0);
1000 __node_holder __construct_node_with_key(key_type&& __k);
Howard Hinnant74279a52010-09-04 23:28:19 +00001001#ifndef _LIBCPP_HAS_NO_VARIADICS
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001002 template <class _A0, class _A1, class ..._Args>
1003 __node_holder __construct_node(_A0&& __a0, _A1&& __a1, _Args&& ...__args);
Howard Hinnant74279a52010-09-04 23:28:19 +00001004#endif // _LIBCPP_HAS_NO_VARIADICS
Howard Hinnantc51e1022010-05-11 19:42:16 +00001005#endif
Howard Hinnantac7e7482013-07-04 20:59:16 +00001006 __node_holder __construct_node_with_key(const key_type& __k);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001007
1008 __node_base_pointer&
1009 __find_equal_key(__node_base_pointer& __parent, const key_type& __k);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001010 __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 Hinnant2d0046b2013-06-19 21:29:40 +00001028 if (__tree_.value_comp().key_comp()(__k, __nd->__value_.__cc.first))
Howard Hinnantc51e1022010-05-11 19:42:16 +00001029 {
1030 if (__nd->__left_ != nullptr)
1031 __nd = static_cast<__node_pointer>(__nd->__left_);
1032 else
1033 {
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001034 __parent = static_cast<__node_base_pointer>(__nd);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001035 return __parent->__left_;
1036 }
1037 }
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001038 else if (__tree_.value_comp().key_comp()(__nd->__value_.__cc.first, __k))
Howard Hinnantc51e1022010-05-11 19:42:16 +00001039 {
1040 if (__nd->__right_ != nullptr)
1041 __nd = static_cast<__node_pointer>(__nd->__right_);
1042 else
1043 {
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001044 __parent = static_cast<__node_base_pointer>(__nd);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001045 return __parent->__right_;
1046 }
1047 }
1048 else
1049 {
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001050 __parent = static_cast<__node_base_pointer>(__nd);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001051 return __parent;
1052 }
1053 }
1054 }
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001055 __parent = static_cast<__node_base_pointer>(__tree_.__end_node());
Howard Hinnantc51e1022010-05-11 19:42:16 +00001056 return __parent->__left_;
1057}
1058
Howard Hinnantc51e1022010-05-11 19:42:16 +00001059// 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 Hinnant2d0046b2013-06-19 21:29:40 +00001073 if (__tree_.value_comp().key_comp()(__k, __nd->__value_.__cc.first))
Howard Hinnantc51e1022010-05-11 19:42:16 +00001074 {
1075 if (__nd->__left_ != nullptr)
1076 __nd = static_cast<__node_pointer>(__nd->__left_);
1077 else
1078 {
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001079 __parent = static_cast<__node_base_pointer>(__nd);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001080 return const_cast<const __node_base_const_pointer&>(__parent->__left_);
1081 }
1082 }
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001083 else if (__tree_.value_comp().key_comp()(__nd->__value_.__cc.first, __k))
Howard Hinnantc51e1022010-05-11 19:42:16 +00001084 {
1085 if (__nd->__right_ != nullptr)
1086 __nd = static_cast<__node_pointer>(__nd->__right_);
1087 else
1088 {
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001089 __parent = static_cast<__node_base_pointer>(__nd);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001090 return const_cast<const __node_base_const_pointer&>(__parent->__right_);
1091 }
1092 }
1093 else
1094 {
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001095 __parent = static_cast<__node_base_pointer>(__nd);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001096 return __parent;
1097 }
1098 }
1099 }
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001100 __parent = static_cast<__node_base_pointer>(__tree_.__end_node());
Howard Hinnantc51e1022010-05-11 19:42:16 +00001101 return const_cast<const __node_base_const_pointer&>(__parent->__left_);
1102}
1103
Howard Hinnant74279a52010-09-04 23:28:19 +00001104#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +00001105
1106template <class _Key, class _Tp, class _Compare, class _Allocator>
1107map<_Key, _Tp, _Compare, _Allocator>::map(map&& __m, const allocator_type& __a)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001108 : __tree_(_VSTD::move(__m.__tree_), __a)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001109{
1110 if (__a != __m.get_allocator())
1111 {
1112 const_iterator __e = cend();
1113 while (!__m.empty())
1114 __tree_.__insert_unique(__e.__i_,
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001115 _VSTD::move(__m.__tree_.remove(__m.begin().__i_)->__value_));
Howard Hinnantc51e1022010-05-11 19:42:16 +00001116 }
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 Hinnantc834c512011-11-29 18:15:50 +00001124 __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001125 __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__cc.first));
Howard Hinnantc51e1022010-05-11 19:42:16 +00001126 __h.get_deleter().__first_constructed = true;
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001127 __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__cc.second));
Howard Hinnantc51e1022010-05-11 19:42:16 +00001128 __h.get_deleter().__second_constructed = true;
1129 return __h;
1130}
1131
1132template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001133template <class _A0>
Howard Hinnantac7e7482013-07-04 20:59:16 +00001134typename map<_Key, _Tp, _Compare, _Allocator>::__node_holder
Howard Hinnantc51e1022010-05-11 19:42:16 +00001135map<_Key, _Tp, _Compare, _Allocator>::__construct_node(_A0&& __a0)
1136{
1137 __node_allocator& __na = __tree_.__node_alloc();
Howard Hinnantc834c512011-11-29 18:15:50 +00001138 __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001139 __node_traits::construct(__na, _VSTD::addressof(__h->__value_), _VSTD::forward<_A0>(__a0));
Howard Hinnantc51e1022010-05-11 19:42:16 +00001140 __h.get_deleter().__first_constructed = true;
1141 __h.get_deleter().__second_constructed = true;
1142 return __h;
1143}
1144
1145template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnantac7e7482013-07-04 20:59:16 +00001146typename map<_Key, _Tp, _Compare, _Allocator>::__node_holder
1147map<_Key, _Tp, _Compare, _Allocator>::__construct_node_with_key(key_type&& __k)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001148{
1149 __node_allocator& __na = __tree_.__node_alloc();
Howard Hinnantc834c512011-11-29 18:15:50 +00001150 __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
Howard Hinnantac7e7482013-07-04 20:59:16 +00001151 __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__cc.first), _VSTD::move(__k));
Howard Hinnantc51e1022010-05-11 19:42:16 +00001152 __h.get_deleter().__first_constructed = true;
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001153 __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__cc.second));
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001154 __h.get_deleter().__second_constructed = true;
Howard Hinnantac7e7482013-07-04 20:59:16 +00001155 return _VSTD::move(__h);
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001156}
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 Hinnantc51e1022010-05-11 19:42:16 +00001171 __h.get_deleter().__second_constructed = true;
1172 return __h;
1173}
1174
Howard Hinnant74279a52010-09-04 23:28:19 +00001175#endif // _LIBCPP_HAS_NO_VARIADICS
1176
Howard Hinnantac7e7482013-07-04 20:59:16 +00001177#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +00001178
1179template <class _Key, class _Tp, class _Compare, class _Allocator>
1180typename map<_Key, _Tp, _Compare, _Allocator>::__node_holder
Howard Hinnantac7e7482013-07-04 20:59:16 +00001181map<_Key, _Tp, _Compare, _Allocator>::__construct_node_with_key(const key_type& __k)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001182{
1183 __node_allocator& __na = __tree_.__node_alloc();
Howard Hinnantc834c512011-11-29 18:15:50 +00001184 __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001185 __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__cc.first), __k);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001186 __h.get_deleter().__first_constructed = true;
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001187 __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__cc.second));
Howard Hinnantc51e1022010-05-11 19:42:16 +00001188 __h.get_deleter().__second_constructed = true;
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001189 return _VSTD::move(__h);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001190}
1191
Howard Hinnantc51e1022010-05-11 19:42:16 +00001192template <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 Hinnantac7e7482013-07-04 20:59:16 +00001201 __node_holder __h = __construct_node_with_key(__k);
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001202 __tree_.__insert_node_at(__parent, __child, static_cast<__node_base_pointer>(__h.get()));
Howard Hinnantc51e1022010-05-11 19:42:16 +00001203 __r = __h.release();
1204 }
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001205 return __r->__value_.__cc.second;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001206}
1207
Howard Hinnant74279a52010-09-04 23:28:19 +00001208#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +00001209
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 Hinnantac7e7482013-07-04 20:59:16 +00001219 __node_holder __h = __construct_node_with_key(_VSTD::move(__k));
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001220 __tree_.__insert_node_at(__parent, __child, static_cast<__node_base_pointer>(__h.get()));
Howard Hinnantc51e1022010-05-11 19:42:16 +00001221 __r = __h.release();
1222 }
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001223 return __r->__value_.__cc.second;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001224}
1225
Howard Hinnant74279a52010-09-04 23:28:19 +00001226#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +00001227
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 Hinnant72f73582010-08-11 17:04:31 +00001234#ifndef _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +00001235 if (__child == nullptr)
1236 throw out_of_range("map::at: key not found");
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001237#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001238 return static_cast<__node_pointer>(__child)->__value_.__cc.second;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001239}
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 Hinnant72f73582010-08-11 17:04:31 +00001247#ifndef _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +00001248 if (__child == nullptr)
1249 throw out_of_range("map::at: key not found");
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001250#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001251 return static_cast<__node_const_pointer>(__child)->__value_.__cc.second;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001252}
1253
Howard Hinnant74279a52010-09-04 23:28:19 +00001254#if !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001255
1256template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001257template <class ..._Args>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001258pair<typename map<_Key, _Tp, _Compare, _Allocator>::iterator, bool>
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001259map<_Key, _Tp, _Compare, _Allocator>::emplace(_Args&& ...__args)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001260{
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001261 __node_holder __h = __construct_node(_VSTD::forward<_Args>(__args)...);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001262 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 Hinnant29eb9b82012-05-25 22:04:21 +00001269template <class ..._Args>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001270typename map<_Key, _Tp, _Compare, _Allocator>::iterator
1271map<_Key, _Tp, _Compare, _Allocator>::emplace_hint(const_iterator __p,
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001272 _Args&& ...__args)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001273{
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001274 __node_holder __h = __construct_node(_VSTD::forward<_Args>(__args)...);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001275 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 Hinnant74279a52010-09-04 23:28:19 +00001281#endif // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001282
1283template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001284inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001285bool
1286operator==(const map<_Key, _Tp, _Compare, _Allocator>& __x,
1287 const map<_Key, _Tp, _Compare, _Allocator>& __y)
1288{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001289 return __x.size() == __y.size() && _VSTD::equal(__x.begin(), __x.end(), __y.begin());
Howard Hinnantc51e1022010-05-11 19:42:16 +00001290}
1291
1292template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001293inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001294bool
1295operator< (const map<_Key, _Tp, _Compare, _Allocator>& __x,
1296 const map<_Key, _Tp, _Compare, _Allocator>& __y)
1297{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001298 return _VSTD::lexicographical_compare(__x.begin(), __x.end(), __y.begin(), __y.end());
Howard Hinnantc51e1022010-05-11 19:42:16 +00001299}
1300
1301template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001302inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001303bool
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 Hinnant756c69b2010-09-22 16:48:34 +00001311inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001312bool
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 Hinnant756c69b2010-09-22 16:48:34 +00001320inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001321bool
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 Hinnant756c69b2010-09-22 16:48:34 +00001329inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001330bool
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 Hinnant756c69b2010-09-22 16:48:34 +00001338inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001339void
1340swap(map<_Key, _Tp, _Compare, _Allocator>& __x,
1341 map<_Key, _Tp, _Compare, _Allocator>& __y)
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001342 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
Howard Hinnantc51e1022010-05-11 19:42:16 +00001343{
1344 __x.swap(__y);
1345}
1346
1347template <class _Key, class _Tp, class _Compare = less<_Key>,
1348 class _Allocator = allocator<pair<const _Key, _Tp> > >
Howard Hinnant8331b762013-03-06 23:30:19 +00001349class _LIBCPP_TYPE_VIS multimap
Howard Hinnantc51e1022010-05-11 19:42:16 +00001350{
1351public:
1352 // types:
1353 typedef _Key key_type;
1354 typedef _Tp mapped_type;
1355 typedef pair<const key_type, mapped_type> value_type;
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001356 typedef pair<key_type, mapped_type> __nc_value_type;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001357 typedef _Compare key_compare;
1358 typedef _Allocator allocator_type;
1359 typedef value_type& reference;
1360 typedef const value_type& const_reference;
1361
Howard Hinnant8331b762013-03-06 23:30:19 +00001362 class _LIBCPP_TYPE_VIS value_compare
Howard Hinnantc51e1022010-05-11 19:42:16 +00001363 : public binary_function<value_type, value_type, bool>
1364 {
1365 friend class multimap;
1366 protected:
1367 key_compare comp;
1368
Howard Hinnant756c69b2010-09-22 16:48:34 +00001369 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001370 value_compare(key_compare c) : comp(c) {}
1371 public:
Howard Hinnant756c69b2010-09-22 16:48:34 +00001372 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001373 bool operator()(const value_type& __x, const value_type& __y) const
1374 {return comp(__x.first, __y.first);}
1375 };
1376
1377private:
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001378#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 Hinnant2d0046b2013-06-19 21:29:40 +00001403 };
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 Hinnant2d0046b2013-06-19 21:29:40 +00001419 };
1420#endif
Howard Hinnant90b91592013-07-05 18:06:00 +00001421 typedef __map_value_compare<key_type, __value_type, key_compare> __vc;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001422 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 Hinnantb1ad5a82011-06-30 21:18:19 +00001442 typedef _VSTD::reverse_iterator<iterator> reverse_iterator;
1443 typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001444
Howard Hinnant756c69b2010-09-22 16:48:34 +00001445 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001446 explicit multimap(const key_compare& __comp = key_compare())
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001447 _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 Hinnantc51e1022010-05-11 19:42:16 +00001451 : __tree_(__vc(__comp)) {}
1452
Howard Hinnant756c69b2010-09-22 16:48:34 +00001453 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001454 explicit multimap(const key_compare& __comp, const allocator_type& __a)
1455 : __tree_(__vc(__comp), __a) {}
1456
1457 template <class _InputIterator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001458 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001459 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 Hinnant756c69b2010-09-22 16:48:34 +00001467 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001468 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 Hinnant756c69b2010-09-22 16:48:34 +00001475 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001476 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 Hinnantd3a657f2011-07-01 19:24:36 +00001483 _LIBCPP_INLINE_VISIBILITY
1484 multimap& operator=(const multimap& __m)
1485 {
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001486#if __cplusplus >= 201103L
Howard Hinnantd3a657f2011-07-01 19:24:36 +00001487 __tree_ = __m.__tree_;
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001488#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 Hinnantd3a657f2011-07-01 19:24:36 +00001494 return *this;
1495 }
1496
Howard Hinnant74279a52010-09-04 23:28:19 +00001497#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +00001498
Howard Hinnant756c69b2010-09-22 16:48:34 +00001499 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001500 multimap(multimap&& __m)
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001501 _NOEXCEPT_(is_nothrow_move_constructible<__base>::value)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001502 : __tree_(_VSTD::move(__m.__tree_))
Howard Hinnantc51e1022010-05-11 19:42:16 +00001503 {
1504 }
1505
1506 multimap(multimap&& __m, const allocator_type& __a);
1507
Howard Hinnant756c69b2010-09-22 16:48:34 +00001508 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant33711792011-08-12 21:56:02 +00001509 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 Hinnantc51e1022010-05-11 19:42:16 +00001521 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 Hinnant756c69b2010-09-22 16:48:34 +00001527 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001528 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 Hinnant756c69b2010-09-22 16:48:34 +00001534 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001535 multimap& operator=(initializer_list<value_type> __il)
1536 {
1537 __tree_.__assign_multi(__il.begin(), __il.end());
1538 return *this;
1539 }
Howard Hinnant33711792011-08-12 21:56:02 +00001540
1541#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantc51e1022010-05-11 19:42:16 +00001542
Howard Hinnant756c69b2010-09-22 16:48:34 +00001543 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001544 explicit multimap(const allocator_type& __a)
1545 : __tree_(__a)
1546 {
1547 }
1548
Howard Hinnant756c69b2010-09-22 16:48:34 +00001549 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001550 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 Hinnant756c69b2010-09-22 16:48:34 +00001556 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001557 iterator begin() _NOEXCEPT {return __tree_.begin();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001558 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001559 const_iterator begin() const _NOEXCEPT {return __tree_.begin();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001560 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001561 iterator end() _NOEXCEPT {return __tree_.end();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001562 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001563 const_iterator end() const _NOEXCEPT {return __tree_.end();}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001564
Howard Hinnant756c69b2010-09-22 16:48:34 +00001565 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001566 reverse_iterator rbegin() _NOEXCEPT {return reverse_iterator(end());}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001567 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001568 const_reverse_iterator rbegin() const _NOEXCEPT
1569 {return const_reverse_iterator(end());}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001570 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001571 reverse_iterator rend() _NOEXCEPT {return reverse_iterator(begin());}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001572 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001573 const_reverse_iterator rend() const _NOEXCEPT
1574 {return const_reverse_iterator(begin());}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001575
Howard Hinnant756c69b2010-09-22 16:48:34 +00001576 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001577 const_iterator cbegin() const _NOEXCEPT {return begin();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001578 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001579 const_iterator cend() const _NOEXCEPT {return end();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001580 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001581 const_reverse_iterator crbegin() const _NOEXCEPT {return rbegin();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001582 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001583 const_reverse_iterator crend() const _NOEXCEPT {return rend();}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001584
Howard Hinnant756c69b2010-09-22 16:48:34 +00001585 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001586 bool empty() const _NOEXCEPT {return __tree_.size() == 0;}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001587 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001588 size_type size() const _NOEXCEPT {return __tree_.size();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001589 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001590 size_type max_size() const _NOEXCEPT {return __tree_.max_size();}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001591
Howard Hinnant756c69b2010-09-22 16:48:34 +00001592 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001593 allocator_type get_allocator() const _NOEXCEPT {return __tree_.__alloc();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001594 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001595 key_compare key_comp() const {return __tree_.value_comp().key_comp();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001596 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001597 value_compare value_comp() const
1598 {return value_compare(__tree_.value_comp().key_comp());}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001599
Howard Hinnant74279a52010-09-04 23:28:19 +00001600#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant74279a52010-09-04 23:28:19 +00001601#ifndef _LIBCPP_HAS_NO_VARIADICS
1602
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001603 template <class ..._Args>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001604 iterator
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001605 emplace(_Args&& ...__args);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001606
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001607 template <class ..._Args>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001608 iterator
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001609 emplace_hint(const_iterator __p, _Args&& ...__args);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001610
Howard Hinnant74279a52010-09-04 23:28:19 +00001611#endif // _LIBCPP_HAS_NO_VARIADICS
1612
Howard Hinnantc834c512011-11-29 18:15:50 +00001613 template <class _Pp,
1614 class = typename enable_if<is_constructible<value_type, _Pp>::value>::type>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001615 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc834c512011-11-29 18:15:50 +00001616 iterator insert(_Pp&& __p)
1617 {return __tree_.__insert_multi(_VSTD::forward<_Pp>(__p));}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001618
Howard Hinnantc834c512011-11-29 18:15:50 +00001619 template <class _Pp,
1620 class = typename enable_if<is_constructible<value_type, _Pp>::value>::type>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001621 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc834c512011-11-29 18:15:50 +00001622 iterator insert(const_iterator __pos, _Pp&& __p)
1623 {return __tree_.__insert_multi(__pos.__i_, _VSTD::forward<_Pp>(__p));}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001624
Howard Hinnant74279a52010-09-04 23:28:19 +00001625#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +00001626
Howard Hinnant756c69b2010-09-22 16:48:34 +00001627 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001628 iterator insert(const value_type& __v) {return __tree_.__insert_multi(__v);}
1629
Howard Hinnant756c69b2010-09-22 16:48:34 +00001630 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001631 iterator insert(const_iterator __p, const value_type& __v)
1632 {return __tree_.__insert_multi(__p.__i_, __v);}
1633
1634 template <class _InputIterator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001635 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001636 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 Hinnant33711792011-08-12 21:56:02 +00001642#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1643
Howard Hinnant756c69b2010-09-22 16:48:34 +00001644 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001645 void insert(initializer_list<value_type> __il)
1646 {insert(__il.begin(), __il.end());}
1647
Howard Hinnant33711792011-08-12 21:56:02 +00001648#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1649
Howard Hinnant756c69b2010-09-22 16:48:34 +00001650 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001651 iterator erase(const_iterator __p) {return __tree_.erase(__p.__i_);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001652 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001653 size_type erase(const key_type& __k) {return __tree_.__erase_multi(__k);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001654 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001655 iterator erase(const_iterator __f, const_iterator __l)
1656 {return __tree_.erase(__f.__i_, __l.__i_);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001657 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001658 void clear() {__tree_.clear();}
1659
Howard Hinnant756c69b2010-09-22 16:48:34 +00001660 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001661 void swap(multimap& __m)
1662 _NOEXCEPT_(__is_nothrow_swappable<__base>::value)
1663 {__tree_.swap(__m.__tree_);}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001664
Howard Hinnant756c69b2010-09-22 16:48:34 +00001665 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001666 iterator find(const key_type& __k) {return __tree_.find(__k);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001667 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001668 const_iterator find(const key_type& __k) const {return __tree_.find(__k);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001669 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001670 size_type count(const key_type& __k) const
1671 {return __tree_.__count_multi(__k);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001672 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001673 iterator lower_bound(const key_type& __k)
1674 {return __tree_.lower_bound(__k);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001675 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001676 const_iterator lower_bound(const key_type& __k) const
1677 {return __tree_.lower_bound(__k);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001678 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001679 iterator upper_bound(const key_type& __k)
1680 {return __tree_.upper_bound(__k);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001681 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001682 const_iterator upper_bound(const key_type& __k) const
1683 {return __tree_.upper_bound(__k);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001684 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001685 pair<iterator,iterator> equal_range(const key_type& __k)
1686 {return __tree_.__equal_range_multi(__k);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001687 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001688 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 Hinnantc834c512011-11-29 18:15:50 +00001696 typedef __map_node_destructor<__node_allocator> _Dp;
1697 typedef unique_ptr<__node, _Dp> __node_holder;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001698
Howard Hinnant74279a52010-09-04 23:28:19 +00001699#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +00001700 __node_holder __construct_node();
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001701 template <class _A0>
Howard Hinnantac7e7482013-07-04 20:59:16 +00001702 __node_holder
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001703 __construct_node(_A0&& __a0);
Howard Hinnant74279a52010-09-04 23:28:19 +00001704#ifndef _LIBCPP_HAS_NO_VARIADICS
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001705 template <class _A0, class _A1, class ..._Args>
1706 __node_holder __construct_node(_A0&& __a0, _A1&& __a1, _Args&& ...__args);
Howard Hinnant74279a52010-09-04 23:28:19 +00001707#endif // _LIBCPP_HAS_NO_VARIADICS
1708#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +00001709};
1710
Howard Hinnant74279a52010-09-04 23:28:19 +00001711#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +00001712
1713template <class _Key, class _Tp, class _Compare, class _Allocator>
1714multimap<_Key, _Tp, _Compare, _Allocator>::multimap(multimap&& __m, const allocator_type& __a)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001715 : __tree_(_VSTD::move(__m.__tree_), __a)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001716{
1717 if (__a != __m.get_allocator())
1718 {
1719 const_iterator __e = cend();
1720 while (!__m.empty())
1721 __tree_.__insert_multi(__e.__i_,
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001722 _VSTD::move(__m.__tree_.remove(__m.begin().__i_)->__value_));
Howard Hinnantc51e1022010-05-11 19:42:16 +00001723 }
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 Hinnantc834c512011-11-29 18:15:50 +00001731 __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001732 __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__cc.first));
Howard Hinnantc51e1022010-05-11 19:42:16 +00001733 __h.get_deleter().__first_constructed = true;
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001734 __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__cc.second));
Howard Hinnantc51e1022010-05-11 19:42:16 +00001735 __h.get_deleter().__second_constructed = true;
1736 return __h;
1737}
1738
1739template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001740template <class _A0>
Howard Hinnantac7e7482013-07-04 20:59:16 +00001741typename multimap<_Key, _Tp, _Compare, _Allocator>::__node_holder
Howard Hinnantc51e1022010-05-11 19:42:16 +00001742multimap<_Key, _Tp, _Compare, _Allocator>::__construct_node(_A0&& __a0)
1743{
1744 __node_allocator& __na = __tree_.__node_alloc();
Howard Hinnantc834c512011-11-29 18:15:50 +00001745 __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001746 __node_traits::construct(__na, _VSTD::addressof(__h->__value_), _VSTD::forward<_A0>(__a0));
Howard Hinnantc51e1022010-05-11 19:42:16 +00001747 __h.get_deleter().__first_constructed = true;
1748 __h.get_deleter().__second_constructed = true;
1749 return __h;
1750}
1751
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001752#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 Hinnantc51e1022010-05-11 19:42:16 +00001765 __h.get_deleter().__second_constructed = true;
1766 return __h;
1767}
1768
Howard Hinnant74279a52010-09-04 23:28:19 +00001769#endif // _LIBCPP_HAS_NO_VARIADICS
1770#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +00001771
Howard Hinnant74279a52010-09-04 23:28:19 +00001772#if !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001773
1774template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001775template <class ..._Args>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001776typename multimap<_Key, _Tp, _Compare, _Allocator>::iterator
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001777multimap<_Key, _Tp, _Compare, _Allocator>::emplace(_Args&& ...__args)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001778{
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001779 __node_holder __h = __construct_node(_VSTD::forward<_Args>(__args)...);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001780 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 Hinnant29eb9b82012-05-25 22:04:21 +00001786template <class ..._Args>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001787typename multimap<_Key, _Tp, _Compare, _Allocator>::iterator
1788multimap<_Key, _Tp, _Compare, _Allocator>::emplace_hint(const_iterator __p,
Howard Hinnantc51e1022010-05-11 19:42:16 +00001789 _Args&& ...__args)
1790{
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001791 __node_holder __h = __construct_node(_VSTD::forward<_Args>(__args)...);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001792 iterator __r = __tree_.__node_insert_multi(__p.__i_, __h.get());
1793 __h.release();
1794 return __r;
1795}
1796
Howard Hinnant74279a52010-09-04 23:28:19 +00001797#endif // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001798
1799template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001800inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001801bool
1802operator==(const multimap<_Key, _Tp, _Compare, _Allocator>& __x,
1803 const multimap<_Key, _Tp, _Compare, _Allocator>& __y)
1804{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001805 return __x.size() == __y.size() && _VSTD::equal(__x.begin(), __x.end(), __y.begin());
Howard Hinnantc51e1022010-05-11 19:42:16 +00001806}
1807
1808template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001809inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001810bool
1811operator< (const multimap<_Key, _Tp, _Compare, _Allocator>& __x,
1812 const multimap<_Key, _Tp, _Compare, _Allocator>& __y)
1813{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001814 return _VSTD::lexicographical_compare(__x.begin(), __x.end(), __y.begin(), __y.end());
Howard Hinnantc51e1022010-05-11 19:42:16 +00001815}
1816
1817template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001818inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001819bool
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 Hinnant756c69b2010-09-22 16:48:34 +00001827inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001828bool
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 Hinnant756c69b2010-09-22 16:48:34 +00001836inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001837bool
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 Hinnant756c69b2010-09-22 16:48:34 +00001845inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001846bool
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 Hinnant756c69b2010-09-22 16:48:34 +00001854inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001855void
1856swap(multimap<_Key, _Tp, _Compare, _Allocator>& __x,
1857 multimap<_Key, _Tp, _Compare, _Allocator>& __y)
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001858 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
Howard Hinnantc51e1022010-05-11 19:42:16 +00001859{
1860 __x.swap(__y);
1861}
1862
1863_LIBCPP_END_NAMESPACE_STD
1864
1865#endif // _LIBCPP_MAP