blob: d0cd0c6b844b4c8e6ab4c7ad9d681d7ed12978b4 [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 Hinnantd0aabf82011-12-11 20:31:33 +0000384template <class _Key, class _Tp, class _Compare, bool = is_empty<_Compare>::value
385#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 +0000392 typedef pair<const _Key, _Tp> _CP;
393public:
Howard Hinnant756c69b2010-09-22 16:48:34 +0000394 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000395 __map_value_compare()
396 _NOEXCEPT_(is_nothrow_default_constructible<_Compare>::value)
397 : _Compare() {}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000398 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000399 __map_value_compare(_Compare c)
400 _NOEXCEPT_(is_nothrow_copy_constructible<_Compare>::value)
401 : _Compare(c) {}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000402 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000403 const _Compare& key_comp() const _NOEXCEPT {return *this;}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000404 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000405 bool operator()(const _CP& __x, const _CP& __y) const
406 {return static_cast<const _Compare&>(*this)(__x.first, __y.first);}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000407 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000408 bool operator()(const _CP& __x, const _Key& __y) const
409 {return static_cast<const _Compare&>(*this)(__x.first, __y);}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000410 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000411 bool operator()(const _Key& __x, const _CP& __y) const
412 {return static_cast<const _Compare&>(*this)(__x, __y.first);}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000413};
414
415template <class _Key, class _Tp, class _Compare>
416class __map_value_compare<_Key, _Tp, _Compare, false>
417{
418 _Compare comp;
419
Howard Hinnantc51e1022010-05-11 19:42:16 +0000420 typedef pair<const _Key, _Tp> _CP;
421
422public:
Howard Hinnant756c69b2010-09-22 16:48:34 +0000423 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000424 __map_value_compare()
425 _NOEXCEPT_(is_nothrow_default_constructible<_Compare>::value)
426 : comp() {}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000427 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000428 __map_value_compare(_Compare c)
429 _NOEXCEPT_(is_nothrow_copy_constructible<_Compare>::value)
430 : comp(c) {}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000431 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000432 const _Compare& key_comp() const _NOEXCEPT {return comp;}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000433
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 _CP& __y) const
436 {return comp(__x.first, __y.first);}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000437 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000438 bool operator()(const _CP& __x, const _Key& __y) const
439 {return comp(__x.first, __y);}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000440 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000441 bool operator()(const _Key& __x, const _CP& __y) const
442 {return comp(__x, __y.first);}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000443};
444
445template <class _Allocator>
446class __map_node_destructor
447{
448 typedef _Allocator allocator_type;
449 typedef allocator_traits<allocator_type> __alloc_traits;
450 typedef typename __alloc_traits::value_type::value_type value_type;
451public:
452 typedef typename __alloc_traits::pointer pointer;
453private:
Howard Hinnant2d0046b2013-06-19 21:29:40 +0000454 typedef typename value_type::value_type::first_type first_type;
455 typedef typename value_type::value_type::second_type second_type;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000456
457 allocator_type& __na_;
458
459 __map_node_destructor& operator=(const __map_node_destructor&);
460
461public:
462 bool __first_constructed;
463 bool __second_constructed;
464
Howard Hinnant756c69b2010-09-22 16:48:34 +0000465 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000466 explicit __map_node_destructor(allocator_type& __na) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +0000467 : __na_(__na),
468 __first_constructed(false),
469 __second_constructed(false)
470 {}
471
Howard Hinnant74279a52010-09-04 23:28:19 +0000472#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant756c69b2010-09-22 16:48:34 +0000473 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000474 __map_node_destructor(__tree_node_destructor<allocator_type>&& __x) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +0000475 : __na_(__x.__na_),
476 __first_constructed(__x.__value_constructed),
477 __second_constructed(__x.__value_constructed)
478 {
479 __x.__value_constructed = false;
480 }
Howard Hinnant5dc89112010-09-04 23:46:48 +0000481#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +0000482
Howard Hinnant756c69b2010-09-22 16:48:34 +0000483 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000484 void operator()(pointer __p) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +0000485 {
486 if (__second_constructed)
Howard Hinnant2d0046b2013-06-19 21:29:40 +0000487 __alloc_traits::destroy(__na_, _VSTD::addressof(__p->__value_.__cc.second));
Howard Hinnantc51e1022010-05-11 19:42:16 +0000488 if (__first_constructed)
Howard Hinnant2d0046b2013-06-19 21:29:40 +0000489 __alloc_traits::destroy(__na_, _VSTD::addressof(__p->__value_.__cc.first));
Howard Hinnantc51e1022010-05-11 19:42:16 +0000490 if (__p)
491 __alloc_traits::deallocate(__na_, __p, 1);
492 }
493};
494
Howard Hinnant944510a2011-06-14 19:58:17 +0000495template <class _Key, class _Tp, class _Compare, class _Allocator>
496 class map;
497template <class _Key, class _Tp, class _Compare, class _Allocator>
498 class multimap;
499template <class _TreeIterator> class __map_const_iterator;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000500
501template <class _TreeIterator>
Howard Hinnant8331b762013-03-06 23:30:19 +0000502class _LIBCPP_TYPE_VIS __map_iterator
Howard Hinnantc51e1022010-05-11 19:42:16 +0000503{
504 _TreeIterator __i_;
505
506 typedef typename _TreeIterator::__pointer_traits __pointer_traits;
Howard Hinnant2d0046b2013-06-19 21:29:40 +0000507 typedef const typename _TreeIterator::value_type::value_type::first_type __key_type;
508 typedef typename _TreeIterator::value_type::value_type::second_type __mapped_type;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000509public:
510 typedef bidirectional_iterator_tag iterator_category;
Howard Hinnantb2e8a422011-02-27 18:02:02 +0000511 typedef pair<__key_type, __mapped_type> value_type;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000512 typedef typename _TreeIterator::difference_type difference_type;
513 typedef value_type& reference;
514 typedef typename __pointer_traits::template
515#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
516 rebind<value_type>
517#else
518 rebind<value_type>::other
519#endif
520 pointer;
521
Howard Hinnant756c69b2010-09-22 16:48:34 +0000522 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000523 __map_iterator() _NOEXCEPT {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000524
Howard Hinnant756c69b2010-09-22 16:48:34 +0000525 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000526 __map_iterator(_TreeIterator __i) _NOEXCEPT : __i_(__i) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000527
Howard Hinnant756c69b2010-09-22 16:48:34 +0000528 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2d0046b2013-06-19 21:29:40 +0000529 reference operator*() const {return __i_->__cc;}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000530 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2d0046b2013-06-19 21:29:40 +0000531 pointer operator->() const {return pointer_traits<pointer>::pointer_to(__i_->__cc);}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000532
Howard Hinnant756c69b2010-09-22 16:48:34 +0000533 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000534 __map_iterator& operator++() {++__i_; return *this;}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000535 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000536 __map_iterator operator++(int)
537 {
538 __map_iterator __t(*this);
539 ++(*this);
540 return __t;
541 }
542
Howard Hinnant756c69b2010-09-22 16:48:34 +0000543 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000544 __map_iterator& operator--() {--__i_; return *this;}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000545 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000546 __map_iterator operator--(int)
547 {
548 __map_iterator __t(*this);
549 --(*this);
550 return __t;
551 }
552
Howard Hinnant756c69b2010-09-22 16:48:34 +0000553 friend _LIBCPP_INLINE_VISIBILITY
554 bool operator==(const __map_iterator& __x, const __map_iterator& __y)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000555 {return __x.__i_ == __y.__i_;}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000556 friend
557 _LIBCPP_INLINE_VISIBILITY
558 bool operator!=(const __map_iterator& __x, const __map_iterator& __y)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000559 {return __x.__i_ != __y.__i_;}
560
Howard Hinnant8331b762013-03-06 23:30:19 +0000561 template <class, class, class, class> friend class _LIBCPP_TYPE_VIS map;
562 template <class, class, class, class> friend class _LIBCPP_TYPE_VIS multimap;
563 template <class> friend class _LIBCPP_TYPE_VIS __map_const_iterator;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000564};
565
566template <class _TreeIterator>
Howard Hinnant8331b762013-03-06 23:30:19 +0000567class _LIBCPP_TYPE_VIS __map_const_iterator
Howard Hinnantc51e1022010-05-11 19:42:16 +0000568{
569 _TreeIterator __i_;
570
571 typedef typename _TreeIterator::__pointer_traits __pointer_traits;
Howard Hinnant2d0046b2013-06-19 21:29:40 +0000572 typedef const typename _TreeIterator::value_type::value_type::first_type __key_type;
573 typedef typename _TreeIterator::value_type::value_type::second_type __mapped_type;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000574public:
575 typedef bidirectional_iterator_tag iterator_category;
Howard Hinnantb2e8a422011-02-27 18:02:02 +0000576 typedef pair<__key_type, __mapped_type> value_type;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000577 typedef typename _TreeIterator::difference_type difference_type;
578 typedef const value_type& reference;
579 typedef typename __pointer_traits::template
580#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
Howard Hinnant73f3c8a2011-04-11 02:18:41 +0000581 rebind<const value_type>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000582#else
Howard Hinnant73f3c8a2011-04-11 02:18:41 +0000583 rebind<const value_type>::other
Howard Hinnantc51e1022010-05-11 19:42:16 +0000584#endif
585 pointer;
586
Howard Hinnant756c69b2010-09-22 16:48:34 +0000587 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000588 __map_const_iterator() _NOEXCEPT {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000589
Howard Hinnant756c69b2010-09-22 16:48:34 +0000590 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000591 __map_const_iterator(_TreeIterator __i) _NOEXCEPT : __i_(__i) {}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000592 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000593 __map_const_iterator(
594 __map_iterator<typename _TreeIterator::__non_const_iterator> __i)
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000595 _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +0000596 : __i_(__i.__i_) {}
597
Howard Hinnant756c69b2010-09-22 16:48:34 +0000598 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2d0046b2013-06-19 21:29:40 +0000599 reference operator*() const {return __i_->__cc;}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000600 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2d0046b2013-06-19 21:29:40 +0000601 pointer operator->() const {return pointer_traits<pointer>::pointer_to(__i_->__cc);}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000602
Howard Hinnant756c69b2010-09-22 16:48:34 +0000603 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000604 __map_const_iterator& operator++() {++__i_; return *this;}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000605 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000606 __map_const_iterator operator++(int)
607 {
608 __map_const_iterator __t(*this);
609 ++(*this);
610 return __t;
611 }
612
Howard Hinnant756c69b2010-09-22 16:48:34 +0000613 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000614 __map_const_iterator& operator--() {--__i_; return *this;}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000615 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000616 __map_const_iterator operator--(int)
617 {
618 __map_const_iterator __t(*this);
619 --(*this);
620 return __t;
621 }
622
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_;}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000626 friend _LIBCPP_INLINE_VISIBILITY
627 bool operator!=(const __map_const_iterator& __x, const __map_const_iterator& __y)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000628 {return __x.__i_ != __y.__i_;}
629
Howard Hinnant8331b762013-03-06 23:30:19 +0000630 template <class, class, class, class> friend class _LIBCPP_TYPE_VIS map;
631 template <class, class, class, class> friend class _LIBCPP_TYPE_VIS multimap;
632 template <class, class, class> friend class _LIBCPP_TYPE_VIS __tree_const_iterator;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000633};
634
635template <class _Key, class _Tp, class _Compare = less<_Key>,
636 class _Allocator = allocator<pair<const _Key, _Tp> > >
Howard Hinnant8331b762013-03-06 23:30:19 +0000637class _LIBCPP_TYPE_VIS map
Howard Hinnantc51e1022010-05-11 19:42:16 +0000638{
639public:
640 // types:
641 typedef _Key key_type;
642 typedef _Tp mapped_type;
643 typedef pair<const key_type, mapped_type> value_type;
Howard Hinnant2d0046b2013-06-19 21:29:40 +0000644 typedef pair<key_type, mapped_type> __nc_value_type;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000645 typedef _Compare key_compare;
646 typedef _Allocator allocator_type;
647 typedef value_type& reference;
648 typedef const value_type& const_reference;
649
Howard Hinnant8331b762013-03-06 23:30:19 +0000650 class _LIBCPP_TYPE_VIS value_compare
Howard Hinnantc51e1022010-05-11 19:42:16 +0000651 : public binary_function<value_type, value_type, bool>
652 {
653 friend class map;
654 protected:
655 key_compare comp;
656
Howard Hinnant756c69b2010-09-22 16:48:34 +0000657 _LIBCPP_INLINE_VISIBILITY value_compare(key_compare c) : comp(c) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000658 public:
Howard Hinnant756c69b2010-09-22 16:48:34 +0000659 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000660 bool operator()(const value_type& __x, const value_type& __y) const
661 {return comp(__x.first, __y.first);}
662 };
663
664private:
Howard Hinnant2d0046b2013-06-19 21:29:40 +0000665
666#if __cplusplus >= 201103L
667 union __value_type
668 {
669 typedef typename map::value_type value_type;
670 typedef typename map::__nc_value_type __nc_value_type;
671 value_type __cc;
672 __nc_value_type __nc;
673
674 template <class ..._Args>
675 __value_type(_Args&& ...__args)
676 : __cc(std::forward<_Args>(__args)...) {}
677
678 __value_type(const __value_type& __v)
679 : __cc(std::move(__v.__cc)) {}
680
681 __value_type(__value_type&& __v)
682 : __nc(std::move(__v.__nc)) {}
683
684 __value_type& operator=(const __value_type& __v)
685 {__nc = __v.__cc; return *this;}
686
687 __value_type& operator=(__value_type&& __v)
688 {__nc = std::move(__v.__nc); return *this;}
689
690 ~__value_type() {__cc.~value_type();}
691
692 operator const value_type& () const {return __cc;}
693 };
694#else
695 struct __value_type
696 {
697 typedef typename map::value_type value_type;
698 value_type __cc;
699
700 __value_type() {}
701
702 template <class _A0>
703 __value_type(const _A0& __a0)
704 : __cc(__a0) {}
705
706 template <class _A0, class _A1>
707 __value_type(const _A0& __a0, const _A1& __a1)
708 : __cc(__a0, __a1) {}
709
710 operator const value_type& () const {return __cc;}
711 };
712#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000713 typedef __map_value_compare<key_type, mapped_type, key_compare> __vc;
714 typedef typename allocator_traits<allocator_type>::template
715#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
716 rebind_alloc<__value_type>
717#else
718 rebind_alloc<__value_type>::other
719#endif
720 __allocator_type;
721 typedef __tree<__value_type, __vc, __allocator_type> __base;
722 typedef typename __base::__node_traits __node_traits;
723 typedef allocator_traits<allocator_type> __alloc_traits;
724
725 __base __tree_;
726
727public:
728 typedef typename __alloc_traits::pointer pointer;
729 typedef typename __alloc_traits::const_pointer const_pointer;
730 typedef typename __alloc_traits::size_type size_type;
731 typedef typename __alloc_traits::difference_type difference_type;
732 typedef __map_iterator<typename __base::iterator> iterator;
733 typedef __map_const_iterator<typename __base::const_iterator> const_iterator;
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000734 typedef _VSTD::reverse_iterator<iterator> reverse_iterator;
735 typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000736
Howard Hinnant756c69b2010-09-22 16:48:34 +0000737 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000738 explicit map(const key_compare& __comp = key_compare())
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000739 _NOEXCEPT_(
740 is_nothrow_default_constructible<allocator_type>::value &&
741 is_nothrow_default_constructible<key_compare>::value &&
742 is_nothrow_copy_constructible<key_compare>::value)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000743 : __tree_(__vc(__comp)) {}
744
Howard Hinnant756c69b2010-09-22 16:48:34 +0000745 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000746 explicit map(const key_compare& __comp, const allocator_type& __a)
747 : __tree_(__vc(__comp), __a) {}
748
749 template <class _InputIterator>
Howard Hinnant756c69b2010-09-22 16:48:34 +0000750 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000751 map(_InputIterator __f, _InputIterator __l,
752 const key_compare& __comp = key_compare())
753 : __tree_(__vc(__comp))
754 {
755 insert(__f, __l);
756 }
757
758 template <class _InputIterator>
Howard Hinnant756c69b2010-09-22 16:48:34 +0000759 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000760 map(_InputIterator __f, _InputIterator __l,
761 const key_compare& __comp, const allocator_type& __a)
762 : __tree_(__vc(__comp), __a)
763 {
764 insert(__f, __l);
765 }
766
Howard Hinnant756c69b2010-09-22 16:48:34 +0000767 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000768 map(const map& __m)
769 : __tree_(__m.__tree_)
770 {
771 insert(__m.begin(), __m.end());
772 }
773
Howard Hinnantd3a657f2011-07-01 19:24:36 +0000774 _LIBCPP_INLINE_VISIBILITY
775 map& operator=(const map& __m)
776 {
Howard Hinnant2d0046b2013-06-19 21:29:40 +0000777#if __cplusplus >= 201103L
Howard Hinnantd3a657f2011-07-01 19:24:36 +0000778 __tree_ = __m.__tree_;
Howard Hinnant2d0046b2013-06-19 21:29:40 +0000779#else
780 __tree_.clear();
781 __tree_.value_comp() = __m.__tree_.value_comp();
782 __tree_.__copy_assign_alloc(__m.__tree_);
783 insert(__m.begin(), __m.end());
784#endif
Howard Hinnantd3a657f2011-07-01 19:24:36 +0000785 return *this;
786 }
787
Howard Hinnant74279a52010-09-04 23:28:19 +0000788#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +0000789
Howard Hinnant756c69b2010-09-22 16:48:34 +0000790 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000791 map(map&& __m)
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000792 _NOEXCEPT_(is_nothrow_move_constructible<__base>::value)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000793 : __tree_(_VSTD::move(__m.__tree_))
Howard Hinnantc51e1022010-05-11 19:42:16 +0000794 {
795 }
796
797 map(map&& __m, const allocator_type& __a);
798
Howard Hinnant756c69b2010-09-22 16:48:34 +0000799 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant33711792011-08-12 21:56:02 +0000800 map& operator=(map&& __m)
801 _NOEXCEPT_(is_nothrow_move_assignable<__base>::value)
802 {
803 __tree_ = _VSTD::move(__m.__tree_);
804 return *this;
805 }
806
807#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
808
809#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
810
811 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000812 map(initializer_list<value_type> __il, const key_compare& __comp = key_compare())
813 : __tree_(__vc(__comp))
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(initializer_list<value_type> __il, const key_compare& __comp, const allocator_type& __a)
820 : __tree_(__vc(__comp), __a)
821 {
822 insert(__il.begin(), __il.end());
823 }
824
Howard Hinnant756c69b2010-09-22 16:48:34 +0000825 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000826 map& operator=(initializer_list<value_type> __il)
827 {
828 __tree_.__assign_unique(__il.begin(), __il.end());
829 return *this;
830 }
831
Howard Hinnant33711792011-08-12 21:56:02 +0000832#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000833
Howard Hinnant756c69b2010-09-22 16:48:34 +0000834 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000835 explicit map(const allocator_type& __a)
836 : __tree_(__a)
837 {
838 }
839
Howard Hinnant756c69b2010-09-22 16:48:34 +0000840 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000841 map(const map& __m, const allocator_type& __a)
842 : __tree_(__m.__tree_.value_comp(), __a)
843 {
844 insert(__m.begin(), __m.end());
845 }
846
Howard Hinnant756c69b2010-09-22 16:48:34 +0000847 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000848 iterator begin() _NOEXCEPT {return __tree_.begin();}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000849 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000850 const_iterator begin() const _NOEXCEPT {return __tree_.begin();}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000851 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000852 iterator end() _NOEXCEPT {return __tree_.end();}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000853 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000854 const_iterator end() const _NOEXCEPT {return __tree_.end();}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000855
Howard Hinnant756c69b2010-09-22 16:48:34 +0000856 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000857 reverse_iterator rbegin() _NOEXCEPT {return reverse_iterator(end());}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000858 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000859 const_reverse_iterator rbegin() const _NOEXCEPT
860 {return const_reverse_iterator(end());}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000861 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000862 reverse_iterator rend() _NOEXCEPT
863 {return reverse_iterator(begin());}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000864 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000865 const_reverse_iterator rend() const _NOEXCEPT
866 {return const_reverse_iterator(begin());}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000867
Howard Hinnant756c69b2010-09-22 16:48:34 +0000868 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000869 const_iterator cbegin() const _NOEXCEPT {return begin();}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000870 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000871 const_iterator cend() const _NOEXCEPT {return end();}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000872 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000873 const_reverse_iterator crbegin() const _NOEXCEPT {return rbegin();}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000874 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000875 const_reverse_iterator crend() const _NOEXCEPT {return rend();}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000876
Howard Hinnant756c69b2010-09-22 16:48:34 +0000877 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000878 bool empty() const _NOEXCEPT {return __tree_.size() == 0;}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000879 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000880 size_type size() const _NOEXCEPT {return __tree_.size();}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000881 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000882 size_type max_size() const _NOEXCEPT {return __tree_.max_size();}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000883
884 mapped_type& operator[](const key_type& __k);
Howard Hinnant74279a52010-09-04 23:28:19 +0000885#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +0000886 mapped_type& operator[](key_type&& __k);
887#endif
888
889 mapped_type& at(const key_type& __k);
890 const mapped_type& at(const key_type& __k) const;
891
Howard Hinnant756c69b2010-09-22 16:48:34 +0000892 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000893 allocator_type get_allocator() const _NOEXCEPT {return __tree_.__alloc();}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000894 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000895 key_compare key_comp() const {return __tree_.value_comp().key_comp();}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000896 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000897 value_compare value_comp() const {return value_compare(__tree_.value_comp().key_comp());}
898
Howard Hinnant74279a52010-09-04 23:28:19 +0000899#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant74279a52010-09-04 23:28:19 +0000900#ifndef _LIBCPP_HAS_NO_VARIADICS
901
Howard Hinnant29eb9b82012-05-25 22:04:21 +0000902 template <class ..._Args>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000903 pair<iterator, bool>
Howard Hinnant29eb9b82012-05-25 22:04:21 +0000904 emplace(_Args&& ...__args);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000905
Howard Hinnant29eb9b82012-05-25 22:04:21 +0000906 template <class ..._Args>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000907 iterator
Howard Hinnant29eb9b82012-05-25 22:04:21 +0000908 emplace_hint(const_iterator __p, _Args&& ...__args);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000909
Howard Hinnant74279a52010-09-04 23:28:19 +0000910#endif // _LIBCPP_HAS_NO_VARIADICS
911
Howard Hinnantc834c512011-11-29 18:15:50 +0000912 template <class _Pp,
913 class = typename enable_if<is_constructible<value_type, _Pp>::value>::type>
Howard Hinnant756c69b2010-09-22 16:48:34 +0000914 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc834c512011-11-29 18:15:50 +0000915 pair<iterator, bool> insert(_Pp&& __p)
916 {return __tree_.__insert_unique(_VSTD::forward<_Pp>(__p));}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000917
Howard Hinnantc834c512011-11-29 18:15:50 +0000918 template <class _Pp,
919 class = typename enable_if<is_constructible<value_type, _Pp>::value>::type>
Howard Hinnant756c69b2010-09-22 16:48:34 +0000920 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc834c512011-11-29 18:15:50 +0000921 iterator insert(const_iterator __pos, _Pp&& __p)
922 {return __tree_.__insert_unique(__pos.__i_, _VSTD::forward<_Pp>(__p));}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000923
Howard Hinnant74279a52010-09-04 23:28:19 +0000924#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +0000925
Howard Hinnant756c69b2010-09-22 16:48:34 +0000926 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000927 pair<iterator, bool>
928 insert(const value_type& __v) {return __tree_.__insert_unique(__v);}
929
Howard Hinnant756c69b2010-09-22 16:48:34 +0000930 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000931 iterator
932 insert(const_iterator __p, const value_type& __v)
933 {return __tree_.__insert_unique(__p.__i_, __v);}
934
935 template <class _InputIterator>
Howard Hinnant756c69b2010-09-22 16:48:34 +0000936 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000937 void insert(_InputIterator __f, _InputIterator __l)
938 {
939 for (const_iterator __e = cend(); __f != __l; ++__f)
940 insert(__e.__i_, *__f);
941 }
942
Howard Hinnant33711792011-08-12 21:56:02 +0000943#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
944
Howard Hinnant756c69b2010-09-22 16:48:34 +0000945 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000946 void insert(initializer_list<value_type> __il)
947 {insert(__il.begin(), __il.end());}
948
Howard Hinnant33711792011-08-12 21:56:02 +0000949#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
950
Howard Hinnant756c69b2010-09-22 16:48:34 +0000951 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000952 iterator erase(const_iterator __p) {return __tree_.erase(__p.__i_);}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000953 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000954 size_type erase(const key_type& __k)
955 {return __tree_.__erase_unique(__k);}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000956 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000957 iterator erase(const_iterator __f, const_iterator __l)
958 {return __tree_.erase(__f.__i_, __l.__i_);}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000959 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000960 void clear() _NOEXCEPT {__tree_.clear();}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000961
Howard Hinnant756c69b2010-09-22 16:48:34 +0000962 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000963 void swap(map& __m)
964 _NOEXCEPT_(__is_nothrow_swappable<__base>::value)
965 {__tree_.swap(__m.__tree_);}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000966
Howard Hinnant756c69b2010-09-22 16:48:34 +0000967 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000968 iterator find(const key_type& __k) {return __tree_.find(__k);}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000969 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000970 const_iterator find(const key_type& __k) const {return __tree_.find(__k);}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000971 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000972 size_type count(const key_type& __k) const
973 {return __tree_.__count_unique(__k);}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000974 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000975 iterator lower_bound(const key_type& __k)
976 {return __tree_.lower_bound(__k);}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000977 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000978 const_iterator lower_bound(const key_type& __k) const
979 {return __tree_.lower_bound(__k);}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000980 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000981 iterator upper_bound(const key_type& __k)
982 {return __tree_.upper_bound(__k);}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000983 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000984 const_iterator upper_bound(const key_type& __k) const
985 {return __tree_.upper_bound(__k);}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000986 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000987 pair<iterator,iterator> equal_range(const key_type& __k)
988 {return __tree_.__equal_range_unique(__k);}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000989 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000990 pair<const_iterator,const_iterator> equal_range(const key_type& __k) const
991 {return __tree_.__equal_range_unique(__k);}
992
993private:
994 typedef typename __base::__node __node;
995 typedef typename __base::__node_allocator __node_allocator;
996 typedef typename __base::__node_pointer __node_pointer;
997 typedef typename __base::__node_const_pointer __node_const_pointer;
998 typedef typename __base::__node_base_pointer __node_base_pointer;
999 typedef typename __base::__node_base_const_pointer __node_base_const_pointer;
Howard Hinnantc834c512011-11-29 18:15:50 +00001000 typedef __map_node_destructor<__node_allocator> _Dp;
1001 typedef unique_ptr<__node, _Dp> __node_holder;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001002
Howard Hinnant74279a52010-09-04 23:28:19 +00001003#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +00001004 __node_holder __construct_node();
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001005 template <class _A0>
1006 typename enable_if
1007 <
1008 is_constructible<value_type, _A0>::value,
1009 __node_holder
1010 >::type
1011 __construct_node(_A0&& __a0);
1012 template <class _A0>
1013 typename enable_if
1014 <
1015 is_constructible<key_type, _A0>::value,
1016 __node_holder
1017 >::type
1018 __construct_node(_A0&& __a0);
Howard Hinnant74279a52010-09-04 23:28:19 +00001019#ifndef _LIBCPP_HAS_NO_VARIADICS
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001020 template <class _A0, class _A1, class ..._Args>
1021 __node_holder __construct_node(_A0&& __a0, _A1&& __a1, _Args&& ...__args);
Howard Hinnant74279a52010-09-04 23:28:19 +00001022#endif // _LIBCPP_HAS_NO_VARIADICS
1023#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +00001024 __node_holder __construct_node(const key_type& __k);
1025#endif
1026
1027 __node_base_pointer&
1028 __find_equal_key(__node_base_pointer& __parent, const key_type& __k);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001029 __node_base_const_pointer
1030 __find_equal_key(__node_base_const_pointer& __parent, const key_type& __k) const;
1031};
1032
1033// Find place to insert if __k doesn't exist
1034// Set __parent to parent of null leaf
1035// Return reference to null leaf
1036// If __k exists, set parent to node of __k and return reference to node of __k
1037template <class _Key, class _Tp, class _Compare, class _Allocator>
1038typename map<_Key, _Tp, _Compare, _Allocator>::__node_base_pointer&
1039map<_Key, _Tp, _Compare, _Allocator>::__find_equal_key(__node_base_pointer& __parent,
1040 const key_type& __k)
1041{
1042 __node_pointer __nd = __tree_.__root();
1043 if (__nd != nullptr)
1044 {
1045 while (true)
1046 {
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001047 if (__tree_.value_comp().key_comp()(__k, __nd->__value_.__cc.first))
Howard Hinnantc51e1022010-05-11 19:42:16 +00001048 {
1049 if (__nd->__left_ != nullptr)
1050 __nd = static_cast<__node_pointer>(__nd->__left_);
1051 else
1052 {
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001053 __parent = static_cast<__node_base_pointer>(__nd);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001054 return __parent->__left_;
1055 }
1056 }
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001057 else if (__tree_.value_comp().key_comp()(__nd->__value_.__cc.first, __k))
Howard Hinnantc51e1022010-05-11 19:42:16 +00001058 {
1059 if (__nd->__right_ != nullptr)
1060 __nd = static_cast<__node_pointer>(__nd->__right_);
1061 else
1062 {
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001063 __parent = static_cast<__node_base_pointer>(__nd);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001064 return __parent->__right_;
1065 }
1066 }
1067 else
1068 {
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001069 __parent = static_cast<__node_base_pointer>(__nd);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001070 return __parent;
1071 }
1072 }
1073 }
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001074 __parent = static_cast<__node_base_pointer>(__tree_.__end_node());
Howard Hinnantc51e1022010-05-11 19:42:16 +00001075 return __parent->__left_;
1076}
1077
Howard Hinnantc51e1022010-05-11 19:42:16 +00001078// Find __k
1079// Set __parent to parent of null leaf and
1080// return reference to null leaf iv __k does not exist.
1081// If __k exists, set parent to node of __k and return reference to node of __k
1082template <class _Key, class _Tp, class _Compare, class _Allocator>
1083typename map<_Key, _Tp, _Compare, _Allocator>::__node_base_const_pointer
1084map<_Key, _Tp, _Compare, _Allocator>::__find_equal_key(__node_base_const_pointer& __parent,
1085 const key_type& __k) const
1086{
1087 __node_const_pointer __nd = __tree_.__root();
1088 if (__nd != nullptr)
1089 {
1090 while (true)
1091 {
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001092 if (__tree_.value_comp().key_comp()(__k, __nd->__value_.__cc.first))
Howard Hinnantc51e1022010-05-11 19:42:16 +00001093 {
1094 if (__nd->__left_ != nullptr)
1095 __nd = static_cast<__node_pointer>(__nd->__left_);
1096 else
1097 {
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001098 __parent = static_cast<__node_base_pointer>(__nd);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001099 return const_cast<const __node_base_const_pointer&>(__parent->__left_);
1100 }
1101 }
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001102 else if (__tree_.value_comp().key_comp()(__nd->__value_.__cc.first, __k))
Howard Hinnantc51e1022010-05-11 19:42:16 +00001103 {
1104 if (__nd->__right_ != nullptr)
1105 __nd = static_cast<__node_pointer>(__nd->__right_);
1106 else
1107 {
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001108 __parent = static_cast<__node_base_pointer>(__nd);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001109 return const_cast<const __node_base_const_pointer&>(__parent->__right_);
1110 }
1111 }
1112 else
1113 {
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001114 __parent = static_cast<__node_base_pointer>(__nd);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001115 return __parent;
1116 }
1117 }
1118 }
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001119 __parent = static_cast<__node_base_pointer>(__tree_.__end_node());
Howard Hinnantc51e1022010-05-11 19:42:16 +00001120 return const_cast<const __node_base_const_pointer&>(__parent->__left_);
1121}
1122
Howard Hinnant74279a52010-09-04 23:28:19 +00001123#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +00001124
1125template <class _Key, class _Tp, class _Compare, class _Allocator>
1126map<_Key, _Tp, _Compare, _Allocator>::map(map&& __m, const allocator_type& __a)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001127 : __tree_(_VSTD::move(__m.__tree_), __a)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001128{
1129 if (__a != __m.get_allocator())
1130 {
1131 const_iterator __e = cend();
1132 while (!__m.empty())
1133 __tree_.__insert_unique(__e.__i_,
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001134 _VSTD::move(__m.__tree_.remove(__m.begin().__i_)->__value_));
Howard Hinnantc51e1022010-05-11 19:42:16 +00001135 }
1136}
1137
1138template <class _Key, class _Tp, class _Compare, class _Allocator>
1139typename map<_Key, _Tp, _Compare, _Allocator>::__node_holder
1140map<_Key, _Tp, _Compare, _Allocator>::__construct_node()
1141{
1142 __node_allocator& __na = __tree_.__node_alloc();
Howard Hinnantc834c512011-11-29 18:15:50 +00001143 __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001144 __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__cc.first));
Howard Hinnantc51e1022010-05-11 19:42:16 +00001145 __h.get_deleter().__first_constructed = true;
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001146 __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__cc.second));
Howard Hinnantc51e1022010-05-11 19:42:16 +00001147 __h.get_deleter().__second_constructed = true;
1148 return __h;
1149}
1150
1151template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001152template <class _A0>
1153typename enable_if
1154<
1155 is_constructible<pair<const _Key, _Tp>, _A0>::value,
1156 typename map<_Key, _Tp, _Compare, _Allocator>::__node_holder
1157>::type
Howard Hinnantc51e1022010-05-11 19:42:16 +00001158map<_Key, _Tp, _Compare, _Allocator>::__construct_node(_A0&& __a0)
1159{
1160 __node_allocator& __na = __tree_.__node_alloc();
Howard Hinnantc834c512011-11-29 18:15:50 +00001161 __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001162 __node_traits::construct(__na, _VSTD::addressof(__h->__value_), _VSTD::forward<_A0>(__a0));
Howard Hinnantc51e1022010-05-11 19:42:16 +00001163 __h.get_deleter().__first_constructed = true;
1164 __h.get_deleter().__second_constructed = true;
1165 return __h;
1166}
1167
1168template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001169template <class _A0>
1170typename enable_if
1171<
1172 is_constructible<_Key, _A0>::value,
1173 typename map<_Key, _Tp, _Compare, _Allocator>::__node_holder
1174>::type
1175map<_Key, _Tp, _Compare, _Allocator>::__construct_node(_A0&& __a0)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001176{
1177 __node_allocator& __na = __tree_.__node_alloc();
Howard Hinnantc834c512011-11-29 18:15:50 +00001178 __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001179 __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__cc.first), _VSTD::forward<_A0>(__a0));
Howard Hinnantc51e1022010-05-11 19:42:16 +00001180 __h.get_deleter().__first_constructed = true;
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001181 __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__cc.second));
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001182 __h.get_deleter().__second_constructed = true;
1183 return __h;
1184}
1185
1186#ifndef _LIBCPP_HAS_NO_VARIADICS
1187
1188template <class _Key, class _Tp, class _Compare, class _Allocator>
1189template <class _A0, class _A1, class ..._Args>
1190typename map<_Key, _Tp, _Compare, _Allocator>::__node_holder
1191map<_Key, _Tp, _Compare, _Allocator>::__construct_node(_A0&& __a0, _A1&& __a1, _Args&& ...__args)
1192{
1193 __node_allocator& __na = __tree_.__node_alloc();
1194 __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
1195 __node_traits::construct(__na, _VSTD::addressof(__h->__value_),
1196 _VSTD::forward<_A0>(__a0), _VSTD::forward<_A1>(__a1),
1197 _VSTD::forward<_Args>(__args)...);
1198 __h.get_deleter().__first_constructed = true;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001199 __h.get_deleter().__second_constructed = true;
1200 return __h;
1201}
1202
Howard Hinnant74279a52010-09-04 23:28:19 +00001203#endif // _LIBCPP_HAS_NO_VARIADICS
1204
1205#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +00001206
1207template <class _Key, class _Tp, class _Compare, class _Allocator>
1208typename map<_Key, _Tp, _Compare, _Allocator>::__node_holder
1209map<_Key, _Tp, _Compare, _Allocator>::__construct_node(const key_type& __k)
1210{
1211 __node_allocator& __na = __tree_.__node_alloc();
Howard Hinnantc834c512011-11-29 18:15:50 +00001212 __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001213 __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__cc.first), __k);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001214 __h.get_deleter().__first_constructed = true;
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001215 __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__cc.second));
Howard Hinnantc51e1022010-05-11 19:42:16 +00001216 __h.get_deleter().__second_constructed = true;
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001217 return _VSTD::move(__h);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001218}
1219
Howard Hinnant74279a52010-09-04 23:28:19 +00001220#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +00001221
1222template <class _Key, class _Tp, class _Compare, class _Allocator>
1223_Tp&
1224map<_Key, _Tp, _Compare, _Allocator>::operator[](const key_type& __k)
1225{
1226 __node_base_pointer __parent;
1227 __node_base_pointer& __child = __find_equal_key(__parent, __k);
1228 __node_pointer __r = static_cast<__node_pointer>(__child);
1229 if (__child == nullptr)
1230 {
1231 __node_holder __h = __construct_node(__k);
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001232 __tree_.__insert_node_at(__parent, __child, static_cast<__node_base_pointer>(__h.get()));
Howard Hinnantc51e1022010-05-11 19:42:16 +00001233 __r = __h.release();
1234 }
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001235 return __r->__value_.__cc.second;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001236}
1237
Howard Hinnant74279a52010-09-04 23:28:19 +00001238#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +00001239
1240template <class _Key, class _Tp, class _Compare, class _Allocator>
1241_Tp&
1242map<_Key, _Tp, _Compare, _Allocator>::operator[](key_type&& __k)
1243{
1244 __node_base_pointer __parent;
1245 __node_base_pointer& __child = __find_equal_key(__parent, __k);
1246 __node_pointer __r = static_cast<__node_pointer>(__child);
1247 if (__child == nullptr)
1248 {
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001249 __node_holder __h = __construct_node(_VSTD::move(__k));
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001250 __tree_.__insert_node_at(__parent, __child, static_cast<__node_base_pointer>(__h.get()));
Howard Hinnantc51e1022010-05-11 19:42:16 +00001251 __r = __h.release();
1252 }
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001253 return __r->__value_.__cc.second;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001254}
1255
Howard Hinnant74279a52010-09-04 23:28:19 +00001256#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +00001257
1258template <class _Key, class _Tp, class _Compare, class _Allocator>
1259_Tp&
1260map<_Key, _Tp, _Compare, _Allocator>::at(const key_type& __k)
1261{
1262 __node_base_pointer __parent;
1263 __node_base_pointer& __child = __find_equal_key(__parent, __k);
Howard Hinnant72f73582010-08-11 17:04:31 +00001264#ifndef _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +00001265 if (__child == nullptr)
1266 throw out_of_range("map::at: key not found");
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001267#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001268 return static_cast<__node_pointer>(__child)->__value_.__cc.second;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001269}
1270
1271template <class _Key, class _Tp, class _Compare, class _Allocator>
1272const _Tp&
1273map<_Key, _Tp, _Compare, _Allocator>::at(const key_type& __k) const
1274{
1275 __node_base_const_pointer __parent;
1276 __node_base_const_pointer __child = __find_equal_key(__parent, __k);
Howard Hinnant72f73582010-08-11 17:04:31 +00001277#ifndef _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +00001278 if (__child == nullptr)
1279 throw out_of_range("map::at: key not found");
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001280#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001281 return static_cast<__node_const_pointer>(__child)->__value_.__cc.second;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001282}
1283
Howard Hinnant74279a52010-09-04 23:28:19 +00001284#if !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001285
1286template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001287template <class ..._Args>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001288pair<typename map<_Key, _Tp, _Compare, _Allocator>::iterator, bool>
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001289map<_Key, _Tp, _Compare, _Allocator>::emplace(_Args&& ...__args)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001290{
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001291 __node_holder __h = __construct_node(_VSTD::forward<_Args>(__args)...);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001292 pair<iterator, bool> __r = __tree_.__node_insert_unique(__h.get());
1293 if (__r.second)
1294 __h.release();
1295 return __r;
1296}
1297
1298template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001299template <class ..._Args>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001300typename map<_Key, _Tp, _Compare, _Allocator>::iterator
1301map<_Key, _Tp, _Compare, _Allocator>::emplace_hint(const_iterator __p,
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001302 _Args&& ...__args)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001303{
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001304 __node_holder __h = __construct_node(_VSTD::forward<_Args>(__args)...);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001305 iterator __r = __tree_.__node_insert_unique(__p.__i_, __h.get());
1306 if (__r.__i_.__ptr_ == __h.get())
1307 __h.release();
1308 return __r;
1309}
1310
Howard Hinnant74279a52010-09-04 23:28:19 +00001311#endif // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001312
1313template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001314inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001315bool
1316operator==(const map<_Key, _Tp, _Compare, _Allocator>& __x,
1317 const map<_Key, _Tp, _Compare, _Allocator>& __y)
1318{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001319 return __x.size() == __y.size() && _VSTD::equal(__x.begin(), __x.end(), __y.begin());
Howard Hinnantc51e1022010-05-11 19:42:16 +00001320}
1321
1322template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001323inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001324bool
1325operator< (const map<_Key, _Tp, _Compare, _Allocator>& __x,
1326 const map<_Key, _Tp, _Compare, _Allocator>& __y)
1327{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001328 return _VSTD::lexicographical_compare(__x.begin(), __x.end(), __y.begin(), __y.end());
Howard Hinnantc51e1022010-05-11 19:42:16 +00001329}
1330
1331template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001332inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001333bool
1334operator!=(const map<_Key, _Tp, _Compare, _Allocator>& __x,
1335 const map<_Key, _Tp, _Compare, _Allocator>& __y)
1336{
1337 return !(__x == __y);
1338}
1339
1340template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001341inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001342bool
1343operator> (const map<_Key, _Tp, _Compare, _Allocator>& __x,
1344 const map<_Key, _Tp, _Compare, _Allocator>& __y)
1345{
1346 return __y < __x;
1347}
1348
1349template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001350inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001351bool
1352operator>=(const map<_Key, _Tp, _Compare, _Allocator>& __x,
1353 const map<_Key, _Tp, _Compare, _Allocator>& __y)
1354{
1355 return !(__x < __y);
1356}
1357
1358template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001359inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001360bool
1361operator<=(const map<_Key, _Tp, _Compare, _Allocator>& __x,
1362 const map<_Key, _Tp, _Compare, _Allocator>& __y)
1363{
1364 return !(__y < __x);
1365}
1366
1367template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001368inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001369void
1370swap(map<_Key, _Tp, _Compare, _Allocator>& __x,
1371 map<_Key, _Tp, _Compare, _Allocator>& __y)
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001372 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
Howard Hinnantc51e1022010-05-11 19:42:16 +00001373{
1374 __x.swap(__y);
1375}
1376
1377template <class _Key, class _Tp, class _Compare = less<_Key>,
1378 class _Allocator = allocator<pair<const _Key, _Tp> > >
Howard Hinnant8331b762013-03-06 23:30:19 +00001379class _LIBCPP_TYPE_VIS multimap
Howard Hinnantc51e1022010-05-11 19:42:16 +00001380{
1381public:
1382 // types:
1383 typedef _Key key_type;
1384 typedef _Tp mapped_type;
1385 typedef pair<const key_type, mapped_type> value_type;
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001386 typedef pair<key_type, mapped_type> __nc_value_type;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001387 typedef _Compare key_compare;
1388 typedef _Allocator allocator_type;
1389 typedef value_type& reference;
1390 typedef const value_type& const_reference;
1391
Howard Hinnant8331b762013-03-06 23:30:19 +00001392 class _LIBCPP_TYPE_VIS value_compare
Howard Hinnantc51e1022010-05-11 19:42:16 +00001393 : public binary_function<value_type, value_type, bool>
1394 {
1395 friend class multimap;
1396 protected:
1397 key_compare comp;
1398
Howard Hinnant756c69b2010-09-22 16:48:34 +00001399 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001400 value_compare(key_compare c) : comp(c) {}
1401 public:
Howard Hinnant756c69b2010-09-22 16:48:34 +00001402 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001403 bool operator()(const value_type& __x, const value_type& __y) const
1404 {return comp(__x.first, __y.first);}
1405 };
1406
1407private:
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001408#if __cplusplus >= 201103L
1409 union __value_type
1410 {
1411 typedef typename multimap::value_type value_type;
1412 typedef typename multimap::__nc_value_type __nc_value_type;
1413 value_type __cc;
1414 __nc_value_type __nc;
1415
1416 template <class ..._Args>
1417 __value_type(_Args&& ...__args)
1418 : __cc(std::forward<_Args>(__args)...) {}
1419
1420 __value_type(const __value_type& __v)
1421 : __cc(std::move(__v.__cc)) {}
1422
1423 __value_type(__value_type&& __v)
1424 : __nc(std::move(__v.__nc)) {}
1425
1426 __value_type& operator=(const __value_type& __v)
1427 {__nc = __v.__cc; return *this;}
1428
1429 __value_type& operator=(__value_type&& __v)
1430 {__nc = std::move(__v.__nc); return *this;}
1431
1432 ~__value_type() {__cc.~value_type();}
1433
1434 operator const value_type& () const {return __cc;}
1435 };
1436#else
1437 struct __value_type
1438 {
1439 typedef typename multimap::value_type value_type;
1440 value_type __cc;
1441
1442 __value_type() {}
1443
1444 template <class _A0>
1445 __value_type(const _A0& __a0)
1446 : __cc(__a0) {}
1447
1448 template <class _A0, class _A1>
1449 __value_type(const _A0& __a0, const _A1& __a1)
1450 : __cc(__a0, __a1) {}
1451
1452 operator const value_type& () const {return __cc;}
1453 };
1454#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001455 typedef __map_value_compare<key_type, mapped_type, key_compare> __vc;
1456 typedef typename allocator_traits<allocator_type>::template
1457#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
1458 rebind_alloc<__value_type>
1459#else
1460 rebind_alloc<__value_type>::other
1461#endif
1462 __allocator_type;
1463 typedef __tree<__value_type, __vc, __allocator_type> __base;
1464 typedef typename __base::__node_traits __node_traits;
1465 typedef allocator_traits<allocator_type> __alloc_traits;
1466
1467 __base __tree_;
1468
1469public:
1470 typedef typename __alloc_traits::pointer pointer;
1471 typedef typename __alloc_traits::const_pointer const_pointer;
1472 typedef typename __alloc_traits::size_type size_type;
1473 typedef typename __alloc_traits::difference_type difference_type;
1474 typedef __map_iterator<typename __base::iterator> iterator;
1475 typedef __map_const_iterator<typename __base::const_iterator> const_iterator;
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001476 typedef _VSTD::reverse_iterator<iterator> reverse_iterator;
1477 typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001478
Howard Hinnant756c69b2010-09-22 16:48:34 +00001479 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001480 explicit multimap(const key_compare& __comp = key_compare())
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001481 _NOEXCEPT_(
1482 is_nothrow_default_constructible<allocator_type>::value &&
1483 is_nothrow_default_constructible<key_compare>::value &&
1484 is_nothrow_copy_constructible<key_compare>::value)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001485 : __tree_(__vc(__comp)) {}
1486
Howard Hinnant756c69b2010-09-22 16:48:34 +00001487 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001488 explicit multimap(const key_compare& __comp, const allocator_type& __a)
1489 : __tree_(__vc(__comp), __a) {}
1490
1491 template <class _InputIterator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001492 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001493 multimap(_InputIterator __f, _InputIterator __l,
1494 const key_compare& __comp = key_compare())
1495 : __tree_(__vc(__comp))
1496 {
1497 insert(__f, __l);
1498 }
1499
1500 template <class _InputIterator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001501 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001502 multimap(_InputIterator __f, _InputIterator __l,
1503 const key_compare& __comp, const allocator_type& __a)
1504 : __tree_(__vc(__comp), __a)
1505 {
1506 insert(__f, __l);
1507 }
1508
Howard Hinnant756c69b2010-09-22 16:48:34 +00001509 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001510 multimap(const multimap& __m)
1511 : __tree_(__m.__tree_.value_comp(),
1512 __alloc_traits::select_on_container_copy_construction(__m.__tree_.__alloc()))
1513 {
1514 insert(__m.begin(), __m.end());
1515 }
1516
Howard Hinnantd3a657f2011-07-01 19:24:36 +00001517 _LIBCPP_INLINE_VISIBILITY
1518 multimap& operator=(const multimap& __m)
1519 {
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001520#if __cplusplus >= 201103L
Howard Hinnantd3a657f2011-07-01 19:24:36 +00001521 __tree_ = __m.__tree_;
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001522#else
1523 __tree_.clear();
1524 __tree_.value_comp() = __m.__tree_.value_comp();
1525 __tree_.__copy_assign_alloc(__m.__tree_);
1526 insert(__m.begin(), __m.end());
1527#endif
Howard Hinnantd3a657f2011-07-01 19:24:36 +00001528 return *this;
1529 }
1530
Howard Hinnant74279a52010-09-04 23:28:19 +00001531#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +00001532
Howard Hinnant756c69b2010-09-22 16:48:34 +00001533 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001534 multimap(multimap&& __m)
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001535 _NOEXCEPT_(is_nothrow_move_constructible<__base>::value)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001536 : __tree_(_VSTD::move(__m.__tree_))
Howard Hinnantc51e1022010-05-11 19:42:16 +00001537 {
1538 }
1539
1540 multimap(multimap&& __m, const allocator_type& __a);
1541
Howard Hinnant756c69b2010-09-22 16:48:34 +00001542 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant33711792011-08-12 21:56:02 +00001543 multimap& operator=(multimap&& __m)
1544 _NOEXCEPT_(is_nothrow_move_assignable<__base>::value)
1545 {
1546 __tree_ = _VSTD::move(__m.__tree_);
1547 return *this;
1548 }
1549
1550#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
1551
1552#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1553
1554 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001555 multimap(initializer_list<value_type> __il, const key_compare& __comp = key_compare())
1556 : __tree_(__vc(__comp))
1557 {
1558 insert(__il.begin(), __il.end());
1559 }
1560
Howard Hinnant756c69b2010-09-22 16:48:34 +00001561 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001562 multimap(initializer_list<value_type> __il, const key_compare& __comp, const allocator_type& __a)
1563 : __tree_(__vc(__comp), __a)
1564 {
1565 insert(__il.begin(), __il.end());
1566 }
1567
Howard Hinnant756c69b2010-09-22 16:48:34 +00001568 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001569 multimap& operator=(initializer_list<value_type> __il)
1570 {
1571 __tree_.__assign_multi(__il.begin(), __il.end());
1572 return *this;
1573 }
Howard Hinnant33711792011-08-12 21:56:02 +00001574
1575#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantc51e1022010-05-11 19:42:16 +00001576
Howard Hinnant756c69b2010-09-22 16:48:34 +00001577 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001578 explicit multimap(const allocator_type& __a)
1579 : __tree_(__a)
1580 {
1581 }
1582
Howard Hinnant756c69b2010-09-22 16:48:34 +00001583 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001584 multimap(const multimap& __m, const allocator_type& __a)
1585 : __tree_(__m.__tree_.value_comp(), __a)
1586 {
1587 insert(__m.begin(), __m.end());
1588 }
1589
Howard Hinnant756c69b2010-09-22 16:48:34 +00001590 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001591 iterator begin() _NOEXCEPT {return __tree_.begin();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001592 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001593 const_iterator begin() const _NOEXCEPT {return __tree_.begin();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001594 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001595 iterator end() _NOEXCEPT {return __tree_.end();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001596 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001597 const_iterator end() const _NOEXCEPT {return __tree_.end();}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001598
Howard Hinnant756c69b2010-09-22 16:48:34 +00001599 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001600 reverse_iterator rbegin() _NOEXCEPT {return reverse_iterator(end());}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001601 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001602 const_reverse_iterator rbegin() const _NOEXCEPT
1603 {return const_reverse_iterator(end());}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001604 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001605 reverse_iterator rend() _NOEXCEPT {return reverse_iterator(begin());}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001606 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001607 const_reverse_iterator rend() const _NOEXCEPT
1608 {return const_reverse_iterator(begin());}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001609
Howard Hinnant756c69b2010-09-22 16:48:34 +00001610 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001611 const_iterator cbegin() const _NOEXCEPT {return begin();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001612 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001613 const_iterator cend() const _NOEXCEPT {return end();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001614 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001615 const_reverse_iterator crbegin() const _NOEXCEPT {return rbegin();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001616 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001617 const_reverse_iterator crend() const _NOEXCEPT {return rend();}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001618
Howard Hinnant756c69b2010-09-22 16:48:34 +00001619 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001620 bool empty() const _NOEXCEPT {return __tree_.size() == 0;}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001621 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001622 size_type size() const _NOEXCEPT {return __tree_.size();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001623 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001624 size_type max_size() const _NOEXCEPT {return __tree_.max_size();}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001625
Howard Hinnant756c69b2010-09-22 16:48:34 +00001626 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001627 allocator_type get_allocator() const _NOEXCEPT {return __tree_.__alloc();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001628 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001629 key_compare key_comp() const {return __tree_.value_comp().key_comp();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001630 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001631 value_compare value_comp() const
1632 {return value_compare(__tree_.value_comp().key_comp());}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001633
Howard Hinnant74279a52010-09-04 23:28:19 +00001634#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant74279a52010-09-04 23:28:19 +00001635#ifndef _LIBCPP_HAS_NO_VARIADICS
1636
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001637 template <class ..._Args>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001638 iterator
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001639 emplace(_Args&& ...__args);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001640
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001641 template <class ..._Args>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001642 iterator
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001643 emplace_hint(const_iterator __p, _Args&& ...__args);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001644
Howard Hinnant74279a52010-09-04 23:28:19 +00001645#endif // _LIBCPP_HAS_NO_VARIADICS
1646
Howard Hinnantc834c512011-11-29 18:15:50 +00001647 template <class _Pp,
1648 class = typename enable_if<is_constructible<value_type, _Pp>::value>::type>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001649 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc834c512011-11-29 18:15:50 +00001650 iterator insert(_Pp&& __p)
1651 {return __tree_.__insert_multi(_VSTD::forward<_Pp>(__p));}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001652
Howard Hinnantc834c512011-11-29 18:15:50 +00001653 template <class _Pp,
1654 class = typename enable_if<is_constructible<value_type, _Pp>::value>::type>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001655 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc834c512011-11-29 18:15:50 +00001656 iterator insert(const_iterator __pos, _Pp&& __p)
1657 {return __tree_.__insert_multi(__pos.__i_, _VSTD::forward<_Pp>(__p));}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001658
Howard Hinnant74279a52010-09-04 23:28:19 +00001659#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +00001660
Howard Hinnant756c69b2010-09-22 16:48:34 +00001661 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001662 iterator insert(const value_type& __v) {return __tree_.__insert_multi(__v);}
1663
Howard Hinnant756c69b2010-09-22 16:48:34 +00001664 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001665 iterator insert(const_iterator __p, const value_type& __v)
1666 {return __tree_.__insert_multi(__p.__i_, __v);}
1667
1668 template <class _InputIterator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001669 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001670 void insert(_InputIterator __f, _InputIterator __l)
1671 {
1672 for (const_iterator __e = cend(); __f != __l; ++__f)
1673 __tree_.__insert_multi(__e.__i_, *__f);
1674 }
1675
Howard Hinnant33711792011-08-12 21:56:02 +00001676#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1677
Howard Hinnant756c69b2010-09-22 16:48:34 +00001678 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001679 void insert(initializer_list<value_type> __il)
1680 {insert(__il.begin(), __il.end());}
1681
Howard Hinnant33711792011-08-12 21:56:02 +00001682#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1683
Howard Hinnant756c69b2010-09-22 16:48:34 +00001684 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001685 iterator erase(const_iterator __p) {return __tree_.erase(__p.__i_);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001686 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001687 size_type erase(const key_type& __k) {return __tree_.__erase_multi(__k);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001688 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001689 iterator erase(const_iterator __f, const_iterator __l)
1690 {return __tree_.erase(__f.__i_, __l.__i_);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001691 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001692 void clear() {__tree_.clear();}
1693
Howard Hinnant756c69b2010-09-22 16:48:34 +00001694 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001695 void swap(multimap& __m)
1696 _NOEXCEPT_(__is_nothrow_swappable<__base>::value)
1697 {__tree_.swap(__m.__tree_);}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001698
Howard Hinnant756c69b2010-09-22 16:48:34 +00001699 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001700 iterator find(const key_type& __k) {return __tree_.find(__k);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001701 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001702 const_iterator find(const key_type& __k) const {return __tree_.find(__k);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001703 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001704 size_type count(const key_type& __k) const
1705 {return __tree_.__count_multi(__k);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001706 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001707 iterator lower_bound(const key_type& __k)
1708 {return __tree_.lower_bound(__k);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001709 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001710 const_iterator lower_bound(const key_type& __k) const
1711 {return __tree_.lower_bound(__k);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001712 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001713 iterator upper_bound(const key_type& __k)
1714 {return __tree_.upper_bound(__k);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001715 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001716 const_iterator upper_bound(const key_type& __k) const
1717 {return __tree_.upper_bound(__k);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001718 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001719 pair<iterator,iterator> equal_range(const key_type& __k)
1720 {return __tree_.__equal_range_multi(__k);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001721 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001722 pair<const_iterator,const_iterator> equal_range(const key_type& __k) const
1723 {return __tree_.__equal_range_multi(__k);}
1724
1725private:
1726 typedef typename __base::__node __node;
1727 typedef typename __base::__node_allocator __node_allocator;
1728 typedef typename __base::__node_pointer __node_pointer;
1729 typedef typename __base::__node_const_pointer __node_const_pointer;
Howard Hinnantc834c512011-11-29 18:15:50 +00001730 typedef __map_node_destructor<__node_allocator> _Dp;
1731 typedef unique_ptr<__node, _Dp> __node_holder;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001732
Howard Hinnant74279a52010-09-04 23:28:19 +00001733#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +00001734 __node_holder __construct_node();
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001735 template <class _A0>
1736 typename enable_if
1737 <
1738 is_constructible<value_type, _A0>::value,
1739 __node_holder
1740 >::type
1741 __construct_node(_A0&& __a0);
1742 template <class _A0>
1743 typename enable_if
1744 <
1745 is_constructible<key_type, _A0>::value,
1746 __node_holder
1747 >::type
1748 __construct_node(_A0&& __a0);
Howard Hinnant74279a52010-09-04 23:28:19 +00001749#ifndef _LIBCPP_HAS_NO_VARIADICS
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001750 template <class _A0, class _A1, class ..._Args>
1751 __node_holder __construct_node(_A0&& __a0, _A1&& __a1, _Args&& ...__args);
Howard Hinnant74279a52010-09-04 23:28:19 +00001752#endif // _LIBCPP_HAS_NO_VARIADICS
1753#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +00001754};
1755
Howard Hinnant74279a52010-09-04 23:28:19 +00001756#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +00001757
1758template <class _Key, class _Tp, class _Compare, class _Allocator>
1759multimap<_Key, _Tp, _Compare, _Allocator>::multimap(multimap&& __m, const allocator_type& __a)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001760 : __tree_(_VSTD::move(__m.__tree_), __a)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001761{
1762 if (__a != __m.get_allocator())
1763 {
1764 const_iterator __e = cend();
1765 while (!__m.empty())
1766 __tree_.__insert_multi(__e.__i_,
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001767 _VSTD::move(__m.__tree_.remove(__m.begin().__i_)->__value_));
Howard Hinnantc51e1022010-05-11 19:42:16 +00001768 }
1769}
1770
1771template <class _Key, class _Tp, class _Compare, class _Allocator>
1772typename multimap<_Key, _Tp, _Compare, _Allocator>::__node_holder
1773multimap<_Key, _Tp, _Compare, _Allocator>::__construct_node()
1774{
1775 __node_allocator& __na = __tree_.__node_alloc();
Howard Hinnantc834c512011-11-29 18:15:50 +00001776 __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001777 __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__cc.first));
Howard Hinnantc51e1022010-05-11 19:42:16 +00001778 __h.get_deleter().__first_constructed = true;
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001779 __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__cc.second));
Howard Hinnantc51e1022010-05-11 19:42:16 +00001780 __h.get_deleter().__second_constructed = true;
1781 return __h;
1782}
1783
1784template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001785template <class _A0>
1786typename enable_if
1787<
1788 is_constructible<pair<const _Key, _Tp>, _A0>::value,
1789 typename multimap<_Key, _Tp, _Compare, _Allocator>::__node_holder
1790>::type
Howard Hinnantc51e1022010-05-11 19:42:16 +00001791multimap<_Key, _Tp, _Compare, _Allocator>::__construct_node(_A0&& __a0)
1792{
1793 __node_allocator& __na = __tree_.__node_alloc();
Howard Hinnantc834c512011-11-29 18:15:50 +00001794 __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001795 __node_traits::construct(__na, _VSTD::addressof(__h->__value_), _VSTD::forward<_A0>(__a0));
Howard Hinnantc51e1022010-05-11 19:42:16 +00001796 __h.get_deleter().__first_constructed = true;
1797 __h.get_deleter().__second_constructed = true;
1798 return __h;
1799}
1800
1801template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001802template <class _A0>
1803typename enable_if
1804<
1805 is_constructible<_Key, _A0>::value,
1806 typename multimap<_Key, _Tp, _Compare, _Allocator>::__node_holder
1807>::type
1808multimap<_Key, _Tp, _Compare, _Allocator>::__construct_node(_A0&& __a0)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001809{
1810 __node_allocator& __na = __tree_.__node_alloc();
Howard Hinnantc834c512011-11-29 18:15:50 +00001811 __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001812 __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__cc.first), _VSTD::forward<_A0>(__a0));
Howard Hinnantc51e1022010-05-11 19:42:16 +00001813 __h.get_deleter().__first_constructed = true;
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001814 __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__cc.second));
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001815 __h.get_deleter().__second_constructed = true;
1816 return __h;
1817}
1818
1819#ifndef _LIBCPP_HAS_NO_VARIADICS
1820
1821template <class _Key, class _Tp, class _Compare, class _Allocator>
1822template <class _A0, class _A1, class ..._Args>
1823typename multimap<_Key, _Tp, _Compare, _Allocator>::__node_holder
1824multimap<_Key, _Tp, _Compare, _Allocator>::__construct_node(_A0&& __a0, _A1&& __a1, _Args&& ...__args)
1825{
1826 __node_allocator& __na = __tree_.__node_alloc();
1827 __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
1828 __node_traits::construct(__na, _VSTD::addressof(__h->__value_),
1829 _VSTD::forward<_A0>(__a0), _VSTD::forward<_A1>(__a1),
1830 _VSTD::forward<_Args>(__args)...);
1831 __h.get_deleter().__first_constructed = true;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001832 __h.get_deleter().__second_constructed = true;
1833 return __h;
1834}
1835
Howard Hinnant74279a52010-09-04 23:28:19 +00001836#endif // _LIBCPP_HAS_NO_VARIADICS
1837#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +00001838
Howard Hinnant74279a52010-09-04 23:28:19 +00001839#if !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001840
1841template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001842template <class ..._Args>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001843typename multimap<_Key, _Tp, _Compare, _Allocator>::iterator
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001844multimap<_Key, _Tp, _Compare, _Allocator>::emplace(_Args&& ...__args)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001845{
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001846 __node_holder __h = __construct_node(_VSTD::forward<_Args>(__args)...);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001847 iterator __r = __tree_.__node_insert_multi(__h.get());
1848 __h.release();
1849 return __r;
1850}
1851
1852template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001853template <class ..._Args>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001854typename multimap<_Key, _Tp, _Compare, _Allocator>::iterator
1855multimap<_Key, _Tp, _Compare, _Allocator>::emplace_hint(const_iterator __p,
Howard Hinnantc51e1022010-05-11 19:42:16 +00001856 _Args&& ...__args)
1857{
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001858 __node_holder __h = __construct_node(_VSTD::forward<_Args>(__args)...);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001859 iterator __r = __tree_.__node_insert_multi(__p.__i_, __h.get());
1860 __h.release();
1861 return __r;
1862}
1863
Howard Hinnant74279a52010-09-04 23:28:19 +00001864#endif // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001865
1866template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001867inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001868bool
1869operator==(const multimap<_Key, _Tp, _Compare, _Allocator>& __x,
1870 const multimap<_Key, _Tp, _Compare, _Allocator>& __y)
1871{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001872 return __x.size() == __y.size() && _VSTD::equal(__x.begin(), __x.end(), __y.begin());
Howard Hinnantc51e1022010-05-11 19:42:16 +00001873}
1874
1875template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001876inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001877bool
1878operator< (const multimap<_Key, _Tp, _Compare, _Allocator>& __x,
1879 const multimap<_Key, _Tp, _Compare, _Allocator>& __y)
1880{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001881 return _VSTD::lexicographical_compare(__x.begin(), __x.end(), __y.begin(), __y.end());
Howard Hinnantc51e1022010-05-11 19:42:16 +00001882}
1883
1884template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001885inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001886bool
1887operator!=(const multimap<_Key, _Tp, _Compare, _Allocator>& __x,
1888 const multimap<_Key, _Tp, _Compare, _Allocator>& __y)
1889{
1890 return !(__x == __y);
1891}
1892
1893template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001894inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001895bool
1896operator> (const multimap<_Key, _Tp, _Compare, _Allocator>& __x,
1897 const multimap<_Key, _Tp, _Compare, _Allocator>& __y)
1898{
1899 return __y < __x;
1900}
1901
1902template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001903inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001904bool
1905operator>=(const multimap<_Key, _Tp, _Compare, _Allocator>& __x,
1906 const multimap<_Key, _Tp, _Compare, _Allocator>& __y)
1907{
1908 return !(__x < __y);
1909}
1910
1911template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001912inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001913bool
1914operator<=(const multimap<_Key, _Tp, _Compare, _Allocator>& __x,
1915 const multimap<_Key, _Tp, _Compare, _Allocator>& __y)
1916{
1917 return !(__y < __x);
1918}
1919
1920template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001921inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001922void
1923swap(multimap<_Key, _Tp, _Compare, _Allocator>& __x,
1924 multimap<_Key, _Tp, _Compare, _Allocator>& __y)
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001925 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
Howard Hinnantc51e1022010-05-11 19:42:16 +00001926{
1927 __x.swap(__y);
1928}
1929
1930_LIBCPP_END_NAMESPACE_STD
1931
1932#endif // _LIBCPP_MAP