blob: 4107eadd754f2f6c11be7574a4432f9ba52d4391 [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>
Howard Hinnantac7e7482013-07-04 20:59:16 +00001006 __node_holder __construct_node(_A0&& __a0);
1007 __node_holder __construct_node_with_key(key_type&& __k);
Howard Hinnant74279a52010-09-04 23:28:19 +00001008#ifndef _LIBCPP_HAS_NO_VARIADICS
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001009 template <class _A0, class _A1, class ..._Args>
1010 __node_holder __construct_node(_A0&& __a0, _A1&& __a1, _Args&& ...__args);
Howard Hinnant74279a52010-09-04 23:28:19 +00001011#endif // _LIBCPP_HAS_NO_VARIADICS
Howard Hinnantc51e1022010-05-11 19:42:16 +00001012#endif
Howard Hinnantac7e7482013-07-04 20:59:16 +00001013 __node_holder __construct_node_with_key(const key_type& __k);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001014
1015 __node_base_pointer&
1016 __find_equal_key(__node_base_pointer& __parent, const key_type& __k);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001017 __node_base_const_pointer
1018 __find_equal_key(__node_base_const_pointer& __parent, const key_type& __k) const;
1019};
1020
1021// Find place to insert if __k doesn't exist
1022// Set __parent to parent of null leaf
1023// Return reference to null leaf
1024// If __k exists, set parent to node of __k and return reference to node of __k
1025template <class _Key, class _Tp, class _Compare, class _Allocator>
1026typename map<_Key, _Tp, _Compare, _Allocator>::__node_base_pointer&
1027map<_Key, _Tp, _Compare, _Allocator>::__find_equal_key(__node_base_pointer& __parent,
1028 const key_type& __k)
1029{
1030 __node_pointer __nd = __tree_.__root();
1031 if (__nd != nullptr)
1032 {
1033 while (true)
1034 {
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001035 if (__tree_.value_comp().key_comp()(__k, __nd->__value_.__cc.first))
Howard Hinnantc51e1022010-05-11 19:42:16 +00001036 {
1037 if (__nd->__left_ != nullptr)
1038 __nd = static_cast<__node_pointer>(__nd->__left_);
1039 else
1040 {
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001041 __parent = static_cast<__node_base_pointer>(__nd);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001042 return __parent->__left_;
1043 }
1044 }
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001045 else if (__tree_.value_comp().key_comp()(__nd->__value_.__cc.first, __k))
Howard Hinnantc51e1022010-05-11 19:42:16 +00001046 {
1047 if (__nd->__right_ != nullptr)
1048 __nd = static_cast<__node_pointer>(__nd->__right_);
1049 else
1050 {
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001051 __parent = static_cast<__node_base_pointer>(__nd);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001052 return __parent->__right_;
1053 }
1054 }
1055 else
1056 {
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001057 __parent = static_cast<__node_base_pointer>(__nd);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001058 return __parent;
1059 }
1060 }
1061 }
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001062 __parent = static_cast<__node_base_pointer>(__tree_.__end_node());
Howard Hinnantc51e1022010-05-11 19:42:16 +00001063 return __parent->__left_;
1064}
1065
Howard Hinnantc51e1022010-05-11 19:42:16 +00001066// Find __k
1067// Set __parent to parent of null leaf and
1068// return reference to null leaf iv __k does not exist.
1069// If __k exists, set parent to node of __k and return reference to node of __k
1070template <class _Key, class _Tp, class _Compare, class _Allocator>
1071typename map<_Key, _Tp, _Compare, _Allocator>::__node_base_const_pointer
1072map<_Key, _Tp, _Compare, _Allocator>::__find_equal_key(__node_base_const_pointer& __parent,
1073 const key_type& __k) const
1074{
1075 __node_const_pointer __nd = __tree_.__root();
1076 if (__nd != nullptr)
1077 {
1078 while (true)
1079 {
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001080 if (__tree_.value_comp().key_comp()(__k, __nd->__value_.__cc.first))
Howard Hinnantc51e1022010-05-11 19:42:16 +00001081 {
1082 if (__nd->__left_ != nullptr)
1083 __nd = static_cast<__node_pointer>(__nd->__left_);
1084 else
1085 {
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001086 __parent = static_cast<__node_base_pointer>(__nd);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001087 return const_cast<const __node_base_const_pointer&>(__parent->__left_);
1088 }
1089 }
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001090 else if (__tree_.value_comp().key_comp()(__nd->__value_.__cc.first, __k))
Howard Hinnantc51e1022010-05-11 19:42:16 +00001091 {
1092 if (__nd->__right_ != nullptr)
1093 __nd = static_cast<__node_pointer>(__nd->__right_);
1094 else
1095 {
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001096 __parent = static_cast<__node_base_pointer>(__nd);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001097 return const_cast<const __node_base_const_pointer&>(__parent->__right_);
1098 }
1099 }
1100 else
1101 {
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001102 __parent = static_cast<__node_base_pointer>(__nd);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001103 return __parent;
1104 }
1105 }
1106 }
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001107 __parent = static_cast<__node_base_pointer>(__tree_.__end_node());
Howard Hinnantc51e1022010-05-11 19:42:16 +00001108 return const_cast<const __node_base_const_pointer&>(__parent->__left_);
1109}
1110
Howard Hinnant74279a52010-09-04 23:28:19 +00001111#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +00001112
1113template <class _Key, class _Tp, class _Compare, class _Allocator>
1114map<_Key, _Tp, _Compare, _Allocator>::map(map&& __m, const allocator_type& __a)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001115 : __tree_(_VSTD::move(__m.__tree_), __a)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001116{
1117 if (__a != __m.get_allocator())
1118 {
1119 const_iterator __e = cend();
1120 while (!__m.empty())
1121 __tree_.__insert_unique(__e.__i_,
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001122 _VSTD::move(__m.__tree_.remove(__m.begin().__i_)->__value_));
Howard Hinnantc51e1022010-05-11 19:42:16 +00001123 }
1124}
1125
1126template <class _Key, class _Tp, class _Compare, class _Allocator>
1127typename map<_Key, _Tp, _Compare, _Allocator>::__node_holder
1128map<_Key, _Tp, _Compare, _Allocator>::__construct_node()
1129{
1130 __node_allocator& __na = __tree_.__node_alloc();
Howard Hinnantc834c512011-11-29 18:15:50 +00001131 __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001132 __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__cc.first));
Howard Hinnantc51e1022010-05-11 19:42:16 +00001133 __h.get_deleter().__first_constructed = true;
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001134 __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__cc.second));
Howard Hinnantc51e1022010-05-11 19:42:16 +00001135 __h.get_deleter().__second_constructed = true;
1136 return __h;
1137}
1138
1139template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001140template <class _A0>
Howard Hinnantac7e7482013-07-04 20:59:16 +00001141typename map<_Key, _Tp, _Compare, _Allocator>::__node_holder
Howard Hinnantc51e1022010-05-11 19:42:16 +00001142map<_Key, _Tp, _Compare, _Allocator>::__construct_node(_A0&& __a0)
1143{
1144 __node_allocator& __na = __tree_.__node_alloc();
Howard Hinnantc834c512011-11-29 18:15:50 +00001145 __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001146 __node_traits::construct(__na, _VSTD::addressof(__h->__value_), _VSTD::forward<_A0>(__a0));
Howard Hinnantc51e1022010-05-11 19:42:16 +00001147 __h.get_deleter().__first_constructed = true;
1148 __h.get_deleter().__second_constructed = true;
1149 return __h;
1150}
1151
1152template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnantac7e7482013-07-04 20:59:16 +00001153typename map<_Key, _Tp, _Compare, _Allocator>::__node_holder
1154map<_Key, _Tp, _Compare, _Allocator>::__construct_node_with_key(key_type&& __k)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001155{
1156 __node_allocator& __na = __tree_.__node_alloc();
Howard Hinnantc834c512011-11-29 18:15:50 +00001157 __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
Howard Hinnantac7e7482013-07-04 20:59:16 +00001158 __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__cc.first), _VSTD::move(__k));
Howard Hinnantc51e1022010-05-11 19:42:16 +00001159 __h.get_deleter().__first_constructed = true;
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001160 __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__cc.second));
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001161 __h.get_deleter().__second_constructed = true;
Howard Hinnantac7e7482013-07-04 20:59:16 +00001162 return _VSTD::move(__h);
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001163}
1164
1165#ifndef _LIBCPP_HAS_NO_VARIADICS
1166
1167template <class _Key, class _Tp, class _Compare, class _Allocator>
1168template <class _A0, class _A1, class ..._Args>
1169typename map<_Key, _Tp, _Compare, _Allocator>::__node_holder
1170map<_Key, _Tp, _Compare, _Allocator>::__construct_node(_A0&& __a0, _A1&& __a1, _Args&& ...__args)
1171{
1172 __node_allocator& __na = __tree_.__node_alloc();
1173 __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
1174 __node_traits::construct(__na, _VSTD::addressof(__h->__value_),
1175 _VSTD::forward<_A0>(__a0), _VSTD::forward<_A1>(__a1),
1176 _VSTD::forward<_Args>(__args)...);
1177 __h.get_deleter().__first_constructed = true;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001178 __h.get_deleter().__second_constructed = true;
1179 return __h;
1180}
1181
Howard Hinnant74279a52010-09-04 23:28:19 +00001182#endif // _LIBCPP_HAS_NO_VARIADICS
1183
Howard Hinnantac7e7482013-07-04 20:59:16 +00001184#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +00001185
1186template <class _Key, class _Tp, class _Compare, class _Allocator>
1187typename map<_Key, _Tp, _Compare, _Allocator>::__node_holder
Howard Hinnantac7e7482013-07-04 20:59:16 +00001188map<_Key, _Tp, _Compare, _Allocator>::__construct_node_with_key(const key_type& __k)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001189{
1190 __node_allocator& __na = __tree_.__node_alloc();
Howard Hinnantc834c512011-11-29 18:15:50 +00001191 __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001192 __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__cc.first), __k);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001193 __h.get_deleter().__first_constructed = true;
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001194 __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__cc.second));
Howard Hinnantc51e1022010-05-11 19:42:16 +00001195 __h.get_deleter().__second_constructed = true;
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001196 return _VSTD::move(__h);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001197}
1198
Howard Hinnantc51e1022010-05-11 19:42:16 +00001199template <class _Key, class _Tp, class _Compare, class _Allocator>
1200_Tp&
1201map<_Key, _Tp, _Compare, _Allocator>::operator[](const key_type& __k)
1202{
1203 __node_base_pointer __parent;
1204 __node_base_pointer& __child = __find_equal_key(__parent, __k);
1205 __node_pointer __r = static_cast<__node_pointer>(__child);
1206 if (__child == nullptr)
1207 {
Howard Hinnantac7e7482013-07-04 20:59:16 +00001208 __node_holder __h = __construct_node_with_key(__k);
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001209 __tree_.__insert_node_at(__parent, __child, static_cast<__node_base_pointer>(__h.get()));
Howard Hinnantc51e1022010-05-11 19:42:16 +00001210 __r = __h.release();
1211 }
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001212 return __r->__value_.__cc.second;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001213}
1214
Howard Hinnant74279a52010-09-04 23:28:19 +00001215#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +00001216
1217template <class _Key, class _Tp, class _Compare, class _Allocator>
1218_Tp&
1219map<_Key, _Tp, _Compare, _Allocator>::operator[](key_type&& __k)
1220{
1221 __node_base_pointer __parent;
1222 __node_base_pointer& __child = __find_equal_key(__parent, __k);
1223 __node_pointer __r = static_cast<__node_pointer>(__child);
1224 if (__child == nullptr)
1225 {
Howard Hinnantac7e7482013-07-04 20:59:16 +00001226 __node_holder __h = __construct_node_with_key(_VSTD::move(__k));
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001227 __tree_.__insert_node_at(__parent, __child, static_cast<__node_base_pointer>(__h.get()));
Howard Hinnantc51e1022010-05-11 19:42:16 +00001228 __r = __h.release();
1229 }
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001230 return __r->__value_.__cc.second;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001231}
1232
Howard Hinnant74279a52010-09-04 23:28:19 +00001233#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +00001234
1235template <class _Key, class _Tp, class _Compare, class _Allocator>
1236_Tp&
1237map<_Key, _Tp, _Compare, _Allocator>::at(const key_type& __k)
1238{
1239 __node_base_pointer __parent;
1240 __node_base_pointer& __child = __find_equal_key(__parent, __k);
Howard Hinnant72f73582010-08-11 17:04:31 +00001241#ifndef _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +00001242 if (__child == nullptr)
1243 throw out_of_range("map::at: key not found");
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001244#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001245 return static_cast<__node_pointer>(__child)->__value_.__cc.second;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001246}
1247
1248template <class _Key, class _Tp, class _Compare, class _Allocator>
1249const _Tp&
1250map<_Key, _Tp, _Compare, _Allocator>::at(const key_type& __k) const
1251{
1252 __node_base_const_pointer __parent;
1253 __node_base_const_pointer __child = __find_equal_key(__parent, __k);
Howard Hinnant72f73582010-08-11 17:04:31 +00001254#ifndef _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +00001255 if (__child == nullptr)
1256 throw out_of_range("map::at: key not found");
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001257#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001258 return static_cast<__node_const_pointer>(__child)->__value_.__cc.second;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001259}
1260
Howard Hinnant74279a52010-09-04 23:28:19 +00001261#if !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001262
1263template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001264template <class ..._Args>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001265pair<typename map<_Key, _Tp, _Compare, _Allocator>::iterator, bool>
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001266map<_Key, _Tp, _Compare, _Allocator>::emplace(_Args&& ...__args)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001267{
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001268 __node_holder __h = __construct_node(_VSTD::forward<_Args>(__args)...);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001269 pair<iterator, bool> __r = __tree_.__node_insert_unique(__h.get());
1270 if (__r.second)
1271 __h.release();
1272 return __r;
1273}
1274
1275template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001276template <class ..._Args>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001277typename map<_Key, _Tp, _Compare, _Allocator>::iterator
1278map<_Key, _Tp, _Compare, _Allocator>::emplace_hint(const_iterator __p,
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001279 _Args&& ...__args)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001280{
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001281 __node_holder __h = __construct_node(_VSTD::forward<_Args>(__args)...);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001282 iterator __r = __tree_.__node_insert_unique(__p.__i_, __h.get());
1283 if (__r.__i_.__ptr_ == __h.get())
1284 __h.release();
1285 return __r;
1286}
1287
Howard Hinnant74279a52010-09-04 23:28:19 +00001288#endif // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001289
1290template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001291inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001292bool
1293operator==(const map<_Key, _Tp, _Compare, _Allocator>& __x,
1294 const map<_Key, _Tp, _Compare, _Allocator>& __y)
1295{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001296 return __x.size() == __y.size() && _VSTD::equal(__x.begin(), __x.end(), __y.begin());
Howard Hinnantc51e1022010-05-11 19:42:16 +00001297}
1298
1299template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001300inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001301bool
1302operator< (const map<_Key, _Tp, _Compare, _Allocator>& __x,
1303 const map<_Key, _Tp, _Compare, _Allocator>& __y)
1304{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001305 return _VSTD::lexicographical_compare(__x.begin(), __x.end(), __y.begin(), __y.end());
Howard Hinnantc51e1022010-05-11 19:42:16 +00001306}
1307
1308template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001309inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001310bool
1311operator!=(const map<_Key, _Tp, _Compare, _Allocator>& __x,
1312 const map<_Key, _Tp, _Compare, _Allocator>& __y)
1313{
1314 return !(__x == __y);
1315}
1316
1317template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001318inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001319bool
1320operator> (const map<_Key, _Tp, _Compare, _Allocator>& __x,
1321 const map<_Key, _Tp, _Compare, _Allocator>& __y)
1322{
1323 return __y < __x;
1324}
1325
1326template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001327inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001328bool
1329operator>=(const map<_Key, _Tp, _Compare, _Allocator>& __x,
1330 const map<_Key, _Tp, _Compare, _Allocator>& __y)
1331{
1332 return !(__x < __y);
1333}
1334
1335template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001336inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001337bool
1338operator<=(const map<_Key, _Tp, _Compare, _Allocator>& __x,
1339 const map<_Key, _Tp, _Compare, _Allocator>& __y)
1340{
1341 return !(__y < __x);
1342}
1343
1344template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001345inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001346void
1347swap(map<_Key, _Tp, _Compare, _Allocator>& __x,
1348 map<_Key, _Tp, _Compare, _Allocator>& __y)
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001349 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
Howard Hinnantc51e1022010-05-11 19:42:16 +00001350{
1351 __x.swap(__y);
1352}
1353
1354template <class _Key, class _Tp, class _Compare = less<_Key>,
1355 class _Allocator = allocator<pair<const _Key, _Tp> > >
Howard Hinnant8331b762013-03-06 23:30:19 +00001356class _LIBCPP_TYPE_VIS multimap
Howard Hinnantc51e1022010-05-11 19:42:16 +00001357{
1358public:
1359 // types:
1360 typedef _Key key_type;
1361 typedef _Tp mapped_type;
1362 typedef pair<const key_type, mapped_type> value_type;
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001363 typedef pair<key_type, mapped_type> __nc_value_type;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001364 typedef _Compare key_compare;
1365 typedef _Allocator allocator_type;
1366 typedef value_type& reference;
1367 typedef const value_type& const_reference;
1368
Howard Hinnant8331b762013-03-06 23:30:19 +00001369 class _LIBCPP_TYPE_VIS value_compare
Howard Hinnantc51e1022010-05-11 19:42:16 +00001370 : public binary_function<value_type, value_type, bool>
1371 {
1372 friend class multimap;
1373 protected:
1374 key_compare comp;
1375
Howard Hinnant756c69b2010-09-22 16:48:34 +00001376 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001377 value_compare(key_compare c) : comp(c) {}
1378 public:
Howard Hinnant756c69b2010-09-22 16:48:34 +00001379 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001380 bool operator()(const value_type& __x, const value_type& __y) const
1381 {return comp(__x.first, __y.first);}
1382 };
1383
1384private:
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001385#if __cplusplus >= 201103L
1386 union __value_type
1387 {
1388 typedef typename multimap::value_type value_type;
1389 typedef typename multimap::__nc_value_type __nc_value_type;
1390 value_type __cc;
1391 __nc_value_type __nc;
1392
1393 template <class ..._Args>
1394 __value_type(_Args&& ...__args)
1395 : __cc(std::forward<_Args>(__args)...) {}
1396
1397 __value_type(const __value_type& __v)
1398 : __cc(std::move(__v.__cc)) {}
1399
1400 __value_type(__value_type&& __v)
1401 : __nc(std::move(__v.__nc)) {}
1402
1403 __value_type& operator=(const __value_type& __v)
1404 {__nc = __v.__cc; return *this;}
1405
1406 __value_type& operator=(__value_type&& __v)
1407 {__nc = std::move(__v.__nc); return *this;}
1408
1409 ~__value_type() {__cc.~value_type();}
1410
1411 operator const value_type& () const {return __cc;}
1412 };
1413#else
1414 struct __value_type
1415 {
1416 typedef typename multimap::value_type value_type;
1417 value_type __cc;
1418
1419 __value_type() {}
1420
1421 template <class _A0>
1422 __value_type(const _A0& __a0)
1423 : __cc(__a0) {}
1424
1425 template <class _A0, class _A1>
1426 __value_type(const _A0& __a0, const _A1& __a1)
1427 : __cc(__a0, __a1) {}
1428
1429 operator const value_type& () const {return __cc;}
1430 };
1431#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001432 typedef __map_value_compare<key_type, mapped_type, key_compare> __vc;
1433 typedef typename allocator_traits<allocator_type>::template
1434#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
1435 rebind_alloc<__value_type>
1436#else
1437 rebind_alloc<__value_type>::other
1438#endif
1439 __allocator_type;
1440 typedef __tree<__value_type, __vc, __allocator_type> __base;
1441 typedef typename __base::__node_traits __node_traits;
1442 typedef allocator_traits<allocator_type> __alloc_traits;
1443
1444 __base __tree_;
1445
1446public:
1447 typedef typename __alloc_traits::pointer pointer;
1448 typedef typename __alloc_traits::const_pointer const_pointer;
1449 typedef typename __alloc_traits::size_type size_type;
1450 typedef typename __alloc_traits::difference_type difference_type;
1451 typedef __map_iterator<typename __base::iterator> iterator;
1452 typedef __map_const_iterator<typename __base::const_iterator> const_iterator;
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001453 typedef _VSTD::reverse_iterator<iterator> reverse_iterator;
1454 typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001455
Howard Hinnant756c69b2010-09-22 16:48:34 +00001456 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001457 explicit multimap(const key_compare& __comp = key_compare())
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001458 _NOEXCEPT_(
1459 is_nothrow_default_constructible<allocator_type>::value &&
1460 is_nothrow_default_constructible<key_compare>::value &&
1461 is_nothrow_copy_constructible<key_compare>::value)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001462 : __tree_(__vc(__comp)) {}
1463
Howard Hinnant756c69b2010-09-22 16:48:34 +00001464 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001465 explicit multimap(const key_compare& __comp, const allocator_type& __a)
1466 : __tree_(__vc(__comp), __a) {}
1467
1468 template <class _InputIterator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001469 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001470 multimap(_InputIterator __f, _InputIterator __l,
1471 const key_compare& __comp = key_compare())
1472 : __tree_(__vc(__comp))
1473 {
1474 insert(__f, __l);
1475 }
1476
1477 template <class _InputIterator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001478 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001479 multimap(_InputIterator __f, _InputIterator __l,
1480 const key_compare& __comp, const allocator_type& __a)
1481 : __tree_(__vc(__comp), __a)
1482 {
1483 insert(__f, __l);
1484 }
1485
Howard Hinnant756c69b2010-09-22 16:48:34 +00001486 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001487 multimap(const multimap& __m)
1488 : __tree_(__m.__tree_.value_comp(),
1489 __alloc_traits::select_on_container_copy_construction(__m.__tree_.__alloc()))
1490 {
1491 insert(__m.begin(), __m.end());
1492 }
1493
Howard Hinnantd3a657f2011-07-01 19:24:36 +00001494 _LIBCPP_INLINE_VISIBILITY
1495 multimap& operator=(const multimap& __m)
1496 {
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001497#if __cplusplus >= 201103L
Howard Hinnantd3a657f2011-07-01 19:24:36 +00001498 __tree_ = __m.__tree_;
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001499#else
1500 __tree_.clear();
1501 __tree_.value_comp() = __m.__tree_.value_comp();
1502 __tree_.__copy_assign_alloc(__m.__tree_);
1503 insert(__m.begin(), __m.end());
1504#endif
Howard Hinnantd3a657f2011-07-01 19:24:36 +00001505 return *this;
1506 }
1507
Howard Hinnant74279a52010-09-04 23:28:19 +00001508#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +00001509
Howard Hinnant756c69b2010-09-22 16:48:34 +00001510 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001511 multimap(multimap&& __m)
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001512 _NOEXCEPT_(is_nothrow_move_constructible<__base>::value)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001513 : __tree_(_VSTD::move(__m.__tree_))
Howard Hinnantc51e1022010-05-11 19:42:16 +00001514 {
1515 }
1516
1517 multimap(multimap&& __m, const allocator_type& __a);
1518
Howard Hinnant756c69b2010-09-22 16:48:34 +00001519 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant33711792011-08-12 21:56:02 +00001520 multimap& operator=(multimap&& __m)
1521 _NOEXCEPT_(is_nothrow_move_assignable<__base>::value)
1522 {
1523 __tree_ = _VSTD::move(__m.__tree_);
1524 return *this;
1525 }
1526
1527#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
1528
1529#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1530
1531 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001532 multimap(initializer_list<value_type> __il, const key_compare& __comp = key_compare())
1533 : __tree_(__vc(__comp))
1534 {
1535 insert(__il.begin(), __il.end());
1536 }
1537
Howard Hinnant756c69b2010-09-22 16:48:34 +00001538 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001539 multimap(initializer_list<value_type> __il, const key_compare& __comp, const allocator_type& __a)
1540 : __tree_(__vc(__comp), __a)
1541 {
1542 insert(__il.begin(), __il.end());
1543 }
1544
Howard Hinnant756c69b2010-09-22 16:48:34 +00001545 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001546 multimap& operator=(initializer_list<value_type> __il)
1547 {
1548 __tree_.__assign_multi(__il.begin(), __il.end());
1549 return *this;
1550 }
Howard Hinnant33711792011-08-12 21:56:02 +00001551
1552#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantc51e1022010-05-11 19:42:16 +00001553
Howard Hinnant756c69b2010-09-22 16:48:34 +00001554 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001555 explicit multimap(const allocator_type& __a)
1556 : __tree_(__a)
1557 {
1558 }
1559
Howard Hinnant756c69b2010-09-22 16:48:34 +00001560 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001561 multimap(const multimap& __m, const allocator_type& __a)
1562 : __tree_(__m.__tree_.value_comp(), __a)
1563 {
1564 insert(__m.begin(), __m.end());
1565 }
1566
Howard Hinnant756c69b2010-09-22 16:48:34 +00001567 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001568 iterator begin() _NOEXCEPT {return __tree_.begin();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001569 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001570 const_iterator begin() const _NOEXCEPT {return __tree_.begin();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001571 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001572 iterator end() _NOEXCEPT {return __tree_.end();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001573 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001574 const_iterator end() const _NOEXCEPT {return __tree_.end();}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001575
Howard Hinnant756c69b2010-09-22 16:48:34 +00001576 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001577 reverse_iterator rbegin() _NOEXCEPT {return reverse_iterator(end());}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001578 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001579 const_reverse_iterator rbegin() const _NOEXCEPT
1580 {return const_reverse_iterator(end());}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001581 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001582 reverse_iterator rend() _NOEXCEPT {return reverse_iterator(begin());}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001583 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001584 const_reverse_iterator rend() const _NOEXCEPT
1585 {return const_reverse_iterator(begin());}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001586
Howard Hinnant756c69b2010-09-22 16:48:34 +00001587 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001588 const_iterator cbegin() const _NOEXCEPT {return begin();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001589 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001590 const_iterator cend() const _NOEXCEPT {return end();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001591 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001592 const_reverse_iterator crbegin() const _NOEXCEPT {return rbegin();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001593 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001594 const_reverse_iterator crend() const _NOEXCEPT {return rend();}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001595
Howard Hinnant756c69b2010-09-22 16:48:34 +00001596 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001597 bool empty() const _NOEXCEPT {return __tree_.size() == 0;}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001598 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001599 size_type size() const _NOEXCEPT {return __tree_.size();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001600 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001601 size_type max_size() const _NOEXCEPT {return __tree_.max_size();}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001602
Howard Hinnant756c69b2010-09-22 16:48:34 +00001603 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001604 allocator_type get_allocator() const _NOEXCEPT {return __tree_.__alloc();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001605 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001606 key_compare key_comp() const {return __tree_.value_comp().key_comp();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001607 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001608 value_compare value_comp() const
1609 {return value_compare(__tree_.value_comp().key_comp());}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001610
Howard Hinnant74279a52010-09-04 23:28:19 +00001611#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant74279a52010-09-04 23:28:19 +00001612#ifndef _LIBCPP_HAS_NO_VARIADICS
1613
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001614 template <class ..._Args>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001615 iterator
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001616 emplace(_Args&& ...__args);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001617
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001618 template <class ..._Args>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001619 iterator
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001620 emplace_hint(const_iterator __p, _Args&& ...__args);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001621
Howard Hinnant74279a52010-09-04 23:28:19 +00001622#endif // _LIBCPP_HAS_NO_VARIADICS
1623
Howard Hinnantc834c512011-11-29 18:15:50 +00001624 template <class _Pp,
1625 class = typename enable_if<is_constructible<value_type, _Pp>::value>::type>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001626 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc834c512011-11-29 18:15:50 +00001627 iterator insert(_Pp&& __p)
1628 {return __tree_.__insert_multi(_VSTD::forward<_Pp>(__p));}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001629
Howard Hinnantc834c512011-11-29 18:15:50 +00001630 template <class _Pp,
1631 class = typename enable_if<is_constructible<value_type, _Pp>::value>::type>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001632 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc834c512011-11-29 18:15:50 +00001633 iterator insert(const_iterator __pos, _Pp&& __p)
1634 {return __tree_.__insert_multi(__pos.__i_, _VSTD::forward<_Pp>(__p));}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001635
Howard Hinnant74279a52010-09-04 23:28:19 +00001636#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +00001637
Howard Hinnant756c69b2010-09-22 16:48:34 +00001638 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001639 iterator insert(const value_type& __v) {return __tree_.__insert_multi(__v);}
1640
Howard Hinnant756c69b2010-09-22 16:48:34 +00001641 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001642 iterator insert(const_iterator __p, const value_type& __v)
1643 {return __tree_.__insert_multi(__p.__i_, __v);}
1644
1645 template <class _InputIterator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001646 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001647 void insert(_InputIterator __f, _InputIterator __l)
1648 {
1649 for (const_iterator __e = cend(); __f != __l; ++__f)
1650 __tree_.__insert_multi(__e.__i_, *__f);
1651 }
1652
Howard Hinnant33711792011-08-12 21:56:02 +00001653#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1654
Howard Hinnant756c69b2010-09-22 16:48:34 +00001655 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001656 void insert(initializer_list<value_type> __il)
1657 {insert(__il.begin(), __il.end());}
1658
Howard Hinnant33711792011-08-12 21:56:02 +00001659#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1660
Howard Hinnant756c69b2010-09-22 16:48:34 +00001661 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001662 iterator erase(const_iterator __p) {return __tree_.erase(__p.__i_);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001663 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001664 size_type erase(const key_type& __k) {return __tree_.__erase_multi(__k);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001665 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001666 iterator erase(const_iterator __f, const_iterator __l)
1667 {return __tree_.erase(__f.__i_, __l.__i_);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001668 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001669 void clear() {__tree_.clear();}
1670
Howard Hinnant756c69b2010-09-22 16:48:34 +00001671 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001672 void swap(multimap& __m)
1673 _NOEXCEPT_(__is_nothrow_swappable<__base>::value)
1674 {__tree_.swap(__m.__tree_);}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001675
Howard Hinnant756c69b2010-09-22 16:48:34 +00001676 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001677 iterator find(const key_type& __k) {return __tree_.find(__k);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001678 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001679 const_iterator find(const key_type& __k) const {return __tree_.find(__k);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001680 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001681 size_type count(const key_type& __k) const
1682 {return __tree_.__count_multi(__k);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001683 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001684 iterator lower_bound(const key_type& __k)
1685 {return __tree_.lower_bound(__k);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001686 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001687 const_iterator lower_bound(const key_type& __k) const
1688 {return __tree_.lower_bound(__k);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001689 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001690 iterator upper_bound(const key_type& __k)
1691 {return __tree_.upper_bound(__k);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001692 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001693 const_iterator upper_bound(const key_type& __k) const
1694 {return __tree_.upper_bound(__k);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001695 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001696 pair<iterator,iterator> equal_range(const key_type& __k)
1697 {return __tree_.__equal_range_multi(__k);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001698 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001699 pair<const_iterator,const_iterator> equal_range(const key_type& __k) const
1700 {return __tree_.__equal_range_multi(__k);}
1701
1702private:
1703 typedef typename __base::__node __node;
1704 typedef typename __base::__node_allocator __node_allocator;
1705 typedef typename __base::__node_pointer __node_pointer;
1706 typedef typename __base::__node_const_pointer __node_const_pointer;
Howard Hinnantc834c512011-11-29 18:15:50 +00001707 typedef __map_node_destructor<__node_allocator> _Dp;
1708 typedef unique_ptr<__node, _Dp> __node_holder;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001709
Howard Hinnant74279a52010-09-04 23:28:19 +00001710#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +00001711 __node_holder __construct_node();
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001712 template <class _A0>
Howard Hinnantac7e7482013-07-04 20:59:16 +00001713 __node_holder
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001714 __construct_node(_A0&& __a0);
Howard Hinnant74279a52010-09-04 23:28:19 +00001715#ifndef _LIBCPP_HAS_NO_VARIADICS
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001716 template <class _A0, class _A1, class ..._Args>
1717 __node_holder __construct_node(_A0&& __a0, _A1&& __a1, _Args&& ...__args);
Howard Hinnant74279a52010-09-04 23:28:19 +00001718#endif // _LIBCPP_HAS_NO_VARIADICS
1719#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +00001720};
1721
Howard Hinnant74279a52010-09-04 23:28:19 +00001722#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +00001723
1724template <class _Key, class _Tp, class _Compare, class _Allocator>
1725multimap<_Key, _Tp, _Compare, _Allocator>::multimap(multimap&& __m, const allocator_type& __a)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001726 : __tree_(_VSTD::move(__m.__tree_), __a)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001727{
1728 if (__a != __m.get_allocator())
1729 {
1730 const_iterator __e = cend();
1731 while (!__m.empty())
1732 __tree_.__insert_multi(__e.__i_,
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001733 _VSTD::move(__m.__tree_.remove(__m.begin().__i_)->__value_));
Howard Hinnantc51e1022010-05-11 19:42:16 +00001734 }
1735}
1736
1737template <class _Key, class _Tp, class _Compare, class _Allocator>
1738typename multimap<_Key, _Tp, _Compare, _Allocator>::__node_holder
1739multimap<_Key, _Tp, _Compare, _Allocator>::__construct_node()
1740{
1741 __node_allocator& __na = __tree_.__node_alloc();
Howard Hinnantc834c512011-11-29 18:15:50 +00001742 __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001743 __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__cc.first));
Howard Hinnantc51e1022010-05-11 19:42:16 +00001744 __h.get_deleter().__first_constructed = true;
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001745 __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__cc.second));
Howard Hinnantc51e1022010-05-11 19:42:16 +00001746 __h.get_deleter().__second_constructed = true;
1747 return __h;
1748}
1749
1750template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001751template <class _A0>
Howard Hinnantac7e7482013-07-04 20:59:16 +00001752typename multimap<_Key, _Tp, _Compare, _Allocator>::__node_holder
Howard Hinnantc51e1022010-05-11 19:42:16 +00001753multimap<_Key, _Tp, _Compare, _Allocator>::__construct_node(_A0&& __a0)
1754{
1755 __node_allocator& __na = __tree_.__node_alloc();
Howard Hinnantc834c512011-11-29 18:15:50 +00001756 __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001757 __node_traits::construct(__na, _VSTD::addressof(__h->__value_), _VSTD::forward<_A0>(__a0));
Howard Hinnantc51e1022010-05-11 19:42:16 +00001758 __h.get_deleter().__first_constructed = true;
1759 __h.get_deleter().__second_constructed = true;
1760 return __h;
1761}
1762
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001763#ifndef _LIBCPP_HAS_NO_VARIADICS
1764
1765template <class _Key, class _Tp, class _Compare, class _Allocator>
1766template <class _A0, class _A1, class ..._Args>
1767typename multimap<_Key, _Tp, _Compare, _Allocator>::__node_holder
1768multimap<_Key, _Tp, _Compare, _Allocator>::__construct_node(_A0&& __a0, _A1&& __a1, _Args&& ...__args)
1769{
1770 __node_allocator& __na = __tree_.__node_alloc();
1771 __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
1772 __node_traits::construct(__na, _VSTD::addressof(__h->__value_),
1773 _VSTD::forward<_A0>(__a0), _VSTD::forward<_A1>(__a1),
1774 _VSTD::forward<_Args>(__args)...);
1775 __h.get_deleter().__first_constructed = true;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001776 __h.get_deleter().__second_constructed = true;
1777 return __h;
1778}
1779
Howard Hinnant74279a52010-09-04 23:28:19 +00001780#endif // _LIBCPP_HAS_NO_VARIADICS
1781#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +00001782
Howard Hinnant74279a52010-09-04 23:28:19 +00001783#if !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001784
1785template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001786template <class ..._Args>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001787typename multimap<_Key, _Tp, _Compare, _Allocator>::iterator
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001788multimap<_Key, _Tp, _Compare, _Allocator>::emplace(_Args&& ...__args)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001789{
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001790 __node_holder __h = __construct_node(_VSTD::forward<_Args>(__args)...);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001791 iterator __r = __tree_.__node_insert_multi(__h.get());
1792 __h.release();
1793 return __r;
1794}
1795
1796template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001797template <class ..._Args>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001798typename multimap<_Key, _Tp, _Compare, _Allocator>::iterator
1799multimap<_Key, _Tp, _Compare, _Allocator>::emplace_hint(const_iterator __p,
Howard Hinnantc51e1022010-05-11 19:42:16 +00001800 _Args&& ...__args)
1801{
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001802 __node_holder __h = __construct_node(_VSTD::forward<_Args>(__args)...);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001803 iterator __r = __tree_.__node_insert_multi(__p.__i_, __h.get());
1804 __h.release();
1805 return __r;
1806}
1807
Howard Hinnant74279a52010-09-04 23:28:19 +00001808#endif // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001809
1810template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001811inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001812bool
1813operator==(const multimap<_Key, _Tp, _Compare, _Allocator>& __x,
1814 const multimap<_Key, _Tp, _Compare, _Allocator>& __y)
1815{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001816 return __x.size() == __y.size() && _VSTD::equal(__x.begin(), __x.end(), __y.begin());
Howard Hinnantc51e1022010-05-11 19:42:16 +00001817}
1818
1819template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001820inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001821bool
1822operator< (const multimap<_Key, _Tp, _Compare, _Allocator>& __x,
1823 const multimap<_Key, _Tp, _Compare, _Allocator>& __y)
1824{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001825 return _VSTD::lexicographical_compare(__x.begin(), __x.end(), __y.begin(), __y.end());
Howard Hinnantc51e1022010-05-11 19:42:16 +00001826}
1827
1828template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001829inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001830bool
1831operator!=(const multimap<_Key, _Tp, _Compare, _Allocator>& __x,
1832 const multimap<_Key, _Tp, _Compare, _Allocator>& __y)
1833{
1834 return !(__x == __y);
1835}
1836
1837template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001838inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001839bool
1840operator> (const multimap<_Key, _Tp, _Compare, _Allocator>& __x,
1841 const multimap<_Key, _Tp, _Compare, _Allocator>& __y)
1842{
1843 return __y < __x;
1844}
1845
1846template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001847inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001848bool
1849operator>=(const multimap<_Key, _Tp, _Compare, _Allocator>& __x,
1850 const multimap<_Key, _Tp, _Compare, _Allocator>& __y)
1851{
1852 return !(__x < __y);
1853}
1854
1855template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001856inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001857bool
1858operator<=(const multimap<_Key, _Tp, _Compare, _Allocator>& __x,
1859 const multimap<_Key, _Tp, _Compare, _Allocator>& __y)
1860{
1861 return !(__y < __x);
1862}
1863
1864template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001865inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001866void
1867swap(multimap<_Key, _Tp, _Compare, _Allocator>& __x,
1868 multimap<_Key, _Tp, _Compare, _Allocator>& __y)
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001869 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
Howard Hinnantc51e1022010-05-11 19:42:16 +00001870{
1871 __x.swap(__y);
1872}
1873
1874_LIBCPP_END_NAMESPACE_STD
1875
1876#endif // _LIBCPP_MAP