blob: c8e8fd1f1dfd1f336beb6ddd0c420a6b695adb70 [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);
Marshall Clow300abfb2013-09-11 01:15:47 +000080 template <class InputIterator>
81 map(InputIterator first, InputIterator last, const allocator_type& a)
82 : map(first, last, Compare(), a) {} // C++14
83 map(initializer_list<value_type> il, const allocator_type& a)
84 : map(il, Compare(), a) {} // C++14
85 ~map();
Howard Hinnantc51e1022010-05-11 19:42:16 +000086
87 map& operator=(const map& m);
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +000088 map& operator=(map&& m)
89 noexcept(
90 allocator_type::propagate_on_container_move_assignment::value &&
91 is_nothrow_move_assignable<allocator_type>::value &&
Howard Hinnantf95f4f52011-06-04 15:22:34 +000092 is_nothrow_move_assignable<key_compare>::value);
Howard Hinnantc51e1022010-05-11 19:42:16 +000093 map& operator=(initializer_list<value_type> il);
94
95 // iterators:
Howard Hinnantf95f4f52011-06-04 15:22:34 +000096 iterator begin() noexcept;
97 const_iterator begin() const noexcept;
98 iterator end() noexcept;
99 const_iterator end() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000100
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000101 reverse_iterator rbegin() noexcept;
102 const_reverse_iterator rbegin() const noexcept;
103 reverse_iterator rend() noexcept;
104 const_reverse_iterator rend() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000105
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000106 const_iterator cbegin() const noexcept;
107 const_iterator cend() const noexcept;
108 const_reverse_iterator crbegin() const noexcept;
109 const_reverse_iterator crend() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000110
111 // capacity:
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000112 bool empty() const noexcept;
113 size_type size() const noexcept;
114 size_type max_size() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000115
116 // element access:
117 mapped_type& operator[](const key_type& k);
118 mapped_type& operator[](key_type&& k);
119
120 mapped_type& at(const key_type& k);
121 const mapped_type& at(const key_type& k) const;
122
123 // modifiers:
124 template <class... Args>
125 pair<iterator, bool> emplace(Args&&... args);
126 template <class... Args>
127 iterator emplace_hint(const_iterator position, Args&&... args);
128 pair<iterator, bool> insert(const value_type& v);
129 template <class P>
130 pair<iterator, bool> insert(P&& p);
131 iterator insert(const_iterator position, const value_type& v);
132 template <class P>
133 iterator insert(const_iterator position, P&& p);
134 template <class InputIterator>
135 void insert(InputIterator first, InputIterator last);
136 void insert(initializer_list<value_type> il);
137
138 iterator erase(const_iterator position);
139 size_type erase(const key_type& k);
140 iterator erase(const_iterator first, const_iterator last);
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000141 void clear() noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000142
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000143 void swap(map& m)
144 noexcept(
145 __is_nothrow_swappable<key_compare>::value &&
146 (!allocator_type::propagate_on_container_swap::value ||
147 __is_nothrow_swappable<allocator_type>::value));
Howard Hinnantc51e1022010-05-11 19:42:16 +0000148
149 // observers:
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000150 allocator_type get_allocator() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000151 key_compare key_comp() const;
152 value_compare value_comp() const;
153
154 // map operations:
155 iterator find(const key_type& k);
156 const_iterator find(const key_type& k) const;
Marshall Clowebb57322013-08-13 22:18:47 +0000157 template<typename K>
158 iterator find(const K& x); // C++14
159 template<typename K>
160 const_iterator find(const K& x) const; // C++14
161 template<typename K>
Marshall Clowe6a5f522014-08-24 23:54:16 +0000162 size_type count(const K& x) const; // C++14
Marshall Clowebb57322013-08-13 22:18:47 +0000163
Howard Hinnantc51e1022010-05-11 19:42:16 +0000164 size_type count(const key_type& k) const;
165 iterator lower_bound(const key_type& k);
166 const_iterator lower_bound(const key_type& k) const;
Marshall Clowebb57322013-08-13 22:18:47 +0000167 template<typename K>
168 iterator lower_bound(const K& x); // C++14
169 template<typename K>
170 const_iterator lower_bound(const K& x) const; // C++14
171
Howard Hinnantc51e1022010-05-11 19:42:16 +0000172 iterator upper_bound(const key_type& k);
173 const_iterator upper_bound(const key_type& k) const;
Marshall Clowebb57322013-08-13 22:18:47 +0000174 template<typename K>
175 iterator upper_bound(const K& x); // C++14
176 template<typename K>
177 const_iterator upper_bound(const K& x) const; // C++14
178
Howard Hinnantc51e1022010-05-11 19:42:16 +0000179 pair<iterator,iterator> equal_range(const key_type& k);
180 pair<const_iterator,const_iterator> equal_range(const key_type& k) const;
Marshall Clowebb57322013-08-13 22:18:47 +0000181 template<typename K>
182 pair<iterator,iterator> equal_range(const K& x); // C++14
183 template<typename K>
184 pair<const_iterator,const_iterator> equal_range(const K& x) const; // C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000185};
186
187template <class Key, class T, class Compare, class Allocator>
188bool
189operator==(const map<Key, T, Compare, Allocator>& x,
190 const map<Key, T, Compare, Allocator>& y);
191
192template <class Key, class T, class Compare, class Allocator>
193bool
194operator< (const map<Key, T, Compare, Allocator>& x,
195 const map<Key, T, Compare, Allocator>& y);
196
197template <class Key, class T, class Compare, class Allocator>
198bool
199operator!=(const map<Key, T, Compare, Allocator>& x,
200 const map<Key, T, Compare, Allocator>& y);
201
202template <class Key, class T, class Compare, class Allocator>
203bool
204operator> (const map<Key, T, Compare, Allocator>& x,
205 const map<Key, T, Compare, Allocator>& y);
206
207template <class Key, class T, class Compare, class Allocator>
208bool
209operator>=(const map<Key, T, Compare, Allocator>& x,
210 const map<Key, T, Compare, Allocator>& y);
211
212template <class Key, class T, class Compare, class Allocator>
213bool
214operator<=(const map<Key, T, Compare, Allocator>& x,
215 const map<Key, T, Compare, Allocator>& y);
216
217// specialized algorithms:
218template <class Key, class T, class Compare, class Allocator>
219void
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000220swap(map<Key, T, Compare, Allocator>& x, map<Key, T, Compare, Allocator>& y)
221 noexcept(noexcept(x.swap(y)));
Howard Hinnantc51e1022010-05-11 19:42:16 +0000222
223template <class Key, class T, class Compare = less<Key>,
224 class Allocator = allocator<pair<const Key, T>>>
225class multimap
226{
227public:
228 // types:
229 typedef Key key_type;
230 typedef T mapped_type;
231 typedef pair<const key_type,mapped_type> value_type;
232 typedef Compare key_compare;
233 typedef Allocator allocator_type;
234 typedef typename allocator_type::reference reference;
235 typedef typename allocator_type::const_reference const_reference;
236 typedef typename allocator_type::size_type size_type;
237 typedef typename allocator_type::difference_type difference_type;
238 typedef typename allocator_type::pointer pointer;
239 typedef typename allocator_type::const_pointer const_pointer;
240
241 typedef implementation-defined iterator;
242 typedef implementation-defined const_iterator;
243 typedef std::reverse_iterator<iterator> reverse_iterator;
244 typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
245
246 class value_compare
247 : public binary_function<value_type,value_type,bool>
248 {
249 friend class multimap;
250 protected:
251 key_compare comp;
252 value_compare(key_compare c);
253 public:
254 bool operator()(const value_type& x, const value_type& y) const;
255 };
256
257 // construct/copy/destroy:
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000258 multimap()
259 noexcept(
260 is_nothrow_default_constructible<allocator_type>::value &&
261 is_nothrow_default_constructible<key_compare>::value &&
262 is_nothrow_copy_constructible<key_compare>::value);
263 explicit multimap(const key_compare& comp);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000264 multimap(const key_compare& comp, const allocator_type& a);
265 template <class InputIterator>
266 multimap(InputIterator first, InputIterator last, const key_compare& comp);
267 template <class InputIterator>
268 multimap(InputIterator first, InputIterator last, const key_compare& comp,
269 const allocator_type& a);
270 multimap(const multimap& m);
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000271 multimap(multimap&& m)
272 noexcept(
273 is_nothrow_move_constructible<allocator_type>::value &&
274 is_nothrow_move_constructible<key_compare>::value);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000275 explicit multimap(const allocator_type& a);
276 multimap(const multimap& m, const allocator_type& a);
277 multimap(multimap&& m, const allocator_type& a);
278 multimap(initializer_list<value_type> il, const key_compare& comp = key_compare());
279 multimap(initializer_list<value_type> il, const key_compare& comp,
280 const allocator_type& a);
Marshall Clow300abfb2013-09-11 01:15:47 +0000281 template <class InputIterator>
282 multimap(InputIterator first, InputIterator last, const allocator_type& a)
283 : multimap(first, last, Compare(), a) {} // C++14
284 multimap(initializer_list<value_type> il, const allocator_type& a)
285 : multimap(il, Compare(), a) {} // C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000286 ~multimap();
287
288 multimap& operator=(const multimap& m);
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000289 multimap& operator=(multimap&& m)
290 noexcept(
291 allocator_type::propagate_on_container_move_assignment::value &&
292 is_nothrow_move_assignable<allocator_type>::value &&
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000293 is_nothrow_move_assignable<key_compare>::value);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000294 multimap& operator=(initializer_list<value_type> il);
295
296 // iterators:
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000297 iterator begin() noexcept;
298 const_iterator begin() const noexcept;
299 iterator end() noexcept;
300 const_iterator end() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000301
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000302 reverse_iterator rbegin() noexcept;
303 const_reverse_iterator rbegin() const noexcept;
304 reverse_iterator rend() noexcept;
305 const_reverse_iterator rend() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000306
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000307 const_iterator cbegin() const noexcept;
308 const_iterator cend() const noexcept;
309 const_reverse_iterator crbegin() const noexcept;
310 const_reverse_iterator crend() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000311
312 // capacity:
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000313 bool empty() const noexcept;
314 size_type size() const noexcept;
315 size_type max_size() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000316
317 // modifiers:
318 template <class... Args>
319 iterator emplace(Args&&... args);
320 template <class... Args>
321 iterator emplace_hint(const_iterator position, Args&&... args);
322 iterator insert(const value_type& v);
323 template <class P>
324 iterator insert(P&& p);
325 iterator insert(const_iterator position, const value_type& v);
326 template <class P>
327 iterator insert(const_iterator position, P&& p);
328 template <class InputIterator>
329 void insert(InputIterator first, InputIterator last);
330 void insert(initializer_list<value_type> il);
331
332 iterator erase(const_iterator position);
333 size_type erase(const key_type& k);
334 iterator erase(const_iterator first, const_iterator last);
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000335 void clear() noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000336
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000337 void swap(multimap& m)
338 noexcept(
339 __is_nothrow_swappable<key_compare>::value &&
340 (!allocator_type::propagate_on_container_swap::value ||
341 __is_nothrow_swappable<allocator_type>::value));
Howard Hinnantc51e1022010-05-11 19:42:16 +0000342
343 // observers:
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000344 allocator_type get_allocator() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000345 key_compare key_comp() const;
346 value_compare value_comp() const;
347
348 // map operations:
349 iterator find(const key_type& k);
350 const_iterator find(const key_type& k) const;
Marshall Clowebb57322013-08-13 22:18:47 +0000351 template<typename K>
352 iterator find(const K& x); // C++14
353 template<typename K>
354 const_iterator find(const K& x) const; // C++14
355 template<typename K>
Marshall Clowe6a5f522014-08-24 23:54:16 +0000356 size_type count(const K& x) const; // C++14
Marshall Clowebb57322013-08-13 22:18:47 +0000357
Howard Hinnantc51e1022010-05-11 19:42:16 +0000358 size_type count(const key_type& k) const;
359 iterator lower_bound(const key_type& k);
360 const_iterator lower_bound(const key_type& k) const;
Marshall Clowebb57322013-08-13 22:18:47 +0000361 template<typename K>
362 iterator lower_bound(const K& x); // C++14
363 template<typename K>
364 const_iterator lower_bound(const K& x) const; // C++14
365
Howard Hinnantc51e1022010-05-11 19:42:16 +0000366 iterator upper_bound(const key_type& k);
367 const_iterator upper_bound(const key_type& k) const;
Marshall Clowebb57322013-08-13 22:18:47 +0000368 template<typename K>
369 iterator upper_bound(const K& x); // C++14
370 template<typename K>
371 const_iterator upper_bound(const K& x) const; // C++14
372
Howard Hinnantc51e1022010-05-11 19:42:16 +0000373 pair<iterator,iterator> equal_range(const key_type& k);
374 pair<const_iterator,const_iterator> equal_range(const key_type& k) const;
Marshall Clowebb57322013-08-13 22:18:47 +0000375 template<typename K>
376 pair<iterator,iterator> equal_range(const K& x); // C++14
377 template<typename K>
378 pair<const_iterator,const_iterator> equal_range(const K& x) const; // C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000379};
380
381template <class Key, class T, class Compare, class Allocator>
382bool
383operator==(const multimap<Key, T, Compare, Allocator>& x,
384 const multimap<Key, T, Compare, Allocator>& y);
385
386template <class Key, class T, class Compare, class Allocator>
387bool
388operator< (const multimap<Key, T, Compare, Allocator>& x,
389 const multimap<Key, T, Compare, Allocator>& y);
390
391template <class Key, class T, class Compare, class Allocator>
392bool
393operator!=(const multimap<Key, T, Compare, Allocator>& x,
394 const multimap<Key, T, Compare, Allocator>& y);
395
396template <class Key, class T, class Compare, class Allocator>
397bool
398operator> (const multimap<Key, T, Compare, Allocator>& x,
399 const multimap<Key, T, Compare, Allocator>& y);
400
401template <class Key, class T, class Compare, class Allocator>
402bool
403operator>=(const multimap<Key, T, Compare, Allocator>& x,
404 const multimap<Key, T, Compare, Allocator>& y);
405
406template <class Key, class T, class Compare, class Allocator>
407bool
408operator<=(const multimap<Key, T, Compare, Allocator>& x,
409 const multimap<Key, T, Compare, Allocator>& y);
410
411// specialized algorithms:
412template <class Key, class T, class Compare, class Allocator>
413void
414swap(multimap<Key, T, Compare, Allocator>& x,
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000415 multimap<Key, T, Compare, Allocator>& y)
416 noexcept(noexcept(x.swap(y)));
Howard Hinnantc51e1022010-05-11 19:42:16 +0000417
418} // std
419
420*/
421
422#include <__config>
423#include <__tree>
424#include <iterator>
425#include <memory>
426#include <utility>
427#include <functional>
428#include <initializer_list>
429
Howard Hinnantaaaa52b2011-10-17 20:05:10 +0000430#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000431#pragma GCC system_header
Howard Hinnantaaaa52b2011-10-17 20:05:10 +0000432#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000433
434_LIBCPP_BEGIN_NAMESPACE_STD
435
Howard Hinnant90b91592013-07-05 18:06:00 +0000436template <class _Key, class _CP, class _Compare, bool = is_empty<_Compare>::value
Howard Hinnantd0aabf82011-12-11 20:31:33 +0000437#if __has_feature(is_final)
438 && !__is_final(_Compare)
439#endif
440 >
Howard Hinnantc51e1022010-05-11 19:42:16 +0000441class __map_value_compare
442 : private _Compare
443{
Howard Hinnantc51e1022010-05-11 19:42:16 +0000444public:
Howard Hinnant756c69b2010-09-22 16:48:34 +0000445 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000446 __map_value_compare()
447 _NOEXCEPT_(is_nothrow_default_constructible<_Compare>::value)
448 : _Compare() {}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000449 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000450 __map_value_compare(_Compare c)
451 _NOEXCEPT_(is_nothrow_copy_constructible<_Compare>::value)
452 : _Compare(c) {}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000453 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000454 const _Compare& key_comp() const _NOEXCEPT {return *this;}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000455 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000456 bool operator()(const _CP& __x, const _CP& __y) const
Howard Hinnant90b91592013-07-05 18:06:00 +0000457 {return static_cast<const _Compare&>(*this)(__x.__cc.first, __y.__cc.first);}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000458 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000459 bool operator()(const _CP& __x, const _Key& __y) const
Howard Hinnant90b91592013-07-05 18:06:00 +0000460 {return static_cast<const _Compare&>(*this)(__x.__cc.first, __y);}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000461 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000462 bool operator()(const _Key& __x, const _CP& __y) const
Howard Hinnant90b91592013-07-05 18:06:00 +0000463 {return static_cast<const _Compare&>(*this)(__x, __y.__cc.first);}
Marshall Clowebb57322013-08-13 22:18:47 +0000464
465#if _LIBCPP_STD_VER > 11
466 template <typename _K2>
467 _LIBCPP_INLINE_VISIBILITY
468 typename enable_if<__is_transparent<_Compare, _K2>::value, bool>::type
469 operator () ( const _K2& __x, const _CP& __y ) const
470 {return static_cast<const _Compare&>(*this) (__x, __y.__cc.first);}
471
472 template <typename _K2>
473 _LIBCPP_INLINE_VISIBILITY
474 typename enable_if<__is_transparent<_Compare, _K2>::value, bool>::type
475 operator () (const _CP& __x, const _K2& __y) const
476 {return static_cast<const _Compare&>(*this) (__x.__cc.first, __y);}
477#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000478};
479
Howard Hinnant90b91592013-07-05 18:06:00 +0000480template <class _Key, class _CP, class _Compare>
481class __map_value_compare<_Key, _CP, _Compare, false>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000482{
483 _Compare comp;
484
Howard Hinnantc51e1022010-05-11 19:42:16 +0000485public:
Howard Hinnant756c69b2010-09-22 16:48:34 +0000486 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000487 __map_value_compare()
488 _NOEXCEPT_(is_nothrow_default_constructible<_Compare>::value)
489 : comp() {}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000490 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000491 __map_value_compare(_Compare c)
492 _NOEXCEPT_(is_nothrow_copy_constructible<_Compare>::value)
493 : comp(c) {}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000494 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000495 const _Compare& key_comp() const _NOEXCEPT {return comp;}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000496
Howard Hinnant756c69b2010-09-22 16:48:34 +0000497 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000498 bool operator()(const _CP& __x, const _CP& __y) const
Howard Hinnant90b91592013-07-05 18:06:00 +0000499 {return comp(__x.__cc.first, __y.__cc.first);}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000500 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000501 bool operator()(const _CP& __x, const _Key& __y) const
Howard Hinnant90b91592013-07-05 18:06:00 +0000502 {return comp(__x.__cc.first, __y);}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000503 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000504 bool operator()(const _Key& __x, const _CP& __y) const
Howard Hinnant90b91592013-07-05 18:06:00 +0000505 {return comp(__x, __y.__cc.first);}
Marshall Clowebb57322013-08-13 22:18:47 +0000506
507#if _LIBCPP_STD_VER > 11
508 template <typename _K2>
509 _LIBCPP_INLINE_VISIBILITY
510 typename enable_if<__is_transparent<_Compare, _K2>::value, bool>::type
511 operator () ( const _K2& __x, const _CP& __y ) const
512 {return comp (__x, __y.__cc.first);}
513
514 template <typename _K2>
515 _LIBCPP_INLINE_VISIBILITY
516 typename enable_if<__is_transparent<_Compare, _K2>::value, bool>::type
517 operator () (const _CP& __x, const _K2& __y) const
518 {return comp (__x.__cc.first, __y);}
519#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000520};
521
522template <class _Allocator>
523class __map_node_destructor
524{
525 typedef _Allocator allocator_type;
526 typedef allocator_traits<allocator_type> __alloc_traits;
527 typedef typename __alloc_traits::value_type::value_type value_type;
528public:
529 typedef typename __alloc_traits::pointer pointer;
530private:
Howard Hinnant2d0046b2013-06-19 21:29:40 +0000531 typedef typename value_type::value_type::first_type first_type;
532 typedef typename value_type::value_type::second_type second_type;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000533
534 allocator_type& __na_;
535
536 __map_node_destructor& operator=(const __map_node_destructor&);
537
538public:
539 bool __first_constructed;
540 bool __second_constructed;
541
Howard Hinnant756c69b2010-09-22 16:48:34 +0000542 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000543 explicit __map_node_destructor(allocator_type& __na) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +0000544 : __na_(__na),
545 __first_constructed(false),
546 __second_constructed(false)
547 {}
548
Howard Hinnant74279a52010-09-04 23:28:19 +0000549#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant756c69b2010-09-22 16:48:34 +0000550 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000551 __map_node_destructor(__tree_node_destructor<allocator_type>&& __x) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +0000552 : __na_(__x.__na_),
553 __first_constructed(__x.__value_constructed),
554 __second_constructed(__x.__value_constructed)
555 {
556 __x.__value_constructed = false;
557 }
Howard Hinnant5dc89112010-09-04 23:46:48 +0000558#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +0000559
Howard Hinnant756c69b2010-09-22 16:48:34 +0000560 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000561 void operator()(pointer __p) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +0000562 {
563 if (__second_constructed)
Howard Hinnant2d0046b2013-06-19 21:29:40 +0000564 __alloc_traits::destroy(__na_, _VSTD::addressof(__p->__value_.__cc.second));
Howard Hinnantc51e1022010-05-11 19:42:16 +0000565 if (__first_constructed)
Howard Hinnant2d0046b2013-06-19 21:29:40 +0000566 __alloc_traits::destroy(__na_, _VSTD::addressof(__p->__value_.__cc.first));
Howard Hinnantc51e1022010-05-11 19:42:16 +0000567 if (__p)
568 __alloc_traits::deallocate(__na_, __p, 1);
569 }
570};
571
Howard Hinnant944510a2011-06-14 19:58:17 +0000572template <class _Key, class _Tp, class _Compare, class _Allocator>
573 class map;
574template <class _Key, class _Tp, class _Compare, class _Allocator>
575 class multimap;
576template <class _TreeIterator> class __map_const_iterator;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000577
Howard Hinnant89f8b792013-09-30 19:08:22 +0000578#if __cplusplus >= 201103L
579
580template <class _Key, class _Tp>
581union __value_type
582{
583 typedef _Key key_type;
584 typedef _Tp mapped_type;
585 typedef pair<const key_type, mapped_type> value_type;
586 typedef pair<key_type, mapped_type> __nc_value_type;
587
588 value_type __cc;
589 __nc_value_type __nc;
590
591 template <class ..._Args>
592 _LIBCPP_INLINE_VISIBILITY
593 __value_type(_Args&& ...__args)
594 : __cc(std::forward<_Args>(__args)...) {}
595
596 _LIBCPP_INLINE_VISIBILITY
597 __value_type(const __value_type& __v)
598 : __cc(__v.__cc) {}
599
600 _LIBCPP_INLINE_VISIBILITY
601 __value_type(__value_type& __v)
602 : __cc(__v.__cc) {}
603
604 _LIBCPP_INLINE_VISIBILITY
605 __value_type(__value_type&& __v)
606 : __nc(std::move(__v.__nc)) {}
607
608 _LIBCPP_INLINE_VISIBILITY
609 __value_type& operator=(const __value_type& __v)
610 {__nc = __v.__cc; return *this;}
611
612 _LIBCPP_INLINE_VISIBILITY
613 __value_type& operator=(__value_type&& __v)
614 {__nc = std::move(__v.__nc); return *this;}
615
616 _LIBCPP_INLINE_VISIBILITY
617 ~__value_type() {__cc.~value_type();}
618};
619
620#else
621
622template <class _Key, class _Tp>
623struct __value_type
624{
625 typedef _Key key_type;
626 typedef _Tp mapped_type;
627 typedef pair<const key_type, mapped_type> value_type;
628
629 value_type __cc;
630
631 _LIBCPP_INLINE_VISIBILITY
632 __value_type() {}
633
634 template <class _A0>
635 _LIBCPP_INLINE_VISIBILITY
636 __value_type(const _A0& __a0)
637 : __cc(__a0) {}
638
639 template <class _A0, class _A1>
640 _LIBCPP_INLINE_VISIBILITY
641 __value_type(const _A0& __a0, const _A1& __a1)
642 : __cc(__a0, __a1) {}
643};
644
645#endif
646
Eric Fiselier44f9fd02015-03-03 20:10:01 +0000647template <class _Tp>
648struct __extract_key_value_types;
649
650template <class _Key, class _Tp>
651struct __extract_key_value_types<__value_type<_Key, _Tp> >
652{
653 typedef _Key const __key_type;
654 typedef _Tp __mapped_type;
655};
656
Howard Hinnantc51e1022010-05-11 19:42:16 +0000657template <class _TreeIterator>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +0000658class _LIBCPP_TYPE_VIS_ONLY __map_iterator
Howard Hinnantc51e1022010-05-11 19:42:16 +0000659{
660 _TreeIterator __i_;
661
662 typedef typename _TreeIterator::__pointer_traits __pointer_traits;
Eric Fiselier44f9fd02015-03-03 20:10:01 +0000663 typedef typename _TreeIterator::value_type __value_type;
664 typedef typename __extract_key_value_types<__value_type>::__key_type __key_type;
665 typedef typename __extract_key_value_types<__value_type>::__mapped_type __mapped_type;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000666public:
667 typedef bidirectional_iterator_tag iterator_category;
Howard Hinnantb2e8a422011-02-27 18:02:02 +0000668 typedef pair<__key_type, __mapped_type> value_type;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000669 typedef typename _TreeIterator::difference_type difference_type;
670 typedef value_type& reference;
671 typedef typename __pointer_traits::template
672#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
673 rebind<value_type>
674#else
675 rebind<value_type>::other
676#endif
677 pointer;
678
Howard Hinnant756c69b2010-09-22 16:48:34 +0000679 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000680 __map_iterator() _NOEXCEPT {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000681
Howard Hinnant756c69b2010-09-22 16:48:34 +0000682 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000683 __map_iterator(_TreeIterator __i) _NOEXCEPT : __i_(__i) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000684
Howard Hinnant756c69b2010-09-22 16:48:34 +0000685 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2d0046b2013-06-19 21:29:40 +0000686 reference operator*() const {return __i_->__cc;}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000687 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2d0046b2013-06-19 21:29:40 +0000688 pointer operator->() const {return pointer_traits<pointer>::pointer_to(__i_->__cc);}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000689
Howard Hinnant756c69b2010-09-22 16:48:34 +0000690 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000691 __map_iterator& operator++() {++__i_; return *this;}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000692 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000693 __map_iterator operator++(int)
694 {
695 __map_iterator __t(*this);
696 ++(*this);
697 return __t;
698 }
699
Howard Hinnant756c69b2010-09-22 16:48:34 +0000700 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000701 __map_iterator& operator--() {--__i_; return *this;}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000702 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000703 __map_iterator operator--(int)
704 {
705 __map_iterator __t(*this);
706 --(*this);
707 return __t;
708 }
709
Howard Hinnant756c69b2010-09-22 16:48:34 +0000710 friend _LIBCPP_INLINE_VISIBILITY
711 bool operator==(const __map_iterator& __x, const __map_iterator& __y)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000712 {return __x.__i_ == __y.__i_;}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000713 friend
714 _LIBCPP_INLINE_VISIBILITY
715 bool operator!=(const __map_iterator& __x, const __map_iterator& __y)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000716 {return __x.__i_ != __y.__i_;}
717
Howard Hinnanta37d3cf2013-08-12 18:38:34 +0000718 template <class, class, class, class> friend class _LIBCPP_TYPE_VIS_ONLY map;
719 template <class, class, class, class> friend class _LIBCPP_TYPE_VIS_ONLY multimap;
720 template <class> friend class _LIBCPP_TYPE_VIS_ONLY __map_const_iterator;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000721};
722
723template <class _TreeIterator>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +0000724class _LIBCPP_TYPE_VIS_ONLY __map_const_iterator
Howard Hinnantc51e1022010-05-11 19:42:16 +0000725{
726 _TreeIterator __i_;
727
728 typedef typename _TreeIterator::__pointer_traits __pointer_traits;
Eric Fiselier44f9fd02015-03-03 20:10:01 +0000729 typedef typename _TreeIterator::value_type __value_type;
730 typedef typename __extract_key_value_types<__value_type>::__key_type __key_type;
731 typedef typename __extract_key_value_types<__value_type>::__mapped_type __mapped_type;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000732public:
733 typedef bidirectional_iterator_tag iterator_category;
Howard Hinnantb2e8a422011-02-27 18:02:02 +0000734 typedef pair<__key_type, __mapped_type> value_type;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000735 typedef typename _TreeIterator::difference_type difference_type;
736 typedef const value_type& reference;
737 typedef typename __pointer_traits::template
738#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
Howard Hinnant73f3c8a2011-04-11 02:18:41 +0000739 rebind<const value_type>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000740#else
Howard Hinnant73f3c8a2011-04-11 02:18:41 +0000741 rebind<const value_type>::other
Howard Hinnantc51e1022010-05-11 19:42:16 +0000742#endif
743 pointer;
744
Howard Hinnant756c69b2010-09-22 16:48:34 +0000745 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000746 __map_const_iterator() _NOEXCEPT {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000747
Howard Hinnant756c69b2010-09-22 16:48:34 +0000748 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000749 __map_const_iterator(_TreeIterator __i) _NOEXCEPT : __i_(__i) {}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000750 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier44f9fd02015-03-03 20:10:01 +0000751 __map_const_iterator(__map_iterator<
752 typename _TreeIterator::__non_const_iterator> __i) _NOEXCEPT
753 : __i_(__i.__i_) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000754
Howard Hinnant756c69b2010-09-22 16:48:34 +0000755 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2d0046b2013-06-19 21:29:40 +0000756 reference operator*() const {return __i_->__cc;}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000757 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2d0046b2013-06-19 21:29:40 +0000758 pointer operator->() const {return pointer_traits<pointer>::pointer_to(__i_->__cc);}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000759
Howard Hinnant756c69b2010-09-22 16:48:34 +0000760 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000761 __map_const_iterator& operator++() {++__i_; return *this;}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000762 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000763 __map_const_iterator operator++(int)
764 {
765 __map_const_iterator __t(*this);
766 ++(*this);
767 return __t;
768 }
769
Howard Hinnant756c69b2010-09-22 16:48:34 +0000770 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000771 __map_const_iterator& operator--() {--__i_; return *this;}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000772 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000773 __map_const_iterator operator--(int)
774 {
775 __map_const_iterator __t(*this);
776 --(*this);
777 return __t;
778 }
779
Howard Hinnant756c69b2010-09-22 16:48:34 +0000780 friend _LIBCPP_INLINE_VISIBILITY
781 bool operator==(const __map_const_iterator& __x, const __map_const_iterator& __y)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000782 {return __x.__i_ == __y.__i_;}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000783 friend _LIBCPP_INLINE_VISIBILITY
784 bool operator!=(const __map_const_iterator& __x, const __map_const_iterator& __y)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000785 {return __x.__i_ != __y.__i_;}
786
Howard Hinnanta37d3cf2013-08-12 18:38:34 +0000787 template <class, class, class, class> friend class _LIBCPP_TYPE_VIS_ONLY map;
788 template <class, class, class, class> friend class _LIBCPP_TYPE_VIS_ONLY multimap;
789 template <class, class, class> friend class _LIBCPP_TYPE_VIS_ONLY __tree_const_iterator;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000790};
791
792template <class _Key, class _Tp, class _Compare = less<_Key>,
793 class _Allocator = allocator<pair<const _Key, _Tp> > >
Howard Hinnanta37d3cf2013-08-12 18:38:34 +0000794class _LIBCPP_TYPE_VIS_ONLY map
Howard Hinnantc51e1022010-05-11 19:42:16 +0000795{
796public:
797 // types:
798 typedef _Key key_type;
799 typedef _Tp mapped_type;
800 typedef pair<const key_type, mapped_type> value_type;
Howard Hinnant2d0046b2013-06-19 21:29:40 +0000801 typedef pair<key_type, mapped_type> __nc_value_type;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000802 typedef _Compare key_compare;
803 typedef _Allocator allocator_type;
804 typedef value_type& reference;
805 typedef const value_type& const_reference;
806
Howard Hinnanta37d3cf2013-08-12 18:38:34 +0000807 class _LIBCPP_TYPE_VIS_ONLY value_compare
Howard Hinnantc51e1022010-05-11 19:42:16 +0000808 : public binary_function<value_type, value_type, bool>
809 {
810 friend class map;
811 protected:
812 key_compare comp;
813
Howard Hinnant756c69b2010-09-22 16:48:34 +0000814 _LIBCPP_INLINE_VISIBILITY value_compare(key_compare c) : comp(c) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000815 public:
Howard Hinnant756c69b2010-09-22 16:48:34 +0000816 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000817 bool operator()(const value_type& __x, const value_type& __y) const
818 {return comp(__x.first, __y.first);}
819 };
820
821private:
Howard Hinnant2d0046b2013-06-19 21:29:40 +0000822
Howard Hinnant89f8b792013-09-30 19:08:22 +0000823 typedef _VSTD::__value_type<key_type, mapped_type> __value_type;
Howard Hinnant90b91592013-07-05 18:06:00 +0000824 typedef __map_value_compare<key_type, __value_type, key_compare> __vc;
Marshall Clow940e01c2015-04-07 05:21:38 +0000825 typedef typename __rebind_alloc_helper<allocator_traits<allocator_type>,
826 __value_type>::type __allocator_type;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000827 typedef __tree<__value_type, __vc, __allocator_type> __base;
828 typedef typename __base::__node_traits __node_traits;
829 typedef allocator_traits<allocator_type> __alloc_traits;
830
831 __base __tree_;
832
833public:
834 typedef typename __alloc_traits::pointer pointer;
835 typedef typename __alloc_traits::const_pointer const_pointer;
836 typedef typename __alloc_traits::size_type size_type;
837 typedef typename __alloc_traits::difference_type difference_type;
Eric Fiselier44f9fd02015-03-03 20:10:01 +0000838 typedef __map_iterator<typename __base::iterator> iterator;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000839 typedef __map_const_iterator<typename __base::const_iterator> const_iterator;
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000840 typedef _VSTD::reverse_iterator<iterator> reverse_iterator;
841 typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000842
Howard Hinnant756c69b2010-09-22 16:48:34 +0000843 _LIBCPP_INLINE_VISIBILITY
Marshall Clow7086a5a2014-03-10 04:50:10 +0000844 map()
845 _NOEXCEPT_(
846 is_nothrow_default_constructible<allocator_type>::value &&
847 is_nothrow_default_constructible<key_compare>::value &&
848 is_nothrow_copy_constructible<key_compare>::value)
849 : __tree_(__vc(key_compare())) {}
850
851 _LIBCPP_INLINE_VISIBILITY
852 explicit map(const key_compare& __comp)
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000853 _NOEXCEPT_(
854 is_nothrow_default_constructible<allocator_type>::value &&
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000855 is_nothrow_copy_constructible<key_compare>::value)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000856 : __tree_(__vc(__comp)) {}
857
Howard Hinnant756c69b2010-09-22 16:48:34 +0000858 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000859 explicit map(const key_compare& __comp, const allocator_type& __a)
860 : __tree_(__vc(__comp), __a) {}
861
862 template <class _InputIterator>
Howard Hinnant756c69b2010-09-22 16:48:34 +0000863 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000864 map(_InputIterator __f, _InputIterator __l,
865 const key_compare& __comp = key_compare())
866 : __tree_(__vc(__comp))
867 {
868 insert(__f, __l);
869 }
870
871 template <class _InputIterator>
Howard Hinnant756c69b2010-09-22 16:48:34 +0000872 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000873 map(_InputIterator __f, _InputIterator __l,
874 const key_compare& __comp, const allocator_type& __a)
875 : __tree_(__vc(__comp), __a)
876 {
877 insert(__f, __l);
878 }
879
Marshall Clow300abfb2013-09-11 01:15:47 +0000880#if _LIBCPP_STD_VER > 11
881 template <class _InputIterator>
882 _LIBCPP_INLINE_VISIBILITY
883 map(_InputIterator __f, _InputIterator __l, const allocator_type& __a)
884 : map(__f, __l, key_compare(), __a) {}
885#endif
886
Howard Hinnant756c69b2010-09-22 16:48:34 +0000887 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000888 map(const map& __m)
889 : __tree_(__m.__tree_)
890 {
891 insert(__m.begin(), __m.end());
892 }
893
Howard Hinnantd3a657f2011-07-01 19:24:36 +0000894 _LIBCPP_INLINE_VISIBILITY
895 map& operator=(const map& __m)
896 {
Howard Hinnant2d0046b2013-06-19 21:29:40 +0000897#if __cplusplus >= 201103L
Howard Hinnantd3a657f2011-07-01 19:24:36 +0000898 __tree_ = __m.__tree_;
Howard Hinnant2d0046b2013-06-19 21:29:40 +0000899#else
Marshall Clowdb3cfcb2014-02-08 04:03:14 +0000900 if (this != &__m) {
901 __tree_.clear();
902 __tree_.value_comp() = __m.__tree_.value_comp();
903 __tree_.__copy_assign_alloc(__m.__tree_);
904 insert(__m.begin(), __m.end());
905 }
Howard Hinnant2d0046b2013-06-19 21:29:40 +0000906#endif
Howard Hinnantd3a657f2011-07-01 19:24:36 +0000907 return *this;
908 }
909
Howard Hinnant74279a52010-09-04 23:28:19 +0000910#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +0000911
Howard Hinnant756c69b2010-09-22 16:48:34 +0000912 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000913 map(map&& __m)
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000914 _NOEXCEPT_(is_nothrow_move_constructible<__base>::value)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000915 : __tree_(_VSTD::move(__m.__tree_))
Howard Hinnantc51e1022010-05-11 19:42:16 +0000916 {
917 }
918
919 map(map&& __m, const allocator_type& __a);
920
Howard Hinnant756c69b2010-09-22 16:48:34 +0000921 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant33711792011-08-12 21:56:02 +0000922 map& operator=(map&& __m)
923 _NOEXCEPT_(is_nothrow_move_assignable<__base>::value)
924 {
925 __tree_ = _VSTD::move(__m.__tree_);
926 return *this;
927 }
928
929#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
930
931#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
932
933 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000934 map(initializer_list<value_type> __il, const key_compare& __comp = key_compare())
935 : __tree_(__vc(__comp))
936 {
937 insert(__il.begin(), __il.end());
938 }
939
Howard Hinnant756c69b2010-09-22 16:48:34 +0000940 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000941 map(initializer_list<value_type> __il, const key_compare& __comp, const allocator_type& __a)
942 : __tree_(__vc(__comp), __a)
943 {
944 insert(__il.begin(), __il.end());
945 }
946
Marshall Clow300abfb2013-09-11 01:15:47 +0000947#if _LIBCPP_STD_VER > 11
948 _LIBCPP_INLINE_VISIBILITY
949 map(initializer_list<value_type> __il, const allocator_type& __a)
950 : map(__il, key_compare(), __a) {}
951#endif
952
Howard Hinnant756c69b2010-09-22 16:48:34 +0000953 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000954 map& operator=(initializer_list<value_type> __il)
955 {
956 __tree_.__assign_unique(__il.begin(), __il.end());
957 return *this;
958 }
959
Howard Hinnant33711792011-08-12 21:56:02 +0000960#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000961
Howard Hinnant756c69b2010-09-22 16:48:34 +0000962 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000963 explicit map(const allocator_type& __a)
964 : __tree_(__a)
965 {
966 }
967
Howard Hinnant756c69b2010-09-22 16:48:34 +0000968 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000969 map(const map& __m, const allocator_type& __a)
970 : __tree_(__m.__tree_.value_comp(), __a)
971 {
972 insert(__m.begin(), __m.end());
973 }
974
Howard Hinnant756c69b2010-09-22 16:48:34 +0000975 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000976 iterator begin() _NOEXCEPT {return __tree_.begin();}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000977 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000978 const_iterator begin() const _NOEXCEPT {return __tree_.begin();}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000979 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000980 iterator end() _NOEXCEPT {return __tree_.end();}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000981 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000982 const_iterator end() const _NOEXCEPT {return __tree_.end();}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000983
Howard Hinnant756c69b2010-09-22 16:48:34 +0000984 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000985 reverse_iterator rbegin() _NOEXCEPT {return reverse_iterator(end());}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000986 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000987 const_reverse_iterator rbegin() const _NOEXCEPT
988 {return const_reverse_iterator(end());}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000989 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000990 reverse_iterator rend() _NOEXCEPT
991 {return reverse_iterator(begin());}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000992 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000993 const_reverse_iterator rend() const _NOEXCEPT
994 {return const_reverse_iterator(begin());}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000995
Howard Hinnant756c69b2010-09-22 16:48:34 +0000996 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000997 const_iterator cbegin() const _NOEXCEPT {return begin();}
Howard Hinnant756c69b2010-09-22 16:48:34 +0000998 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +0000999 const_iterator cend() const _NOEXCEPT {return end();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001000 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001001 const_reverse_iterator crbegin() const _NOEXCEPT {return rbegin();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001002 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001003 const_reverse_iterator crend() const _NOEXCEPT {return rend();}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001004
Howard Hinnant756c69b2010-09-22 16:48:34 +00001005 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001006 bool empty() const _NOEXCEPT {return __tree_.size() == 0;}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001007 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001008 size_type size() const _NOEXCEPT {return __tree_.size();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001009 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001010 size_type max_size() const _NOEXCEPT {return __tree_.max_size();}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001011
1012 mapped_type& operator[](const key_type& __k);
Howard Hinnant74279a52010-09-04 23:28:19 +00001013#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +00001014 mapped_type& operator[](key_type&& __k);
1015#endif
1016
1017 mapped_type& at(const key_type& __k);
1018 const mapped_type& at(const key_type& __k) const;
1019
Howard Hinnant756c69b2010-09-22 16:48:34 +00001020 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001021 allocator_type get_allocator() const _NOEXCEPT {return __tree_.__alloc();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001022 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001023 key_compare key_comp() const {return __tree_.value_comp().key_comp();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001024 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001025 value_compare value_comp() const {return value_compare(__tree_.value_comp().key_comp());}
1026
Howard Hinnant74279a52010-09-04 23:28:19 +00001027#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant74279a52010-09-04 23:28:19 +00001028#ifndef _LIBCPP_HAS_NO_VARIADICS
1029
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001030 template <class ..._Args>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001031 pair<iterator, bool>
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001032 emplace(_Args&& ...__args);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001033
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001034 template <class ..._Args>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001035 iterator
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001036 emplace_hint(const_iterator __p, _Args&& ...__args);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001037
Howard Hinnant74279a52010-09-04 23:28:19 +00001038#endif // _LIBCPP_HAS_NO_VARIADICS
1039
Howard Hinnantc834c512011-11-29 18:15:50 +00001040 template <class _Pp,
1041 class = typename enable_if<is_constructible<value_type, _Pp>::value>::type>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001042 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc834c512011-11-29 18:15:50 +00001043 pair<iterator, bool> insert(_Pp&& __p)
1044 {return __tree_.__insert_unique(_VSTD::forward<_Pp>(__p));}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001045
Howard Hinnantc834c512011-11-29 18:15:50 +00001046 template <class _Pp,
1047 class = typename enable_if<is_constructible<value_type, _Pp>::value>::type>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001048 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc834c512011-11-29 18:15:50 +00001049 iterator insert(const_iterator __pos, _Pp&& __p)
1050 {return __tree_.__insert_unique(__pos.__i_, _VSTD::forward<_Pp>(__p));}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001051
Howard Hinnant74279a52010-09-04 23:28:19 +00001052#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +00001053
Howard Hinnant756c69b2010-09-22 16:48:34 +00001054 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001055 pair<iterator, bool>
1056 insert(const value_type& __v) {return __tree_.__insert_unique(__v);}
1057
Howard Hinnant756c69b2010-09-22 16:48:34 +00001058 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001059 iterator
1060 insert(const_iterator __p, const value_type& __v)
1061 {return __tree_.__insert_unique(__p.__i_, __v);}
1062
1063 template <class _InputIterator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001064 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001065 void insert(_InputIterator __f, _InputIterator __l)
1066 {
1067 for (const_iterator __e = cend(); __f != __l; ++__f)
1068 insert(__e.__i_, *__f);
1069 }
1070
Howard Hinnant33711792011-08-12 21:56:02 +00001071#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1072
Howard Hinnant756c69b2010-09-22 16:48:34 +00001073 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001074 void insert(initializer_list<value_type> __il)
1075 {insert(__il.begin(), __il.end());}
1076
Howard Hinnant33711792011-08-12 21:56:02 +00001077#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1078
Howard Hinnant756c69b2010-09-22 16:48:34 +00001079 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001080 iterator erase(const_iterator __p) {return __tree_.erase(__p.__i_);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001081 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001082 size_type erase(const key_type& __k)
1083 {return __tree_.__erase_unique(__k);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001084 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001085 iterator erase(const_iterator __f, const_iterator __l)
1086 {return __tree_.erase(__f.__i_, __l.__i_);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001087 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001088 void clear() _NOEXCEPT {__tree_.clear();}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001089
Howard Hinnant756c69b2010-09-22 16:48:34 +00001090 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001091 void swap(map& __m)
1092 _NOEXCEPT_(__is_nothrow_swappable<__base>::value)
1093 {__tree_.swap(__m.__tree_);}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001094
Howard Hinnant756c69b2010-09-22 16:48:34 +00001095 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001096 iterator find(const key_type& __k) {return __tree_.find(__k);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001097 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001098 const_iterator find(const key_type& __k) const {return __tree_.find(__k);}
Marshall Clowebb57322013-08-13 22:18:47 +00001099#if _LIBCPP_STD_VER > 11
1100 template <typename _K2>
1101 _LIBCPP_INLINE_VISIBILITY
1102 typename enable_if<__is_transparent<_Compare, _K2>::value,iterator>::type
1103 find(const _K2& __k) {return __tree_.find(__k);}
1104 template <typename _K2>
1105 _LIBCPP_INLINE_VISIBILITY
1106 typename enable_if<__is_transparent<_Compare, _K2>::value,const_iterator>::type
1107 find(const _K2& __k) const {return __tree_.find(__k);}
1108#endif
1109
Howard Hinnant756c69b2010-09-22 16:48:34 +00001110 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001111 size_type count(const key_type& __k) const
1112 {return __tree_.__count_unique(__k);}
Marshall Clowe6a5f522014-08-24 23:54:16 +00001113#if _LIBCPP_STD_VER > 11
1114 template <typename _K2>
1115 _LIBCPP_INLINE_VISIBILITY
1116 typename enable_if<__is_transparent<_Compare, _K2>::value,size_type>::type
1117 count(const _K2& __k) {return __tree_.__count_unique(__k);}
1118#endif
Howard Hinnant756c69b2010-09-22 16:48:34 +00001119 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001120 iterator lower_bound(const key_type& __k)
1121 {return __tree_.lower_bound(__k);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001122 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001123 const_iterator lower_bound(const key_type& __k) const
1124 {return __tree_.lower_bound(__k);}
Marshall Clowebb57322013-08-13 22:18:47 +00001125#if _LIBCPP_STD_VER > 11
1126 template <typename _K2>
1127 _LIBCPP_INLINE_VISIBILITY
1128 typename enable_if<__is_transparent<_Compare, _K2>::value,iterator>::type
1129 lower_bound(const _K2& __k) {return __tree_.lower_bound(__k);}
1130
1131 template <typename _K2>
1132 _LIBCPP_INLINE_VISIBILITY
1133 typename enable_if<__is_transparent<_Compare, _K2>::value,const_iterator>::type
1134 lower_bound(const _K2& __k) const {return __tree_.lower_bound(__k);}
1135#endif
1136
Howard Hinnant756c69b2010-09-22 16:48:34 +00001137 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001138 iterator upper_bound(const key_type& __k)
1139 {return __tree_.upper_bound(__k);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001140 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001141 const_iterator upper_bound(const key_type& __k) const
1142 {return __tree_.upper_bound(__k);}
Marshall Clowebb57322013-08-13 22:18:47 +00001143#if _LIBCPP_STD_VER > 11
1144 template <typename _K2>
1145 _LIBCPP_INLINE_VISIBILITY
1146 typename enable_if<__is_transparent<_Compare, _K2>::value,iterator>::type
1147 upper_bound(const _K2& __k) {return __tree_.upper_bound(__k);}
1148 template <typename _K2>
1149 _LIBCPP_INLINE_VISIBILITY
1150 typename enable_if<__is_transparent<_Compare, _K2>::value,const_iterator>::type
1151 upper_bound(const _K2& __k) const {return __tree_.upper_bound(__k);}
1152#endif
1153
Howard Hinnant756c69b2010-09-22 16:48:34 +00001154 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001155 pair<iterator,iterator> equal_range(const key_type& __k)
1156 {return __tree_.__equal_range_unique(__k);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001157 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001158 pair<const_iterator,const_iterator> equal_range(const key_type& __k) const
1159 {return __tree_.__equal_range_unique(__k);}
Marshall Clowebb57322013-08-13 22:18:47 +00001160#if _LIBCPP_STD_VER > 11
1161 template <typename _K2>
1162 _LIBCPP_INLINE_VISIBILITY
1163 typename enable_if<__is_transparent<_Compare, _K2>::value,pair<iterator,iterator>>::type
1164 equal_range(const _K2& __k) {return __tree_.__equal_range_unique(__k);}
1165 template <typename _K2>
1166 _LIBCPP_INLINE_VISIBILITY
1167 typename enable_if<__is_transparent<_Compare, _K2>::value,pair<const_iterator,const_iterator>>::type
1168 equal_range(const _K2& __k) const {return __tree_.__equal_range_unique(__k);}
1169#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001170
1171private:
1172 typedef typename __base::__node __node;
1173 typedef typename __base::__node_allocator __node_allocator;
1174 typedef typename __base::__node_pointer __node_pointer;
1175 typedef typename __base::__node_const_pointer __node_const_pointer;
1176 typedef typename __base::__node_base_pointer __node_base_pointer;
1177 typedef typename __base::__node_base_const_pointer __node_base_const_pointer;
Howard Hinnantc834c512011-11-29 18:15:50 +00001178 typedef __map_node_destructor<__node_allocator> _Dp;
1179 typedef unique_ptr<__node, _Dp> __node_holder;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001180
Howard Hinnant74279a52010-09-04 23:28:19 +00001181#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +00001182 __node_holder __construct_node();
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001183 template <class _A0>
Howard Hinnantac7e7482013-07-04 20:59:16 +00001184 __node_holder __construct_node(_A0&& __a0);
1185 __node_holder __construct_node_with_key(key_type&& __k);
Howard Hinnant74279a52010-09-04 23:28:19 +00001186#ifndef _LIBCPP_HAS_NO_VARIADICS
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001187 template <class _A0, class _A1, class ..._Args>
1188 __node_holder __construct_node(_A0&& __a0, _A1&& __a1, _Args&& ...__args);
Howard Hinnant74279a52010-09-04 23:28:19 +00001189#endif // _LIBCPP_HAS_NO_VARIADICS
Howard Hinnantc51e1022010-05-11 19:42:16 +00001190#endif
Howard Hinnantac7e7482013-07-04 20:59:16 +00001191 __node_holder __construct_node_with_key(const key_type& __k);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001192
1193 __node_base_pointer&
1194 __find_equal_key(__node_base_pointer& __parent, const key_type& __k);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001195 __node_base_const_pointer
1196 __find_equal_key(__node_base_const_pointer& __parent, const key_type& __k) const;
1197};
1198
1199// Find place to insert if __k doesn't exist
1200// Set __parent to parent of null leaf
1201// Return reference to null leaf
1202// If __k exists, set parent to node of __k and return reference to node of __k
1203template <class _Key, class _Tp, class _Compare, class _Allocator>
1204typename map<_Key, _Tp, _Compare, _Allocator>::__node_base_pointer&
1205map<_Key, _Tp, _Compare, _Allocator>::__find_equal_key(__node_base_pointer& __parent,
1206 const key_type& __k)
1207{
1208 __node_pointer __nd = __tree_.__root();
1209 if (__nd != nullptr)
1210 {
1211 while (true)
1212 {
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001213 if (__tree_.value_comp().key_comp()(__k, __nd->__value_.__cc.first))
Howard Hinnantc51e1022010-05-11 19:42:16 +00001214 {
1215 if (__nd->__left_ != nullptr)
1216 __nd = static_cast<__node_pointer>(__nd->__left_);
1217 else
1218 {
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001219 __parent = static_cast<__node_base_pointer>(__nd);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001220 return __parent->__left_;
1221 }
1222 }
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001223 else if (__tree_.value_comp().key_comp()(__nd->__value_.__cc.first, __k))
Howard Hinnantc51e1022010-05-11 19:42:16 +00001224 {
1225 if (__nd->__right_ != nullptr)
1226 __nd = static_cast<__node_pointer>(__nd->__right_);
1227 else
1228 {
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001229 __parent = static_cast<__node_base_pointer>(__nd);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001230 return __parent->__right_;
1231 }
1232 }
1233 else
1234 {
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001235 __parent = static_cast<__node_base_pointer>(__nd);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001236 return __parent;
1237 }
1238 }
1239 }
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001240 __parent = static_cast<__node_base_pointer>(__tree_.__end_node());
Howard Hinnantc51e1022010-05-11 19:42:16 +00001241 return __parent->__left_;
1242}
1243
Howard Hinnantc51e1022010-05-11 19:42:16 +00001244// Find __k
1245// Set __parent to parent of null leaf and
1246// return reference to null leaf iv __k does not exist.
1247// If __k exists, set parent to node of __k and return reference to node of __k
1248template <class _Key, class _Tp, class _Compare, class _Allocator>
1249typename map<_Key, _Tp, _Compare, _Allocator>::__node_base_const_pointer
1250map<_Key, _Tp, _Compare, _Allocator>::__find_equal_key(__node_base_const_pointer& __parent,
1251 const key_type& __k) const
1252{
1253 __node_const_pointer __nd = __tree_.__root();
1254 if (__nd != nullptr)
1255 {
1256 while (true)
1257 {
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001258 if (__tree_.value_comp().key_comp()(__k, __nd->__value_.__cc.first))
Howard Hinnantc51e1022010-05-11 19:42:16 +00001259 {
1260 if (__nd->__left_ != nullptr)
1261 __nd = static_cast<__node_pointer>(__nd->__left_);
1262 else
1263 {
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001264 __parent = static_cast<__node_base_pointer>(__nd);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001265 return const_cast<const __node_base_const_pointer&>(__parent->__left_);
1266 }
1267 }
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001268 else if (__tree_.value_comp().key_comp()(__nd->__value_.__cc.first, __k))
Howard Hinnantc51e1022010-05-11 19:42:16 +00001269 {
1270 if (__nd->__right_ != nullptr)
1271 __nd = static_cast<__node_pointer>(__nd->__right_);
1272 else
1273 {
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001274 __parent = static_cast<__node_base_pointer>(__nd);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001275 return const_cast<const __node_base_const_pointer&>(__parent->__right_);
1276 }
1277 }
1278 else
1279 {
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001280 __parent = static_cast<__node_base_pointer>(__nd);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001281 return __parent;
1282 }
1283 }
1284 }
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001285 __parent = static_cast<__node_base_pointer>(__tree_.__end_node());
Howard Hinnantc51e1022010-05-11 19:42:16 +00001286 return const_cast<const __node_base_const_pointer&>(__parent->__left_);
1287}
1288
Howard Hinnant74279a52010-09-04 23:28:19 +00001289#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +00001290
1291template <class _Key, class _Tp, class _Compare, class _Allocator>
1292map<_Key, _Tp, _Compare, _Allocator>::map(map&& __m, const allocator_type& __a)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001293 : __tree_(_VSTD::move(__m.__tree_), __a)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001294{
1295 if (__a != __m.get_allocator())
1296 {
1297 const_iterator __e = cend();
1298 while (!__m.empty())
1299 __tree_.__insert_unique(__e.__i_,
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001300 _VSTD::move(__m.__tree_.remove(__m.begin().__i_)->__value_));
Howard Hinnantc51e1022010-05-11 19:42:16 +00001301 }
1302}
1303
1304template <class _Key, class _Tp, class _Compare, class _Allocator>
1305typename map<_Key, _Tp, _Compare, _Allocator>::__node_holder
1306map<_Key, _Tp, _Compare, _Allocator>::__construct_node()
1307{
1308 __node_allocator& __na = __tree_.__node_alloc();
Howard Hinnantc834c512011-11-29 18:15:50 +00001309 __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001310 __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__cc.first));
Howard Hinnantc51e1022010-05-11 19:42:16 +00001311 __h.get_deleter().__first_constructed = true;
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001312 __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__cc.second));
Howard Hinnantc51e1022010-05-11 19:42:16 +00001313 __h.get_deleter().__second_constructed = true;
1314 return __h;
1315}
1316
1317template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001318template <class _A0>
Howard Hinnantac7e7482013-07-04 20:59:16 +00001319typename map<_Key, _Tp, _Compare, _Allocator>::__node_holder
Howard Hinnantc51e1022010-05-11 19:42:16 +00001320map<_Key, _Tp, _Compare, _Allocator>::__construct_node(_A0&& __a0)
1321{
1322 __node_allocator& __na = __tree_.__node_alloc();
Howard Hinnantc834c512011-11-29 18:15:50 +00001323 __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001324 __node_traits::construct(__na, _VSTD::addressof(__h->__value_), _VSTD::forward<_A0>(__a0));
Howard Hinnantc51e1022010-05-11 19:42:16 +00001325 __h.get_deleter().__first_constructed = true;
1326 __h.get_deleter().__second_constructed = true;
1327 return __h;
1328}
1329
1330template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnantac7e7482013-07-04 20:59:16 +00001331typename map<_Key, _Tp, _Compare, _Allocator>::__node_holder
1332map<_Key, _Tp, _Compare, _Allocator>::__construct_node_with_key(key_type&& __k)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001333{
1334 __node_allocator& __na = __tree_.__node_alloc();
Howard Hinnantc834c512011-11-29 18:15:50 +00001335 __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
Howard Hinnantac7e7482013-07-04 20:59:16 +00001336 __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__cc.first), _VSTD::move(__k));
Howard Hinnantc51e1022010-05-11 19:42:16 +00001337 __h.get_deleter().__first_constructed = true;
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001338 __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__cc.second));
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001339 __h.get_deleter().__second_constructed = true;
Howard Hinnanta31e9682013-08-22 18:29:50 +00001340 return __h;
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001341}
1342
1343#ifndef _LIBCPP_HAS_NO_VARIADICS
1344
1345template <class _Key, class _Tp, class _Compare, class _Allocator>
1346template <class _A0, class _A1, class ..._Args>
1347typename map<_Key, _Tp, _Compare, _Allocator>::__node_holder
1348map<_Key, _Tp, _Compare, _Allocator>::__construct_node(_A0&& __a0, _A1&& __a1, _Args&& ...__args)
1349{
1350 __node_allocator& __na = __tree_.__node_alloc();
1351 __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
1352 __node_traits::construct(__na, _VSTD::addressof(__h->__value_),
1353 _VSTD::forward<_A0>(__a0), _VSTD::forward<_A1>(__a1),
1354 _VSTD::forward<_Args>(__args)...);
1355 __h.get_deleter().__first_constructed = true;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001356 __h.get_deleter().__second_constructed = true;
1357 return __h;
1358}
1359
Howard Hinnant74279a52010-09-04 23:28:19 +00001360#endif // _LIBCPP_HAS_NO_VARIADICS
1361
Howard Hinnantac7e7482013-07-04 20:59:16 +00001362#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +00001363
1364template <class _Key, class _Tp, class _Compare, class _Allocator>
1365typename map<_Key, _Tp, _Compare, _Allocator>::__node_holder
Howard Hinnantac7e7482013-07-04 20:59:16 +00001366map<_Key, _Tp, _Compare, _Allocator>::__construct_node_with_key(const key_type& __k)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001367{
1368 __node_allocator& __na = __tree_.__node_alloc();
Howard Hinnantc834c512011-11-29 18:15:50 +00001369 __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001370 __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__cc.first), __k);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001371 __h.get_deleter().__first_constructed = true;
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001372 __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__cc.second));
Howard Hinnantc51e1022010-05-11 19:42:16 +00001373 __h.get_deleter().__second_constructed = true;
Howard Hinnanta31e9682013-08-22 18:29:50 +00001374 return _VSTD::move(__h); // explicitly moved for C++03
Howard Hinnantc51e1022010-05-11 19:42:16 +00001375}
1376
Howard Hinnantc51e1022010-05-11 19:42:16 +00001377template <class _Key, class _Tp, class _Compare, class _Allocator>
1378_Tp&
1379map<_Key, _Tp, _Compare, _Allocator>::operator[](const key_type& __k)
1380{
1381 __node_base_pointer __parent;
1382 __node_base_pointer& __child = __find_equal_key(__parent, __k);
1383 __node_pointer __r = static_cast<__node_pointer>(__child);
1384 if (__child == nullptr)
1385 {
Howard Hinnantac7e7482013-07-04 20:59:16 +00001386 __node_holder __h = __construct_node_with_key(__k);
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001387 __tree_.__insert_node_at(__parent, __child, static_cast<__node_base_pointer>(__h.get()));
Howard Hinnantc51e1022010-05-11 19:42:16 +00001388 __r = __h.release();
1389 }
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001390 return __r->__value_.__cc.second;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001391}
1392
Howard Hinnant74279a52010-09-04 23:28:19 +00001393#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +00001394
1395template <class _Key, class _Tp, class _Compare, class _Allocator>
1396_Tp&
1397map<_Key, _Tp, _Compare, _Allocator>::operator[](key_type&& __k)
1398{
1399 __node_base_pointer __parent;
1400 __node_base_pointer& __child = __find_equal_key(__parent, __k);
1401 __node_pointer __r = static_cast<__node_pointer>(__child);
1402 if (__child == nullptr)
1403 {
Howard Hinnantac7e7482013-07-04 20:59:16 +00001404 __node_holder __h = __construct_node_with_key(_VSTD::move(__k));
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001405 __tree_.__insert_node_at(__parent, __child, static_cast<__node_base_pointer>(__h.get()));
Howard Hinnantc51e1022010-05-11 19:42:16 +00001406 __r = __h.release();
1407 }
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001408 return __r->__value_.__cc.second;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001409}
1410
Howard Hinnant74279a52010-09-04 23:28:19 +00001411#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +00001412
1413template <class _Key, class _Tp, class _Compare, class _Allocator>
1414_Tp&
1415map<_Key, _Tp, _Compare, _Allocator>::at(const key_type& __k)
1416{
1417 __node_base_pointer __parent;
1418 __node_base_pointer& __child = __find_equal_key(__parent, __k);
Howard Hinnant72f73582010-08-11 17:04:31 +00001419#ifndef _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +00001420 if (__child == nullptr)
1421 throw out_of_range("map::at: key not found");
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001422#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001423 return static_cast<__node_pointer>(__child)->__value_.__cc.second;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001424}
1425
1426template <class _Key, class _Tp, class _Compare, class _Allocator>
1427const _Tp&
1428map<_Key, _Tp, _Compare, _Allocator>::at(const key_type& __k) const
1429{
1430 __node_base_const_pointer __parent;
1431 __node_base_const_pointer __child = __find_equal_key(__parent, __k);
Howard Hinnant72f73582010-08-11 17:04:31 +00001432#ifndef _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +00001433 if (__child == nullptr)
1434 throw out_of_range("map::at: key not found");
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001435#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001436 return static_cast<__node_const_pointer>(__child)->__value_.__cc.second;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001437}
1438
Howard Hinnant74279a52010-09-04 23:28:19 +00001439#if !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001440
1441template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001442template <class ..._Args>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001443pair<typename map<_Key, _Tp, _Compare, _Allocator>::iterator, bool>
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001444map<_Key, _Tp, _Compare, _Allocator>::emplace(_Args&& ...__args)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001445{
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001446 __node_holder __h = __construct_node(_VSTD::forward<_Args>(__args)...);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001447 pair<iterator, bool> __r = __tree_.__node_insert_unique(__h.get());
1448 if (__r.second)
1449 __h.release();
1450 return __r;
1451}
1452
1453template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001454template <class ..._Args>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001455typename map<_Key, _Tp, _Compare, _Allocator>::iterator
1456map<_Key, _Tp, _Compare, _Allocator>::emplace_hint(const_iterator __p,
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001457 _Args&& ...__args)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001458{
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001459 __node_holder __h = __construct_node(_VSTD::forward<_Args>(__args)...);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001460 iterator __r = __tree_.__node_insert_unique(__p.__i_, __h.get());
1461 if (__r.__i_.__ptr_ == __h.get())
1462 __h.release();
1463 return __r;
1464}
1465
Howard Hinnant74279a52010-09-04 23:28:19 +00001466#endif // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001467
1468template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001469inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001470bool
1471operator==(const map<_Key, _Tp, _Compare, _Allocator>& __x,
1472 const map<_Key, _Tp, _Compare, _Allocator>& __y)
1473{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001474 return __x.size() == __y.size() && _VSTD::equal(__x.begin(), __x.end(), __y.begin());
Howard Hinnantc51e1022010-05-11 19:42:16 +00001475}
1476
1477template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001478inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001479bool
1480operator< (const map<_Key, _Tp, _Compare, _Allocator>& __x,
1481 const map<_Key, _Tp, _Compare, _Allocator>& __y)
1482{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001483 return _VSTD::lexicographical_compare(__x.begin(), __x.end(), __y.begin(), __y.end());
Howard Hinnantc51e1022010-05-11 19:42:16 +00001484}
1485
1486template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001487inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001488bool
1489operator!=(const map<_Key, _Tp, _Compare, _Allocator>& __x,
1490 const map<_Key, _Tp, _Compare, _Allocator>& __y)
1491{
1492 return !(__x == __y);
1493}
1494
1495template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001496inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001497bool
1498operator> (const map<_Key, _Tp, _Compare, _Allocator>& __x,
1499 const map<_Key, _Tp, _Compare, _Allocator>& __y)
1500{
1501 return __y < __x;
1502}
1503
1504template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001505inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001506bool
1507operator>=(const map<_Key, _Tp, _Compare, _Allocator>& __x,
1508 const map<_Key, _Tp, _Compare, _Allocator>& __y)
1509{
1510 return !(__x < __y);
1511}
1512
1513template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001514inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001515bool
1516operator<=(const map<_Key, _Tp, _Compare, _Allocator>& __x,
1517 const map<_Key, _Tp, _Compare, _Allocator>& __y)
1518{
1519 return !(__y < __x);
1520}
1521
1522template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001523inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001524void
1525swap(map<_Key, _Tp, _Compare, _Allocator>& __x,
1526 map<_Key, _Tp, _Compare, _Allocator>& __y)
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001527 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
Howard Hinnantc51e1022010-05-11 19:42:16 +00001528{
1529 __x.swap(__y);
1530}
1531
1532template <class _Key, class _Tp, class _Compare = less<_Key>,
1533 class _Allocator = allocator<pair<const _Key, _Tp> > >
Howard Hinnanta37d3cf2013-08-12 18:38:34 +00001534class _LIBCPP_TYPE_VIS_ONLY multimap
Howard Hinnantc51e1022010-05-11 19:42:16 +00001535{
1536public:
1537 // types:
1538 typedef _Key key_type;
1539 typedef _Tp mapped_type;
1540 typedef pair<const key_type, mapped_type> value_type;
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001541 typedef pair<key_type, mapped_type> __nc_value_type;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001542 typedef _Compare key_compare;
1543 typedef _Allocator allocator_type;
1544 typedef value_type& reference;
1545 typedef const value_type& const_reference;
1546
Howard Hinnanta37d3cf2013-08-12 18:38:34 +00001547 class _LIBCPP_TYPE_VIS_ONLY value_compare
Howard Hinnantc51e1022010-05-11 19:42:16 +00001548 : public binary_function<value_type, value_type, bool>
1549 {
1550 friend class multimap;
1551 protected:
1552 key_compare comp;
1553
Howard Hinnant756c69b2010-09-22 16:48:34 +00001554 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001555 value_compare(key_compare c) : comp(c) {}
1556 public:
Howard Hinnant756c69b2010-09-22 16:48:34 +00001557 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001558 bool operator()(const value_type& __x, const value_type& __y) const
1559 {return comp(__x.first, __y.first);}
1560 };
1561
1562private:
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001563
Howard Hinnant89f8b792013-09-30 19:08:22 +00001564 typedef _VSTD::__value_type<key_type, mapped_type> __value_type;
Howard Hinnant90b91592013-07-05 18:06:00 +00001565 typedef __map_value_compare<key_type, __value_type, key_compare> __vc;
Marshall Clow940e01c2015-04-07 05:21:38 +00001566 typedef typename __rebind_alloc_helper<allocator_traits<allocator_type>,
1567 __value_type>::type __allocator_type;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001568 typedef __tree<__value_type, __vc, __allocator_type> __base;
1569 typedef typename __base::__node_traits __node_traits;
1570 typedef allocator_traits<allocator_type> __alloc_traits;
1571
1572 __base __tree_;
1573
1574public:
1575 typedef typename __alloc_traits::pointer pointer;
1576 typedef typename __alloc_traits::const_pointer const_pointer;
1577 typedef typename __alloc_traits::size_type size_type;
1578 typedef typename __alloc_traits::difference_type difference_type;
1579 typedef __map_iterator<typename __base::iterator> iterator;
1580 typedef __map_const_iterator<typename __base::const_iterator> const_iterator;
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001581 typedef _VSTD::reverse_iterator<iterator> reverse_iterator;
1582 typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001583
Howard Hinnant756c69b2010-09-22 16:48:34 +00001584 _LIBCPP_INLINE_VISIBILITY
Marshall Clow7086a5a2014-03-10 04:50:10 +00001585 multimap()
1586 _NOEXCEPT_(
1587 is_nothrow_default_constructible<allocator_type>::value &&
1588 is_nothrow_default_constructible<key_compare>::value &&
1589 is_nothrow_copy_constructible<key_compare>::value)
1590 : __tree_(__vc(key_compare())) {}
1591
1592 _LIBCPP_INLINE_VISIBILITY
1593 explicit multimap(const key_compare& __comp)
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001594 _NOEXCEPT_(
1595 is_nothrow_default_constructible<allocator_type>::value &&
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001596 is_nothrow_copy_constructible<key_compare>::value)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001597 : __tree_(__vc(__comp)) {}
1598
Howard Hinnant756c69b2010-09-22 16:48:34 +00001599 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001600 explicit multimap(const key_compare& __comp, const allocator_type& __a)
1601 : __tree_(__vc(__comp), __a) {}
1602
1603 template <class _InputIterator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001604 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001605 multimap(_InputIterator __f, _InputIterator __l,
1606 const key_compare& __comp = key_compare())
1607 : __tree_(__vc(__comp))
1608 {
1609 insert(__f, __l);
1610 }
1611
1612 template <class _InputIterator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001613 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001614 multimap(_InputIterator __f, _InputIterator __l,
1615 const key_compare& __comp, const allocator_type& __a)
1616 : __tree_(__vc(__comp), __a)
1617 {
1618 insert(__f, __l);
1619 }
1620
Marshall Clow300abfb2013-09-11 01:15:47 +00001621#if _LIBCPP_STD_VER > 11
1622 template <class _InputIterator>
1623 _LIBCPP_INLINE_VISIBILITY
1624 multimap(_InputIterator __f, _InputIterator __l, const allocator_type& __a)
1625 : multimap(__f, __l, key_compare(), __a) {}
1626#endif
1627
Howard Hinnant756c69b2010-09-22 16:48:34 +00001628 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001629 multimap(const multimap& __m)
1630 : __tree_(__m.__tree_.value_comp(),
1631 __alloc_traits::select_on_container_copy_construction(__m.__tree_.__alloc()))
1632 {
1633 insert(__m.begin(), __m.end());
1634 }
1635
Howard Hinnantd3a657f2011-07-01 19:24:36 +00001636 _LIBCPP_INLINE_VISIBILITY
1637 multimap& operator=(const multimap& __m)
1638 {
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001639#if __cplusplus >= 201103L
Howard Hinnantd3a657f2011-07-01 19:24:36 +00001640 __tree_ = __m.__tree_;
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001641#else
Marshall Clowdb3cfcb2014-02-08 04:03:14 +00001642 if (this != &__m) {
1643 __tree_.clear();
1644 __tree_.value_comp() = __m.__tree_.value_comp();
1645 __tree_.__copy_assign_alloc(__m.__tree_);
1646 insert(__m.begin(), __m.end());
1647 }
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001648#endif
Howard Hinnantd3a657f2011-07-01 19:24:36 +00001649 return *this;
1650 }
1651
Howard Hinnant74279a52010-09-04 23:28:19 +00001652#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +00001653
Howard Hinnant756c69b2010-09-22 16:48:34 +00001654 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001655 multimap(multimap&& __m)
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001656 _NOEXCEPT_(is_nothrow_move_constructible<__base>::value)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001657 : __tree_(_VSTD::move(__m.__tree_))
Howard Hinnantc51e1022010-05-11 19:42:16 +00001658 {
1659 }
1660
1661 multimap(multimap&& __m, const allocator_type& __a);
1662
Howard Hinnant756c69b2010-09-22 16:48:34 +00001663 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant33711792011-08-12 21:56:02 +00001664 multimap& operator=(multimap&& __m)
1665 _NOEXCEPT_(is_nothrow_move_assignable<__base>::value)
1666 {
1667 __tree_ = _VSTD::move(__m.__tree_);
1668 return *this;
1669 }
1670
1671#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
1672
1673#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1674
1675 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001676 multimap(initializer_list<value_type> __il, const key_compare& __comp = key_compare())
1677 : __tree_(__vc(__comp))
1678 {
1679 insert(__il.begin(), __il.end());
1680 }
1681
Howard Hinnant756c69b2010-09-22 16:48:34 +00001682 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001683 multimap(initializer_list<value_type> __il, const key_compare& __comp, const allocator_type& __a)
1684 : __tree_(__vc(__comp), __a)
1685 {
1686 insert(__il.begin(), __il.end());
1687 }
1688
Marshall Clow300abfb2013-09-11 01:15:47 +00001689#if _LIBCPP_STD_VER > 11
1690 _LIBCPP_INLINE_VISIBILITY
1691 multimap(initializer_list<value_type> __il, const allocator_type& __a)
1692 : multimap(__il, key_compare(), __a) {}
1693#endif
1694
Howard Hinnant756c69b2010-09-22 16:48:34 +00001695 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001696 multimap& operator=(initializer_list<value_type> __il)
1697 {
1698 __tree_.__assign_multi(__il.begin(), __il.end());
1699 return *this;
1700 }
Howard Hinnant33711792011-08-12 21:56:02 +00001701
1702#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantc51e1022010-05-11 19:42:16 +00001703
Howard Hinnant756c69b2010-09-22 16:48:34 +00001704 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001705 explicit multimap(const allocator_type& __a)
1706 : __tree_(__a)
1707 {
1708 }
1709
Howard Hinnant756c69b2010-09-22 16:48:34 +00001710 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001711 multimap(const multimap& __m, const allocator_type& __a)
1712 : __tree_(__m.__tree_.value_comp(), __a)
1713 {
1714 insert(__m.begin(), __m.end());
1715 }
1716
Howard Hinnant756c69b2010-09-22 16:48:34 +00001717 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001718 iterator begin() _NOEXCEPT {return __tree_.begin();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001719 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001720 const_iterator begin() const _NOEXCEPT {return __tree_.begin();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001721 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001722 iterator end() _NOEXCEPT {return __tree_.end();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001723 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001724 const_iterator end() const _NOEXCEPT {return __tree_.end();}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001725
Howard Hinnant756c69b2010-09-22 16:48:34 +00001726 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001727 reverse_iterator rbegin() _NOEXCEPT {return reverse_iterator(end());}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001728 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001729 const_reverse_iterator rbegin() const _NOEXCEPT
1730 {return const_reverse_iterator(end());}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001731 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001732 reverse_iterator rend() _NOEXCEPT {return reverse_iterator(begin());}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001733 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001734 const_reverse_iterator rend() const _NOEXCEPT
1735 {return const_reverse_iterator(begin());}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001736
Howard Hinnant756c69b2010-09-22 16:48:34 +00001737 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001738 const_iterator cbegin() const _NOEXCEPT {return begin();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001739 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001740 const_iterator cend() const _NOEXCEPT {return end();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001741 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001742 const_reverse_iterator crbegin() const _NOEXCEPT {return rbegin();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001743 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001744 const_reverse_iterator crend() const _NOEXCEPT {return rend();}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001745
Howard Hinnant756c69b2010-09-22 16:48:34 +00001746 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001747 bool empty() const _NOEXCEPT {return __tree_.size() == 0;}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001748 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001749 size_type size() const _NOEXCEPT {return __tree_.size();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001750 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001751 size_type max_size() const _NOEXCEPT {return __tree_.max_size();}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001752
Howard Hinnant756c69b2010-09-22 16:48:34 +00001753 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001754 allocator_type get_allocator() const _NOEXCEPT {return __tree_.__alloc();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001755 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001756 key_compare key_comp() const {return __tree_.value_comp().key_comp();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001757 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001758 value_compare value_comp() const
1759 {return value_compare(__tree_.value_comp().key_comp());}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001760
Howard Hinnant74279a52010-09-04 23:28:19 +00001761#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant74279a52010-09-04 23:28:19 +00001762#ifndef _LIBCPP_HAS_NO_VARIADICS
1763
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001764 template <class ..._Args>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001765 iterator
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001766 emplace(_Args&& ...__args);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001767
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001768 template <class ..._Args>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001769 iterator
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001770 emplace_hint(const_iterator __p, _Args&& ...__args);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001771
Howard Hinnant74279a52010-09-04 23:28:19 +00001772#endif // _LIBCPP_HAS_NO_VARIADICS
1773
Howard Hinnantc834c512011-11-29 18:15:50 +00001774 template <class _Pp,
1775 class = typename enable_if<is_constructible<value_type, _Pp>::value>::type>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001776 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc834c512011-11-29 18:15:50 +00001777 iterator insert(_Pp&& __p)
1778 {return __tree_.__insert_multi(_VSTD::forward<_Pp>(__p));}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001779
Howard Hinnantc834c512011-11-29 18:15:50 +00001780 template <class _Pp,
1781 class = typename enable_if<is_constructible<value_type, _Pp>::value>::type>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001782 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc834c512011-11-29 18:15:50 +00001783 iterator insert(const_iterator __pos, _Pp&& __p)
1784 {return __tree_.__insert_multi(__pos.__i_, _VSTD::forward<_Pp>(__p));}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001785
Howard Hinnant74279a52010-09-04 23:28:19 +00001786#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +00001787
Howard Hinnant756c69b2010-09-22 16:48:34 +00001788 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001789 iterator insert(const value_type& __v) {return __tree_.__insert_multi(__v);}
1790
Howard Hinnant756c69b2010-09-22 16:48:34 +00001791 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001792 iterator insert(const_iterator __p, const value_type& __v)
1793 {return __tree_.__insert_multi(__p.__i_, __v);}
1794
1795 template <class _InputIterator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001796 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001797 void insert(_InputIterator __f, _InputIterator __l)
1798 {
1799 for (const_iterator __e = cend(); __f != __l; ++__f)
1800 __tree_.__insert_multi(__e.__i_, *__f);
1801 }
1802
Howard Hinnant33711792011-08-12 21:56:02 +00001803#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1804
Howard Hinnant756c69b2010-09-22 16:48:34 +00001805 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001806 void insert(initializer_list<value_type> __il)
1807 {insert(__il.begin(), __il.end());}
1808
Howard Hinnant33711792011-08-12 21:56:02 +00001809#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1810
Howard Hinnant756c69b2010-09-22 16:48:34 +00001811 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001812 iterator erase(const_iterator __p) {return __tree_.erase(__p.__i_);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001813 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001814 size_type erase(const key_type& __k) {return __tree_.__erase_multi(__k);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001815 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001816 iterator erase(const_iterator __f, const_iterator __l)
1817 {return __tree_.erase(__f.__i_, __l.__i_);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001818 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001819 void clear() {__tree_.clear();}
1820
Howard Hinnant756c69b2010-09-22 16:48:34 +00001821 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00001822 void swap(multimap& __m)
1823 _NOEXCEPT_(__is_nothrow_swappable<__base>::value)
1824 {__tree_.swap(__m.__tree_);}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001825
Howard Hinnant756c69b2010-09-22 16:48:34 +00001826 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001827 iterator find(const key_type& __k) {return __tree_.find(__k);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001828 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001829 const_iterator find(const key_type& __k) const {return __tree_.find(__k);}
Marshall Clowebb57322013-08-13 22:18:47 +00001830#if _LIBCPP_STD_VER > 11
1831 template <typename _K2>
1832 _LIBCPP_INLINE_VISIBILITY
1833 typename enable_if<__is_transparent<_Compare, _K2>::value,iterator>::type
1834 find(const _K2& __k) {return __tree_.find(__k);}
1835 template <typename _K2>
1836 _LIBCPP_INLINE_VISIBILITY
1837 typename enable_if<__is_transparent<_Compare, _K2>::value,const_iterator>::type
1838 find(const _K2& __k) const {return __tree_.find(__k);}
1839#endif
1840
Howard Hinnant756c69b2010-09-22 16:48:34 +00001841 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001842 size_type count(const key_type& __k) const
1843 {return __tree_.__count_multi(__k);}
Marshall Clowe6a5f522014-08-24 23:54:16 +00001844#if _LIBCPP_STD_VER > 11
1845 template <typename _K2>
1846 _LIBCPP_INLINE_VISIBILITY
1847 typename enable_if<__is_transparent<_Compare, _K2>::value,size_type>::type
1848 count(const _K2& __k) {return __tree_.__count_multi(__k);}
1849#endif
Howard Hinnant756c69b2010-09-22 16:48:34 +00001850 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001851 iterator lower_bound(const key_type& __k)
1852 {return __tree_.lower_bound(__k);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001853 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001854 const_iterator lower_bound(const key_type& __k) const
1855 {return __tree_.lower_bound(__k);}
Marshall Clowebb57322013-08-13 22:18:47 +00001856#if _LIBCPP_STD_VER > 11
1857 template <typename _K2>
1858 _LIBCPP_INLINE_VISIBILITY
1859 typename enable_if<__is_transparent<_Compare, _K2>::value,iterator>::type
1860 lower_bound(const _K2& __k) {return __tree_.lower_bound(__k);}
1861
1862 template <typename _K2>
1863 _LIBCPP_INLINE_VISIBILITY
1864 typename enable_if<__is_transparent<_Compare, _K2>::value,const_iterator>::type
1865 lower_bound(const _K2& __k) const {return __tree_.lower_bound(__k);}
1866#endif
1867
Howard Hinnant756c69b2010-09-22 16:48:34 +00001868 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001869 iterator upper_bound(const key_type& __k)
1870 {return __tree_.upper_bound(__k);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001871 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001872 const_iterator upper_bound(const key_type& __k) const
1873 {return __tree_.upper_bound(__k);}
Marshall Clowebb57322013-08-13 22:18:47 +00001874#if _LIBCPP_STD_VER > 11
1875 template <typename _K2>
1876 _LIBCPP_INLINE_VISIBILITY
1877 typename enable_if<__is_transparent<_Compare, _K2>::value,iterator>::type
1878 upper_bound(const _K2& __k) {return __tree_.upper_bound(__k);}
1879 template <typename _K2>
1880 _LIBCPP_INLINE_VISIBILITY
1881 typename enable_if<__is_transparent<_Compare, _K2>::value,const_iterator>::type
1882 upper_bound(const _K2& __k) const {return __tree_.upper_bound(__k);}
1883#endif
1884
Howard Hinnant756c69b2010-09-22 16:48:34 +00001885 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001886 pair<iterator,iterator> equal_range(const key_type& __k)
1887 {return __tree_.__equal_range_multi(__k);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001888 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001889 pair<const_iterator,const_iterator> equal_range(const key_type& __k) const
1890 {return __tree_.__equal_range_multi(__k);}
Marshall Clowebb57322013-08-13 22:18:47 +00001891#if _LIBCPP_STD_VER > 11
1892 template <typename _K2>
1893 _LIBCPP_INLINE_VISIBILITY
1894 typename enable_if<__is_transparent<_Compare, _K2>::value,pair<iterator,iterator>>::type
1895 equal_range(const _K2& __k) {return __tree_.__equal_range_multi(__k);}
1896 template <typename _K2>
1897 _LIBCPP_INLINE_VISIBILITY
1898 typename enable_if<__is_transparent<_Compare, _K2>::value,pair<const_iterator,const_iterator>>::type
1899 equal_range(const _K2& __k) const {return __tree_.__equal_range_multi(__k);}
1900#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001901
1902private:
1903 typedef typename __base::__node __node;
1904 typedef typename __base::__node_allocator __node_allocator;
1905 typedef typename __base::__node_pointer __node_pointer;
1906 typedef typename __base::__node_const_pointer __node_const_pointer;
Howard Hinnantc834c512011-11-29 18:15:50 +00001907 typedef __map_node_destructor<__node_allocator> _Dp;
1908 typedef unique_ptr<__node, _Dp> __node_holder;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001909
Howard Hinnant74279a52010-09-04 23:28:19 +00001910#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +00001911 __node_holder __construct_node();
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001912 template <class _A0>
Howard Hinnantac7e7482013-07-04 20:59:16 +00001913 __node_holder
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001914 __construct_node(_A0&& __a0);
Howard Hinnant74279a52010-09-04 23:28:19 +00001915#ifndef _LIBCPP_HAS_NO_VARIADICS
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001916 template <class _A0, class _A1, class ..._Args>
1917 __node_holder __construct_node(_A0&& __a0, _A1&& __a1, _Args&& ...__args);
Howard Hinnant74279a52010-09-04 23:28:19 +00001918#endif // _LIBCPP_HAS_NO_VARIADICS
1919#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +00001920};
1921
Howard Hinnant74279a52010-09-04 23:28:19 +00001922#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +00001923
1924template <class _Key, class _Tp, class _Compare, class _Allocator>
1925multimap<_Key, _Tp, _Compare, _Allocator>::multimap(multimap&& __m, const allocator_type& __a)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001926 : __tree_(_VSTD::move(__m.__tree_), __a)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001927{
1928 if (__a != __m.get_allocator())
1929 {
1930 const_iterator __e = cend();
1931 while (!__m.empty())
1932 __tree_.__insert_multi(__e.__i_,
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001933 _VSTD::move(__m.__tree_.remove(__m.begin().__i_)->__value_));
Howard Hinnantc51e1022010-05-11 19:42:16 +00001934 }
1935}
1936
1937template <class _Key, class _Tp, class _Compare, class _Allocator>
1938typename multimap<_Key, _Tp, _Compare, _Allocator>::__node_holder
1939multimap<_Key, _Tp, _Compare, _Allocator>::__construct_node()
1940{
1941 __node_allocator& __na = __tree_.__node_alloc();
Howard Hinnantc834c512011-11-29 18:15:50 +00001942 __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001943 __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__cc.first));
Howard Hinnantc51e1022010-05-11 19:42:16 +00001944 __h.get_deleter().__first_constructed = true;
Howard Hinnant2d0046b2013-06-19 21:29:40 +00001945 __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__cc.second));
Howard Hinnantc51e1022010-05-11 19:42:16 +00001946 __h.get_deleter().__second_constructed = true;
1947 return __h;
1948}
1949
1950template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001951template <class _A0>
Howard Hinnantac7e7482013-07-04 20:59:16 +00001952typename multimap<_Key, _Tp, _Compare, _Allocator>::__node_holder
Howard Hinnantc51e1022010-05-11 19:42:16 +00001953multimap<_Key, _Tp, _Compare, _Allocator>::__construct_node(_A0&& __a0)
1954{
1955 __node_allocator& __na = __tree_.__node_alloc();
Howard Hinnantc834c512011-11-29 18:15:50 +00001956 __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001957 __node_traits::construct(__na, _VSTD::addressof(__h->__value_), _VSTD::forward<_A0>(__a0));
Howard Hinnantc51e1022010-05-11 19:42:16 +00001958 __h.get_deleter().__first_constructed = true;
1959 __h.get_deleter().__second_constructed = true;
1960 return __h;
1961}
1962
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001963#ifndef _LIBCPP_HAS_NO_VARIADICS
1964
1965template <class _Key, class _Tp, class _Compare, class _Allocator>
1966template <class _A0, class _A1, class ..._Args>
1967typename multimap<_Key, _Tp, _Compare, _Allocator>::__node_holder
1968multimap<_Key, _Tp, _Compare, _Allocator>::__construct_node(_A0&& __a0, _A1&& __a1, _Args&& ...__args)
1969{
1970 __node_allocator& __na = __tree_.__node_alloc();
1971 __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
1972 __node_traits::construct(__na, _VSTD::addressof(__h->__value_),
1973 _VSTD::forward<_A0>(__a0), _VSTD::forward<_A1>(__a1),
1974 _VSTD::forward<_Args>(__args)...);
1975 __h.get_deleter().__first_constructed = true;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001976 __h.get_deleter().__second_constructed = true;
1977 return __h;
1978}
1979
Howard Hinnant74279a52010-09-04 23:28:19 +00001980#endif // _LIBCPP_HAS_NO_VARIADICS
1981#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +00001982
Howard Hinnant74279a52010-09-04 23:28:19 +00001983#if !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001984
1985template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001986template <class ..._Args>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001987typename multimap<_Key, _Tp, _Compare, _Allocator>::iterator
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001988multimap<_Key, _Tp, _Compare, _Allocator>::emplace(_Args&& ...__args)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001989{
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001990 __node_holder __h = __construct_node(_VSTD::forward<_Args>(__args)...);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001991 iterator __r = __tree_.__node_insert_multi(__h.get());
1992 __h.release();
1993 return __r;
1994}
1995
1996template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant29eb9b82012-05-25 22:04:21 +00001997template <class ..._Args>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001998typename multimap<_Key, _Tp, _Compare, _Allocator>::iterator
1999multimap<_Key, _Tp, _Compare, _Allocator>::emplace_hint(const_iterator __p,
Howard Hinnantc51e1022010-05-11 19:42:16 +00002000 _Args&& ...__args)
2001{
Howard Hinnant29eb9b82012-05-25 22:04:21 +00002002 __node_holder __h = __construct_node(_VSTD::forward<_Args>(__args)...);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002003 iterator __r = __tree_.__node_insert_multi(__p.__i_, __h.get());
2004 __h.release();
2005 return __r;
2006}
2007
Howard Hinnant74279a52010-09-04 23:28:19 +00002008#endif // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
Howard Hinnantc51e1022010-05-11 19:42:16 +00002009
2010template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00002011inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002012bool
2013operator==(const multimap<_Key, _Tp, _Compare, _Allocator>& __x,
2014 const multimap<_Key, _Tp, _Compare, _Allocator>& __y)
2015{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00002016 return __x.size() == __y.size() && _VSTD::equal(__x.begin(), __x.end(), __y.begin());
Howard Hinnantc51e1022010-05-11 19:42:16 +00002017}
2018
2019template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00002020inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002021bool
2022operator< (const multimap<_Key, _Tp, _Compare, _Allocator>& __x,
2023 const multimap<_Key, _Tp, _Compare, _Allocator>& __y)
2024{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00002025 return _VSTD::lexicographical_compare(__x.begin(), __x.end(), __y.begin(), __y.end());
Howard Hinnantc51e1022010-05-11 19:42:16 +00002026}
2027
2028template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00002029inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002030bool
2031operator!=(const multimap<_Key, _Tp, _Compare, _Allocator>& __x,
2032 const multimap<_Key, _Tp, _Compare, _Allocator>& __y)
2033{
2034 return !(__x == __y);
2035}
2036
2037template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00002038inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002039bool
2040operator> (const multimap<_Key, _Tp, _Compare, _Allocator>& __x,
2041 const multimap<_Key, _Tp, _Compare, _Allocator>& __y)
2042{
2043 return __y < __x;
2044}
2045
2046template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00002047inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002048bool
2049operator>=(const multimap<_Key, _Tp, _Compare, _Allocator>& __x,
2050 const multimap<_Key, _Tp, _Compare, _Allocator>& __y)
2051{
2052 return !(__x < __y);
2053}
2054
2055template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00002056inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002057bool
2058operator<=(const multimap<_Key, _Tp, _Compare, _Allocator>& __x,
2059 const multimap<_Key, _Tp, _Compare, _Allocator>& __y)
2060{
2061 return !(__y < __x);
2062}
2063
2064template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant756c69b2010-09-22 16:48:34 +00002065inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002066void
2067swap(multimap<_Key, _Tp, _Compare, _Allocator>& __x,
2068 multimap<_Key, _Tp, _Compare, _Allocator>& __y)
Howard Hinnant2f1ea9c2011-06-04 14:31:57 +00002069 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
Howard Hinnantc51e1022010-05-11 19:42:16 +00002070{
2071 __x.swap(__y);
2072}
2073
2074_LIBCPP_END_NAMESPACE_STD
2075
2076#endif // _LIBCPP_MAP