blob: b58846b044a6039b922a9edf61e58efe36daaf94 [file] [log] [blame]
Howard Hinnantbc8d3f92010-05-11 19:42:161// -*- C++ -*-
2//===----------------------------- map ------------------------------------===//
3//
Howard Hinnantf5256e12010-05-11 21:36:014// The LLVM Compiler Infrastructure
Howard Hinnantbc8d3f92010-05-11 19:42:165//
Howard Hinnantb64f8b02010-11-16 22:09:026// This file is dual licensed under the MIT and the University of Illinois Open
7// Source Licenses. See LICENSE.TXT for details.
Howard Hinnantbc8d3f92010-05-11 19:42:168//
9//===----------------------------------------------------------------------===//
10
11#ifndef _LIBCPP_MAP
12#define _LIBCPP_MAP
13
14/*
15
16 map synopsis
17
18namespace std
19{
20
21template <class Key, class T, class Compare = less<Key>,
22 class Allocator = allocator<pair<const Key, T>>>
23class map
24{
25public:
26 // types:
27 typedef Key key_type;
28 typedef T mapped_type;
29 typedef pair<const key_type, mapped_type> value_type;
30 typedef Compare key_compare;
31 typedef Allocator allocator_type;
32 typedef typename allocator_type::reference reference;
33 typedef typename allocator_type::const_reference const_reference;
34 typedef typename allocator_type::pointer pointer;
35 typedef typename allocator_type::const_pointer const_pointer;
36 typedef typename allocator_type::size_type size_type;
37 typedef typename allocator_type::difference_type difference_type;
38
39 typedef implementation-defined iterator;
40 typedef implementation-defined const_iterator;
41 typedef std::reverse_iterator<iterator> reverse_iterator;
42 typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
43
44 class value_compare
45 : public binary_function<value_type, value_type, bool>
46 {
47 friend class map;
48 protected:
49 key_compare comp;
50
51 value_compare(key_compare c);
52 public:
53 bool operator()(const value_type& x, const value_type& y) const;
54 };
55
56 // construct/copy/destroy:
Howard Hinnant7686add2011-06-04 14:31:5757 map()
58 noexcept(
59 is_nothrow_default_constructible<allocator_type>::value &&
60 is_nothrow_default_constructible<key_compare>::value &&
61 is_nothrow_copy_constructible<key_compare>::value);
Howard Hinnantbc8d3f92010-05-11 19:42:1662 explicit map(const key_compare& comp);
63 map(const key_compare& comp, const allocator_type& a);
64 template <class InputIterator>
65 map(InputIterator first, InputIterator last,
66 const key_compare& comp = key_compare());
67 template <class InputIterator>
68 map(InputIterator first, InputIterator last,
69 const key_compare& comp, const allocator_type& a);
70 map(const map& m);
Howard Hinnant7686add2011-06-04 14:31:5771 map(map&& m)
72 noexcept(
73 is_nothrow_move_constructible<allocator_type>::value &&
74 is_nothrow_move_constructible<key_compare>::value);
Howard Hinnantbc8d3f92010-05-11 19:42:1675 explicit map(const allocator_type& a);
76 map(const map& m, const allocator_type& a);
77 map(map&& m, const allocator_type& a);
78 map(initializer_list<value_type> il, const key_compare& comp = key_compare());
79 map(initializer_list<value_type> il, const key_compare& comp, const allocator_type& a);
Marshall Clow49d596d2013-09-11 01:15:4780 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 Hinnantbc8d3f92010-05-11 19:42:1686
87 map& operator=(const map& m);
Howard Hinnant7686add2011-06-04 14:31:5788 map& operator=(map&& m)
89 noexcept(
90 allocator_type::propagate_on_container_move_assignment::value &&
91 is_nothrow_move_assignable<allocator_type>::value &&
Howard Hinnantb2e2a8f2011-06-04 15:22:3492 is_nothrow_move_assignable<key_compare>::value);
Howard Hinnantbc8d3f92010-05-11 19:42:1693 map& operator=(initializer_list<value_type> il);
94
95 // iterators:
Howard Hinnantb2e2a8f2011-06-04 15:22:3496 iterator begin() noexcept;
97 const_iterator begin() const noexcept;
98 iterator end() noexcept;
99 const_iterator end() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16100
Howard Hinnantb2e2a8f2011-06-04 15:22:34101 reverse_iterator rbegin() noexcept;
102 const_reverse_iterator rbegin() const noexcept;
103 reverse_iterator rend() noexcept;
104 const_reverse_iterator rend() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16105
Howard Hinnantb2e2a8f2011-06-04 15:22:34106 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 Hinnantbc8d3f92010-05-11 19:42:16110
111 // capacity:
Howard Hinnantb2e2a8f2011-06-04 15:22:34112 bool empty() const noexcept;
113 size_type size() const noexcept;
114 size_type max_size() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16115
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);
Marshall Clow3426a862016-01-05 19:32:41129 pair<iterator, bool> insert( value_type&& v); // C++17
Howard Hinnantbc8d3f92010-05-11 19:42:16130 template <class P>
131 pair<iterator, bool> insert(P&& p);
132 iterator insert(const_iterator position, const value_type& v);
Marshall Clow3426a862016-01-05 19:32:41133 iterator insert(const_iterator position, value_type&& v); // C++17
Howard Hinnantbc8d3f92010-05-11 19:42:16134 template <class P>
135 iterator insert(const_iterator position, P&& p);
136 template <class InputIterator>
137 void insert(InputIterator first, InputIterator last);
138 void insert(initializer_list<value_type> il);
139
Marshall Clowf3a1a182015-07-07 03:37:33140 template <class... Args>
141 pair<iterator, bool> try_emplace(const key_type& k, Args&&... args); // C++17
142 template <class... Args>
143 pair<iterator, bool> try_emplace(key_type&& k, Args&&... args); // C++17
144 template <class... Args>
145 iterator try_emplace(const_iterator hint, const key_type& k, Args&&... args); // C++17
146 template <class... Args>
147 iterator try_emplace(const_iterator hint, key_type&& k, Args&&... args); // C++17
148 template <class M>
149 pair<iterator, bool> insert_or_assign(const key_type& k, M&& obj); // C++17
150 template <class M>
151 pair<iterator, bool> insert_or_assign(key_type&& k, M&& obj); // C++17
152 template <class M>
153 iterator insert_or_assign(const_iterator hint, const key_type& k, M&& obj); // C++17
154 template <class M>
155 iterator insert_or_assign(const_iterator hint, key_type&& k, M&& obj); // C++17
156
Howard Hinnantbc8d3f92010-05-11 19:42:16157 iterator erase(const_iterator position);
Marshall Clow488025c2015-05-10 13:35:00158 iterator erase(iterator position); // C++14
Howard Hinnantbc8d3f92010-05-11 19:42:16159 size_type erase(const key_type& k);
160 iterator erase(const_iterator first, const_iterator last);
Howard Hinnantb2e2a8f2011-06-04 15:22:34161 void clear() noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16162
Howard Hinnant7686add2011-06-04 14:31:57163 void swap(map& m)
Marshall Clow7d914d12015-07-13 20:04:56164 noexcept(allocator_traits<allocator_type>::is_always_equal::value &&
165 __is_nothrow_swappable<key_compare>::value); // C++17
Howard Hinnantbc8d3f92010-05-11 19:42:16166
167 // observers:
Howard Hinnantb2e2a8f2011-06-04 15:22:34168 allocator_type get_allocator() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16169 key_compare key_comp() const;
170 value_compare value_comp() const;
171
172 // map operations:
173 iterator find(const key_type& k);
174 const_iterator find(const key_type& k) const;
Marshall Clow5cfc6ab2013-08-13 22:18:47175 template<typename K>
176 iterator find(const K& x); // C++14
177 template<typename K>
178 const_iterator find(const K& x) const; // C++14
179 template<typename K>
Marshall Clow4de32042014-08-24 23:54:16180 size_type count(const K& x) const; // C++14
Marshall Clow5cfc6ab2013-08-13 22:18:47181
Howard Hinnantbc8d3f92010-05-11 19:42:16182 size_type count(const key_type& k) const;
183 iterator lower_bound(const key_type& k);
184 const_iterator lower_bound(const key_type& k) const;
Marshall Clow5cfc6ab2013-08-13 22:18:47185 template<typename K>
186 iterator lower_bound(const K& x); // C++14
187 template<typename K>
188 const_iterator lower_bound(const K& x) const; // C++14
189
Howard Hinnantbc8d3f92010-05-11 19:42:16190 iterator upper_bound(const key_type& k);
191 const_iterator upper_bound(const key_type& k) const;
Marshall Clow5cfc6ab2013-08-13 22:18:47192 template<typename K>
193 iterator upper_bound(const K& x); // C++14
194 template<typename K>
195 const_iterator upper_bound(const K& x) const; // C++14
196
Howard Hinnantbc8d3f92010-05-11 19:42:16197 pair<iterator,iterator> equal_range(const key_type& k);
198 pair<const_iterator,const_iterator> equal_range(const key_type& k) const;
Marshall Clow5cfc6ab2013-08-13 22:18:47199 template<typename K>
200 pair<iterator,iterator> equal_range(const K& x); // C++14
201 template<typename K>
202 pair<const_iterator,const_iterator> equal_range(const K& x) const; // C++14
Howard Hinnantbc8d3f92010-05-11 19:42:16203};
204
205template <class Key, class T, class Compare, class Allocator>
206bool
207operator==(const map<Key, T, Compare, Allocator>& x,
208 const map<Key, T, Compare, Allocator>& y);
209
210template <class Key, class T, class Compare, class Allocator>
211bool
212operator< (const map<Key, T, Compare, Allocator>& x,
213 const map<Key, T, Compare, Allocator>& y);
214
215template <class Key, class T, class Compare, class Allocator>
216bool
217operator!=(const map<Key, T, Compare, Allocator>& x,
218 const map<Key, T, Compare, Allocator>& y);
219
220template <class Key, class T, class Compare, class Allocator>
221bool
222operator> (const map<Key, T, Compare, Allocator>& x,
223 const map<Key, T, Compare, Allocator>& y);
224
225template <class Key, class T, class Compare, class Allocator>
226bool
227operator>=(const map<Key, T, Compare, Allocator>& x,
228 const map<Key, T, Compare, Allocator>& y);
229
230template <class Key, class T, class Compare, class Allocator>
231bool
232operator<=(const map<Key, T, Compare, Allocator>& x,
233 const map<Key, T, Compare, Allocator>& y);
234
235// specialized algorithms:
236template <class Key, class T, class Compare, class Allocator>
237void
Howard Hinnant7686add2011-06-04 14:31:57238swap(map<Key, T, Compare, Allocator>& x, map<Key, T, Compare, Allocator>& y)
239 noexcept(noexcept(x.swap(y)));
Howard Hinnantbc8d3f92010-05-11 19:42:16240
241template <class Key, class T, class Compare = less<Key>,
242 class Allocator = allocator<pair<const Key, T>>>
243class multimap
244{
245public:
246 // types:
247 typedef Key key_type;
248 typedef T mapped_type;
249 typedef pair<const key_type,mapped_type> value_type;
250 typedef Compare key_compare;
251 typedef Allocator allocator_type;
252 typedef typename allocator_type::reference reference;
253 typedef typename allocator_type::const_reference const_reference;
254 typedef typename allocator_type::size_type size_type;
255 typedef typename allocator_type::difference_type difference_type;
256 typedef typename allocator_type::pointer pointer;
257 typedef typename allocator_type::const_pointer const_pointer;
258
259 typedef implementation-defined iterator;
260 typedef implementation-defined const_iterator;
261 typedef std::reverse_iterator<iterator> reverse_iterator;
262 typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
263
264 class value_compare
265 : public binary_function<value_type,value_type,bool>
266 {
267 friend class multimap;
268 protected:
269 key_compare comp;
270 value_compare(key_compare c);
271 public:
272 bool operator()(const value_type& x, const value_type& y) const;
273 };
274
275 // construct/copy/destroy:
Howard Hinnant7686add2011-06-04 14:31:57276 multimap()
277 noexcept(
278 is_nothrow_default_constructible<allocator_type>::value &&
279 is_nothrow_default_constructible<key_compare>::value &&
280 is_nothrow_copy_constructible<key_compare>::value);
281 explicit multimap(const key_compare& comp);
Howard Hinnantbc8d3f92010-05-11 19:42:16282 multimap(const key_compare& comp, const allocator_type& a);
283 template <class InputIterator>
284 multimap(InputIterator first, InputIterator last, const key_compare& comp);
285 template <class InputIterator>
286 multimap(InputIterator first, InputIterator last, const key_compare& comp,
287 const allocator_type& a);
288 multimap(const multimap& m);
Howard Hinnant7686add2011-06-04 14:31:57289 multimap(multimap&& m)
290 noexcept(
291 is_nothrow_move_constructible<allocator_type>::value &&
292 is_nothrow_move_constructible<key_compare>::value);
Howard Hinnantbc8d3f92010-05-11 19:42:16293 explicit multimap(const allocator_type& a);
294 multimap(const multimap& m, const allocator_type& a);
295 multimap(multimap&& m, const allocator_type& a);
296 multimap(initializer_list<value_type> il, const key_compare& comp = key_compare());
297 multimap(initializer_list<value_type> il, const key_compare& comp,
298 const allocator_type& a);
Marshall Clow49d596d2013-09-11 01:15:47299 template <class InputIterator>
300 multimap(InputIterator first, InputIterator last, const allocator_type& a)
301 : multimap(first, last, Compare(), a) {} // C++14
302 multimap(initializer_list<value_type> il, const allocator_type& a)
303 : multimap(il, Compare(), a) {} // C++14
Howard Hinnantbc8d3f92010-05-11 19:42:16304 ~multimap();
305
306 multimap& operator=(const multimap& m);
Howard Hinnant7686add2011-06-04 14:31:57307 multimap& operator=(multimap&& m)
308 noexcept(
309 allocator_type::propagate_on_container_move_assignment::value &&
310 is_nothrow_move_assignable<allocator_type>::value &&
Howard Hinnantb2e2a8f2011-06-04 15:22:34311 is_nothrow_move_assignable<key_compare>::value);
Howard Hinnantbc8d3f92010-05-11 19:42:16312 multimap& operator=(initializer_list<value_type> il);
313
314 // iterators:
Howard Hinnantb2e2a8f2011-06-04 15:22:34315 iterator begin() noexcept;
316 const_iterator begin() const noexcept;
317 iterator end() noexcept;
318 const_iterator end() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16319
Howard Hinnantb2e2a8f2011-06-04 15:22:34320 reverse_iterator rbegin() noexcept;
321 const_reverse_iterator rbegin() const noexcept;
322 reverse_iterator rend() noexcept;
323 const_reverse_iterator rend() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16324
Howard Hinnantb2e2a8f2011-06-04 15:22:34325 const_iterator cbegin() const noexcept;
326 const_iterator cend() const noexcept;
327 const_reverse_iterator crbegin() const noexcept;
328 const_reverse_iterator crend() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16329
330 // capacity:
Howard Hinnantb2e2a8f2011-06-04 15:22:34331 bool empty() const noexcept;
332 size_type size() const noexcept;
333 size_type max_size() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16334
335 // modifiers:
336 template <class... Args>
337 iterator emplace(Args&&... args);
338 template <class... Args>
339 iterator emplace_hint(const_iterator position, Args&&... args);
340 iterator insert(const value_type& v);
Marshall Clow3426a862016-01-05 19:32:41341 iterator insert( value_type&& v); // C++17
Howard Hinnantbc8d3f92010-05-11 19:42:16342 template <class P>
343 iterator insert(P&& p);
344 iterator insert(const_iterator position, const value_type& v);
Marshall Clow3426a862016-01-05 19:32:41345 iterator insert(const_iterator position, value_type&& v); // C++17
Howard Hinnantbc8d3f92010-05-11 19:42:16346 template <class P>
347 iterator insert(const_iterator position, P&& p);
348 template <class InputIterator>
349 void insert(InputIterator first, InputIterator last);
350 void insert(initializer_list<value_type> il);
351
352 iterator erase(const_iterator position);
Marshall Clow488025c2015-05-10 13:35:00353 iterator erase(iterator position); // C++14
Howard Hinnantbc8d3f92010-05-11 19:42:16354 size_type erase(const key_type& k);
355 iterator erase(const_iterator first, const_iterator last);
Howard Hinnantb2e2a8f2011-06-04 15:22:34356 void clear() noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16357
Howard Hinnant7686add2011-06-04 14:31:57358 void swap(multimap& m)
Marshall Clow7d914d12015-07-13 20:04:56359 noexcept(allocator_traits<allocator_type>::is_always_equal::value &&
360 __is_nothrow_swappable<key_compare>::value); // C++17
Howard Hinnantbc8d3f92010-05-11 19:42:16361
362 // observers:
Howard Hinnantb2e2a8f2011-06-04 15:22:34363 allocator_type get_allocator() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16364 key_compare key_comp() const;
365 value_compare value_comp() const;
366
367 // map operations:
368 iterator find(const key_type& k);
369 const_iterator find(const key_type& k) const;
Marshall Clow5cfc6ab2013-08-13 22:18:47370 template<typename K>
371 iterator find(const K& x); // C++14
372 template<typename K>
373 const_iterator find(const K& x) const; // C++14
374 template<typename K>
Marshall Clow4de32042014-08-24 23:54:16375 size_type count(const K& x) const; // C++14
Marshall Clow5cfc6ab2013-08-13 22:18:47376
Howard Hinnantbc8d3f92010-05-11 19:42:16377 size_type count(const key_type& k) const;
378 iterator lower_bound(const key_type& k);
379 const_iterator lower_bound(const key_type& k) const;
Marshall Clow5cfc6ab2013-08-13 22:18:47380 template<typename K>
381 iterator lower_bound(const K& x); // C++14
382 template<typename K>
383 const_iterator lower_bound(const K& x) const; // C++14
384
Howard Hinnantbc8d3f92010-05-11 19:42:16385 iterator upper_bound(const key_type& k);
386 const_iterator upper_bound(const key_type& k) const;
Marshall Clow5cfc6ab2013-08-13 22:18:47387 template<typename K>
388 iterator upper_bound(const K& x); // C++14
389 template<typename K>
390 const_iterator upper_bound(const K& x) const; // C++14
391
Howard Hinnantbc8d3f92010-05-11 19:42:16392 pair<iterator,iterator> equal_range(const key_type& k);
393 pair<const_iterator,const_iterator> equal_range(const key_type& k) const;
Marshall Clow5cfc6ab2013-08-13 22:18:47394 template<typename K>
395 pair<iterator,iterator> equal_range(const K& x); // C++14
396 template<typename K>
397 pair<const_iterator,const_iterator> equal_range(const K& x) const; // C++14
Howard Hinnantbc8d3f92010-05-11 19:42:16398};
399
400template <class Key, class T, class Compare, class Allocator>
401bool
402operator==(const multimap<Key, T, Compare, Allocator>& x,
403 const multimap<Key, T, Compare, Allocator>& y);
404
405template <class Key, class T, class Compare, class Allocator>
406bool
407operator< (const multimap<Key, T, Compare, Allocator>& x,
408 const multimap<Key, T, Compare, Allocator>& y);
409
410template <class Key, class T, class Compare, class Allocator>
411bool
412operator!=(const multimap<Key, T, Compare, Allocator>& x,
413 const multimap<Key, T, Compare, Allocator>& y);
414
415template <class Key, class T, class Compare, class Allocator>
416bool
417operator> (const multimap<Key, T, Compare, Allocator>& x,
418 const multimap<Key, T, Compare, Allocator>& y);
419
420template <class Key, class T, class Compare, class Allocator>
421bool
422operator>=(const multimap<Key, T, Compare, Allocator>& x,
423 const multimap<Key, T, Compare, Allocator>& y);
424
425template <class Key, class T, class Compare, class Allocator>
426bool
427operator<=(const multimap<Key, T, Compare, Allocator>& x,
428 const multimap<Key, T, Compare, Allocator>& y);
429
430// specialized algorithms:
431template <class Key, class T, class Compare, class Allocator>
432void
433swap(multimap<Key, T, Compare, Allocator>& x,
Howard Hinnant7686add2011-06-04 14:31:57434 multimap<Key, T, Compare, Allocator>& y)
435 noexcept(noexcept(x.swap(y)));
Howard Hinnantbc8d3f92010-05-11 19:42:16436
437} // std
438
439*/
440
441#include <__config>
442#include <__tree>
443#include <iterator>
444#include <memory>
445#include <utility>
446#include <functional>
447#include <initializer_list>
Eric Fiselier3a0e4302015-06-13 07:08:02448#include <type_traits>
Howard Hinnantbc8d3f92010-05-11 19:42:16449
Howard Hinnant08e17472011-10-17 20:05:10450#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Howard Hinnantbc8d3f92010-05-11 19:42:16451#pragma GCC system_header
Howard Hinnant08e17472011-10-17 20:05:10452#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16453
454_LIBCPP_BEGIN_NAMESPACE_STD
455
Eric Fiselier3a0e4302015-06-13 07:08:02456template <class _Key, class _CP, class _Compare,
457 bool = is_empty<_Compare>::value && !__libcpp_is_final<_Compare>::value
Howard Hinnantd4cf2152011-12-11 20:31:33458 >
Howard Hinnantbc8d3f92010-05-11 19:42:16459class __map_value_compare
460 : private _Compare
461{
Howard Hinnantbc8d3f92010-05-11 19:42:16462public:
Howard Hinnant82894812010-09-22 16:48:34463 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7686add2011-06-04 14:31:57464 __map_value_compare()
465 _NOEXCEPT_(is_nothrow_default_constructible<_Compare>::value)
466 : _Compare() {}
Howard Hinnant82894812010-09-22 16:48:34467 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7686add2011-06-04 14:31:57468 __map_value_compare(_Compare c)
469 _NOEXCEPT_(is_nothrow_copy_constructible<_Compare>::value)
470 : _Compare(c) {}
Howard Hinnant82894812010-09-22 16:48:34471 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7686add2011-06-04 14:31:57472 const _Compare& key_comp() const _NOEXCEPT {return *this;}
Howard Hinnant82894812010-09-22 16:48:34473 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16474 bool operator()(const _CP& __x, const _CP& __y) const
Howard Hinnant9b128e02013-07-05 18:06:00475 {return static_cast<const _Compare&>(*this)(__x.__cc.first, __y.__cc.first);}
Howard Hinnant82894812010-09-22 16:48:34476 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16477 bool operator()(const _CP& __x, const _Key& __y) const
Howard Hinnant9b128e02013-07-05 18:06:00478 {return static_cast<const _Compare&>(*this)(__x.__cc.first, __y);}
Howard Hinnant82894812010-09-22 16:48:34479 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16480 bool operator()(const _Key& __x, const _CP& __y) const
Howard Hinnant9b128e02013-07-05 18:06:00481 {return static_cast<const _Compare&>(*this)(__x, __y.__cc.first);}
Marshall Clow7d914d12015-07-13 20:04:56482 void swap(__map_value_compare&__y)
483 _NOEXCEPT_(__is_nothrow_swappable<_Compare>::value)
484 {
485 using _VSTD::swap;
486 swap(static_cast<const _Compare&>(*this), static_cast<const _Compare&>(__y));
487 }
Marshall Clow5cfc6ab2013-08-13 22:18:47488
489#if _LIBCPP_STD_VER > 11
490 template <typename _K2>
491 _LIBCPP_INLINE_VISIBILITY
492 typename enable_if<__is_transparent<_Compare, _K2>::value, bool>::type
493 operator () ( const _K2& __x, const _CP& __y ) const
494 {return static_cast<const _Compare&>(*this) (__x, __y.__cc.first);}
495
496 template <typename _K2>
497 _LIBCPP_INLINE_VISIBILITY
498 typename enable_if<__is_transparent<_Compare, _K2>::value, bool>::type
499 operator () (const _CP& __x, const _K2& __y) const
500 {return static_cast<const _Compare&>(*this) (__x.__cc.first, __y);}
501#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16502};
503
Howard Hinnant9b128e02013-07-05 18:06:00504template <class _Key, class _CP, class _Compare>
505class __map_value_compare<_Key, _CP, _Compare, false>
Howard Hinnantbc8d3f92010-05-11 19:42:16506{
507 _Compare comp;
508
Howard Hinnantbc8d3f92010-05-11 19:42:16509public:
Howard Hinnant82894812010-09-22 16:48:34510 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7686add2011-06-04 14:31:57511 __map_value_compare()
512 _NOEXCEPT_(is_nothrow_default_constructible<_Compare>::value)
513 : comp() {}
Howard Hinnant82894812010-09-22 16:48:34514 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7686add2011-06-04 14:31:57515 __map_value_compare(_Compare c)
516 _NOEXCEPT_(is_nothrow_copy_constructible<_Compare>::value)
517 : comp(c) {}
Howard Hinnant82894812010-09-22 16:48:34518 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7686add2011-06-04 14:31:57519 const _Compare& key_comp() const _NOEXCEPT {return comp;}
Howard Hinnantbc8d3f92010-05-11 19:42:16520
Howard Hinnant82894812010-09-22 16:48:34521 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16522 bool operator()(const _CP& __x, const _CP& __y) const
Howard Hinnant9b128e02013-07-05 18:06:00523 {return comp(__x.__cc.first, __y.__cc.first);}
Howard Hinnant82894812010-09-22 16:48:34524 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16525 bool operator()(const _CP& __x, const _Key& __y) const
Howard Hinnant9b128e02013-07-05 18:06:00526 {return comp(__x.__cc.first, __y);}
Howard Hinnant82894812010-09-22 16:48:34527 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16528 bool operator()(const _Key& __x, const _CP& __y) const
Howard Hinnant9b128e02013-07-05 18:06:00529 {return comp(__x, __y.__cc.first);}
Marshall Clow7d914d12015-07-13 20:04:56530 void swap(__map_value_compare&__y)
531 _NOEXCEPT_(__is_nothrow_swappable<_Compare>::value)
532 {
533 using _VSTD::swap;
534 swap(comp, __y.comp);
535 }
536
Marshall Clow5cfc6ab2013-08-13 22:18:47537#if _LIBCPP_STD_VER > 11
538 template <typename _K2>
539 _LIBCPP_INLINE_VISIBILITY
540 typename enable_if<__is_transparent<_Compare, _K2>::value, bool>::type
541 operator () ( const _K2& __x, const _CP& __y ) const
542 {return comp (__x, __y.__cc.first);}
543
544 template <typename _K2>
545 _LIBCPP_INLINE_VISIBILITY
546 typename enable_if<__is_transparent<_Compare, _K2>::value, bool>::type
547 operator () (const _CP& __x, const _K2& __y) const
548 {return comp (__x.__cc.first, __y);}
549#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16550};
551
Marshall Clow7d914d12015-07-13 20:04:56552template <class _Key, class _CP, class _Compare, bool __b>
553inline _LIBCPP_INLINE_VISIBILITY
554void
555swap(__map_value_compare<_Key, _CP, _Compare, __b>& __x,
556 __map_value_compare<_Key, _CP, _Compare, __b>& __y)
557 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
558{
559 __x.swap(__y);
560}
561
Howard Hinnantbc8d3f92010-05-11 19:42:16562template <class _Allocator>
563class __map_node_destructor
564{
565 typedef _Allocator allocator_type;
566 typedef allocator_traits<allocator_type> __alloc_traits;
Eric Fiselier55263482016-02-20 05:28:30567
Howard Hinnantbc8d3f92010-05-11 19:42:16568public:
569 typedef typename __alloc_traits::pointer pointer;
Howard Hinnantbc8d3f92010-05-11 19:42:16570
Eric Fiselier55263482016-02-20 05:28:30571private:
Howard Hinnantbc8d3f92010-05-11 19:42:16572 allocator_type& __na_;
573
574 __map_node_destructor& operator=(const __map_node_destructor&);
575
576public:
577 bool __first_constructed;
578 bool __second_constructed;
579
Howard Hinnant82894812010-09-22 16:48:34580 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7686add2011-06-04 14:31:57581 explicit __map_node_destructor(allocator_type& __na) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16582 : __na_(__na),
583 __first_constructed(false),
584 __second_constructed(false)
585 {}
586
Howard Hinnant73d21a42010-09-04 23:28:19587#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant82894812010-09-22 16:48:34588 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7686add2011-06-04 14:31:57589 __map_node_destructor(__tree_node_destructor<allocator_type>&& __x) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16590 : __na_(__x.__na_),
591 __first_constructed(__x.__value_constructed),
592 __second_constructed(__x.__value_constructed)
593 {
594 __x.__value_constructed = false;
595 }
Howard Hinnantbfd55302010-09-04 23:46:48596#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16597
Howard Hinnant82894812010-09-22 16:48:34598 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7686add2011-06-04 14:31:57599 void operator()(pointer __p) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16600 {
601 if (__second_constructed)
Howard Hinnant70342b92013-06-19 21:29:40602 __alloc_traits::destroy(__na_, _VSTD::addressof(__p->__value_.__cc.second));
Howard Hinnantbc8d3f92010-05-11 19:42:16603 if (__first_constructed)
Howard Hinnant70342b92013-06-19 21:29:40604 __alloc_traits::destroy(__na_, _VSTD::addressof(__p->__value_.__cc.first));
Howard Hinnantbc8d3f92010-05-11 19:42:16605 if (__p)
606 __alloc_traits::deallocate(__na_, __p, 1);
607 }
608};
609
Howard Hinnant2b1b2d42011-06-14 19:58:17610template <class _Key, class _Tp, class _Compare, class _Allocator>
611 class map;
612template <class _Key, class _Tp, class _Compare, class _Allocator>
613 class multimap;
614template <class _TreeIterator> class __map_const_iterator;
Howard Hinnantbc8d3f92010-05-11 19:42:16615
Eric Fiselier55263482016-02-20 05:28:30616#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantff7546e2013-09-30 19:08:22617
618template <class _Key, class _Tp>
619union __value_type
620{
621 typedef _Key key_type;
622 typedef _Tp mapped_type;
623 typedef pair<const key_type, mapped_type> value_type;
624 typedef pair<key_type, mapped_type> __nc_value_type;
625
626 value_type __cc;
627 __nc_value_type __nc;
628
629 template <class ..._Args>
630 _LIBCPP_INLINE_VISIBILITY
631 __value_type(_Args&& ...__args)
632 : __cc(std::forward<_Args>(__args)...) {}
633
634 _LIBCPP_INLINE_VISIBILITY
635 __value_type(const __value_type& __v)
636 : __cc(__v.__cc) {}
637
638 _LIBCPP_INLINE_VISIBILITY
639 __value_type(__value_type& __v)
640 : __cc(__v.__cc) {}
641
642 _LIBCPP_INLINE_VISIBILITY
643 __value_type(__value_type&& __v)
644 : __nc(std::move(__v.__nc)) {}
645
646 _LIBCPP_INLINE_VISIBILITY
647 __value_type& operator=(const __value_type& __v)
648 {__nc = __v.__cc; return *this;}
649
650 _LIBCPP_INLINE_VISIBILITY
651 __value_type& operator=(__value_type&& __v)
652 {__nc = std::move(__v.__nc); return *this;}
653
654 _LIBCPP_INLINE_VISIBILITY
655 ~__value_type() {__cc.~value_type();}
656};
657
658#else
659
660template <class _Key, class _Tp>
661struct __value_type
662{
663 typedef _Key key_type;
664 typedef _Tp mapped_type;
665 typedef pair<const key_type, mapped_type> value_type;
666
667 value_type __cc;
668
669 _LIBCPP_INLINE_VISIBILITY
670 __value_type() {}
671
672 template <class _A0>
673 _LIBCPP_INLINE_VISIBILITY
674 __value_type(const _A0& __a0)
675 : __cc(__a0) {}
676
677 template <class _A0, class _A1>
678 _LIBCPP_INLINE_VISIBILITY
679 __value_type(const _A0& __a0, const _A1& __a1)
680 : __cc(__a0, __a1) {}
681};
682
683#endif
684
Eric Fiselier9c8e6632015-03-03 20:10:01685template <class _Tp>
686struct __extract_key_value_types;
687
688template <class _Key, class _Tp>
689struct __extract_key_value_types<__value_type<_Key, _Tp> >
690{
691 typedef _Key const __key_type;
692 typedef _Tp __mapped_type;
693};
694
Howard Hinnantbc8d3f92010-05-11 19:42:16695template <class _TreeIterator>
Howard Hinnant0f678bd2013-08-12 18:38:34696class _LIBCPP_TYPE_VIS_ONLY __map_iterator
Howard Hinnantbc8d3f92010-05-11 19:42:16697{
Eric Fiselier55263482016-02-20 05:28:30698 typedef typename _TreeIterator::_NodeTypes _NodeTypes;
699 typedef typename _TreeIterator::__pointer_traits __pointer_traits;
700
Howard Hinnantbc8d3f92010-05-11 19:42:16701 _TreeIterator __i_;
702
Howard Hinnantbc8d3f92010-05-11 19:42:16703public:
704 typedef bidirectional_iterator_tag iterator_category;
Eric Fiselier55263482016-02-20 05:28:30705 typedef typename _NodeTypes::__map_value_type value_type;
Howard Hinnantbc8d3f92010-05-11 19:42:16706 typedef typename _TreeIterator::difference_type difference_type;
707 typedef value_type& reference;
Eric Fiselier55263482016-02-20 05:28:30708 typedef typename _NodeTypes::__map_value_type_pointer pointer;
Howard Hinnantbc8d3f92010-05-11 19:42:16709
Howard Hinnant82894812010-09-22 16:48:34710 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7686add2011-06-04 14:31:57711 __map_iterator() _NOEXCEPT {}
Howard Hinnantbc8d3f92010-05-11 19:42:16712
Howard Hinnant82894812010-09-22 16:48:34713 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7686add2011-06-04 14:31:57714 __map_iterator(_TreeIterator __i) _NOEXCEPT : __i_(__i) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16715
Howard Hinnant82894812010-09-22 16:48:34716 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant70342b92013-06-19 21:29:40717 reference operator*() const {return __i_->__cc;}
Howard Hinnant82894812010-09-22 16:48:34718 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant70342b92013-06-19 21:29:40719 pointer operator->() const {return pointer_traits<pointer>::pointer_to(__i_->__cc);}
Howard Hinnantbc8d3f92010-05-11 19:42:16720
Howard Hinnant82894812010-09-22 16:48:34721 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16722 __map_iterator& operator++() {++__i_; return *this;}
Howard Hinnant82894812010-09-22 16:48:34723 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16724 __map_iterator operator++(int)
725 {
726 __map_iterator __t(*this);
727 ++(*this);
728 return __t;
729 }
730
Howard Hinnant82894812010-09-22 16:48:34731 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16732 __map_iterator& operator--() {--__i_; return *this;}
Howard Hinnant82894812010-09-22 16:48:34733 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16734 __map_iterator operator--(int)
735 {
736 __map_iterator __t(*this);
737 --(*this);
738 return __t;
739 }
740
Howard Hinnant82894812010-09-22 16:48:34741 friend _LIBCPP_INLINE_VISIBILITY
742 bool operator==(const __map_iterator& __x, const __map_iterator& __y)
Howard Hinnantbc8d3f92010-05-11 19:42:16743 {return __x.__i_ == __y.__i_;}
Howard Hinnant82894812010-09-22 16:48:34744 friend
745 _LIBCPP_INLINE_VISIBILITY
746 bool operator!=(const __map_iterator& __x, const __map_iterator& __y)
Howard Hinnantbc8d3f92010-05-11 19:42:16747 {return __x.__i_ != __y.__i_;}
748
Howard Hinnant0f678bd2013-08-12 18:38:34749 template <class, class, class, class> friend class _LIBCPP_TYPE_VIS_ONLY map;
750 template <class, class, class, class> friend class _LIBCPP_TYPE_VIS_ONLY multimap;
751 template <class> friend class _LIBCPP_TYPE_VIS_ONLY __map_const_iterator;
Howard Hinnantbc8d3f92010-05-11 19:42:16752};
753
754template <class _TreeIterator>
Howard Hinnant0f678bd2013-08-12 18:38:34755class _LIBCPP_TYPE_VIS_ONLY __map_const_iterator
Howard Hinnantbc8d3f92010-05-11 19:42:16756{
Eric Fiselier55263482016-02-20 05:28:30757 typedef typename _TreeIterator::_NodeTypes _NodeTypes;
758 typedef typename _TreeIterator::__pointer_traits __pointer_traits;
759
Howard Hinnantbc8d3f92010-05-11 19:42:16760 _TreeIterator __i_;
761
Howard Hinnantbc8d3f92010-05-11 19:42:16762public:
763 typedef bidirectional_iterator_tag iterator_category;
Eric Fiselier55263482016-02-20 05:28:30764 typedef typename _NodeTypes::__map_value_type value_type;
Howard Hinnantbc8d3f92010-05-11 19:42:16765 typedef typename _TreeIterator::difference_type difference_type;
766 typedef const value_type& reference;
Eric Fiselier55263482016-02-20 05:28:30767 typedef typename _NodeTypes::__const_map_value_type_pointer pointer;
Howard Hinnantbc8d3f92010-05-11 19:42:16768
Howard Hinnant82894812010-09-22 16:48:34769 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7686add2011-06-04 14:31:57770 __map_const_iterator() _NOEXCEPT {}
Howard Hinnantbc8d3f92010-05-11 19:42:16771
Howard Hinnant82894812010-09-22 16:48:34772 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7686add2011-06-04 14:31:57773 __map_const_iterator(_TreeIterator __i) _NOEXCEPT : __i_(__i) {}
Howard Hinnant82894812010-09-22 16:48:34774 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier9c8e6632015-03-03 20:10:01775 __map_const_iterator(__map_iterator<
776 typename _TreeIterator::__non_const_iterator> __i) _NOEXCEPT
777 : __i_(__i.__i_) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16778
Howard Hinnant82894812010-09-22 16:48:34779 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant70342b92013-06-19 21:29:40780 reference operator*() const {return __i_->__cc;}
Howard Hinnant82894812010-09-22 16:48:34781 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant70342b92013-06-19 21:29:40782 pointer operator->() const {return pointer_traits<pointer>::pointer_to(__i_->__cc);}
Howard Hinnantbc8d3f92010-05-11 19:42:16783
Howard Hinnant82894812010-09-22 16:48:34784 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16785 __map_const_iterator& operator++() {++__i_; return *this;}
Howard Hinnant82894812010-09-22 16:48:34786 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16787 __map_const_iterator operator++(int)
788 {
789 __map_const_iterator __t(*this);
790 ++(*this);
791 return __t;
792 }
793
Howard Hinnant82894812010-09-22 16:48:34794 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16795 __map_const_iterator& operator--() {--__i_; return *this;}
Howard Hinnant82894812010-09-22 16:48:34796 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16797 __map_const_iterator operator--(int)
798 {
799 __map_const_iterator __t(*this);
800 --(*this);
801 return __t;
802 }
803
Howard Hinnant82894812010-09-22 16:48:34804 friend _LIBCPP_INLINE_VISIBILITY
805 bool operator==(const __map_const_iterator& __x, const __map_const_iterator& __y)
Howard Hinnantbc8d3f92010-05-11 19:42:16806 {return __x.__i_ == __y.__i_;}
Howard Hinnant82894812010-09-22 16:48:34807 friend _LIBCPP_INLINE_VISIBILITY
808 bool operator!=(const __map_const_iterator& __x, const __map_const_iterator& __y)
Howard Hinnantbc8d3f92010-05-11 19:42:16809 {return __x.__i_ != __y.__i_;}
810
Howard Hinnant0f678bd2013-08-12 18:38:34811 template <class, class, class, class> friend class _LIBCPP_TYPE_VIS_ONLY map;
812 template <class, class, class, class> friend class _LIBCPP_TYPE_VIS_ONLY multimap;
813 template <class, class, class> friend class _LIBCPP_TYPE_VIS_ONLY __tree_const_iterator;
Howard Hinnantbc8d3f92010-05-11 19:42:16814};
815
816template <class _Key, class _Tp, class _Compare = less<_Key>,
817 class _Allocator = allocator<pair<const _Key, _Tp> > >
Howard Hinnant0f678bd2013-08-12 18:38:34818class _LIBCPP_TYPE_VIS_ONLY map
Howard Hinnantbc8d3f92010-05-11 19:42:16819{
820public:
821 // types:
822 typedef _Key key_type;
823 typedef _Tp mapped_type;
824 typedef pair<const key_type, mapped_type> value_type;
Howard Hinnant70342b92013-06-19 21:29:40825 typedef pair<key_type, mapped_type> __nc_value_type;
Howard Hinnantbc8d3f92010-05-11 19:42:16826 typedef _Compare key_compare;
827 typedef _Allocator allocator_type;
828 typedef value_type& reference;
829 typedef const value_type& const_reference;
830
Marshall Clow14ba0ad2015-11-26 01:24:04831 static_assert((is_same<typename allocator_type::value_type, value_type>::value),
832 "Allocator::value_type must be same type as value_type");
833
Howard Hinnant0f678bd2013-08-12 18:38:34834 class _LIBCPP_TYPE_VIS_ONLY value_compare
Howard Hinnantbc8d3f92010-05-11 19:42:16835 : public binary_function<value_type, value_type, bool>
836 {
837 friend class map;
838 protected:
839 key_compare comp;
840
Howard Hinnant82894812010-09-22 16:48:34841 _LIBCPP_INLINE_VISIBILITY value_compare(key_compare c) : comp(c) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16842 public:
Howard Hinnant82894812010-09-22 16:48:34843 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16844 bool operator()(const value_type& __x, const value_type& __y) const
845 {return comp(__x.first, __y.first);}
846 };
847
848private:
Howard Hinnant70342b92013-06-19 21:29:40849
Howard Hinnantff7546e2013-09-30 19:08:22850 typedef _VSTD::__value_type<key_type, mapped_type> __value_type;
Howard Hinnant9b128e02013-07-05 18:06:00851 typedef __map_value_compare<key_type, __value_type, key_compare> __vc;
Marshall Clow66302c62015-04-07 05:21:38852 typedef typename __rebind_alloc_helper<allocator_traits<allocator_type>,
853 __value_type>::type __allocator_type;
Howard Hinnantbc8d3f92010-05-11 19:42:16854 typedef __tree<__value_type, __vc, __allocator_type> __base;
855 typedef typename __base::__node_traits __node_traits;
856 typedef allocator_traits<allocator_type> __alloc_traits;
857
858 __base __tree_;
859
860public:
861 typedef typename __alloc_traits::pointer pointer;
862 typedef typename __alloc_traits::const_pointer const_pointer;
863 typedef typename __alloc_traits::size_type size_type;
864 typedef typename __alloc_traits::difference_type difference_type;
Eric Fiselier9c8e6632015-03-03 20:10:01865 typedef __map_iterator<typename __base::iterator> iterator;
Howard Hinnantbc8d3f92010-05-11 19:42:16866 typedef __map_const_iterator<typename __base::const_iterator> const_iterator;
Howard Hinnant0949eed2011-06-30 21:18:19867 typedef _VSTD::reverse_iterator<iterator> reverse_iterator;
868 typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator;
Howard Hinnantbc8d3f92010-05-11 19:42:16869
Howard Hinnant82894812010-09-22 16:48:34870 _LIBCPP_INLINE_VISIBILITY
Marshall Clowcaaa1412014-03-10 04:50:10871 map()
872 _NOEXCEPT_(
873 is_nothrow_default_constructible<allocator_type>::value &&
874 is_nothrow_default_constructible<key_compare>::value &&
875 is_nothrow_copy_constructible<key_compare>::value)
876 : __tree_(__vc(key_compare())) {}
877
878 _LIBCPP_INLINE_VISIBILITY
879 explicit map(const key_compare& __comp)
Howard Hinnant7686add2011-06-04 14:31:57880 _NOEXCEPT_(
881 is_nothrow_default_constructible<allocator_type>::value &&
Howard Hinnant7686add2011-06-04 14:31:57882 is_nothrow_copy_constructible<key_compare>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16883 : __tree_(__vc(__comp)) {}
884
Howard Hinnant82894812010-09-22 16:48:34885 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16886 explicit map(const key_compare& __comp, const allocator_type& __a)
887 : __tree_(__vc(__comp), __a) {}
888
889 template <class _InputIterator>
Howard Hinnant82894812010-09-22 16:48:34890 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16891 map(_InputIterator __f, _InputIterator __l,
892 const key_compare& __comp = key_compare())
893 : __tree_(__vc(__comp))
894 {
895 insert(__f, __l);
896 }
897
898 template <class _InputIterator>
Howard Hinnant82894812010-09-22 16:48:34899 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16900 map(_InputIterator __f, _InputIterator __l,
901 const key_compare& __comp, const allocator_type& __a)
902 : __tree_(__vc(__comp), __a)
903 {
904 insert(__f, __l);
905 }
906
Marshall Clow49d596d2013-09-11 01:15:47907#if _LIBCPP_STD_VER > 11
908 template <class _InputIterator>
909 _LIBCPP_INLINE_VISIBILITY
910 map(_InputIterator __f, _InputIterator __l, const allocator_type& __a)
911 : map(__f, __l, key_compare(), __a) {}
912#endif
913
Howard Hinnant82894812010-09-22 16:48:34914 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16915 map(const map& __m)
916 : __tree_(__m.__tree_)
917 {
918 insert(__m.begin(), __m.end());
919 }
920
Howard Hinnant61aa6012011-07-01 19:24:36921 _LIBCPP_INLINE_VISIBILITY
922 map& operator=(const map& __m)
923 {
Howard Hinnant70342b92013-06-19 21:29:40924#if __cplusplus >= 201103L
Howard Hinnant61aa6012011-07-01 19:24:36925 __tree_ = __m.__tree_;
Howard Hinnant70342b92013-06-19 21:29:40926#else
Marshall Clowebfc50e2014-02-08 04:03:14927 if (this != &__m) {
928 __tree_.clear();
929 __tree_.value_comp() = __m.__tree_.value_comp();
930 __tree_.__copy_assign_alloc(__m.__tree_);
931 insert(__m.begin(), __m.end());
932 }
Howard Hinnant70342b92013-06-19 21:29:40933#endif
Howard Hinnant61aa6012011-07-01 19:24:36934 return *this;
935 }
936
Howard Hinnant73d21a42010-09-04 23:28:19937#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16938
Howard Hinnant82894812010-09-22 16:48:34939 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16940 map(map&& __m)
Howard Hinnant7686add2011-06-04 14:31:57941 _NOEXCEPT_(is_nothrow_move_constructible<__base>::value)
Howard Hinnant0949eed2011-06-30 21:18:19942 : __tree_(_VSTD::move(__m.__tree_))
Howard Hinnantbc8d3f92010-05-11 19:42:16943 {
944 }
945
946 map(map&& __m, const allocator_type& __a);
947
Howard Hinnant82894812010-09-22 16:48:34948 _LIBCPP_INLINE_VISIBILITY
Howard Hinnante3e32912011-08-12 21:56:02949 map& operator=(map&& __m)
950 _NOEXCEPT_(is_nothrow_move_assignable<__base>::value)
951 {
952 __tree_ = _VSTD::move(__m.__tree_);
953 return *this;
954 }
955
956#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
957
958#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
959
960 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16961 map(initializer_list<value_type> __il, const key_compare& __comp = key_compare())
962 : __tree_(__vc(__comp))
963 {
964 insert(__il.begin(), __il.end());
965 }
966
Howard Hinnant82894812010-09-22 16:48:34967 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16968 map(initializer_list<value_type> __il, const key_compare& __comp, const allocator_type& __a)
969 : __tree_(__vc(__comp), __a)
970 {
971 insert(__il.begin(), __il.end());
972 }
973
Marshall Clow49d596d2013-09-11 01:15:47974#if _LIBCPP_STD_VER > 11
975 _LIBCPP_INLINE_VISIBILITY
976 map(initializer_list<value_type> __il, const allocator_type& __a)
977 : map(__il, key_compare(), __a) {}
978#endif
979
Howard Hinnant82894812010-09-22 16:48:34980 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16981 map& operator=(initializer_list<value_type> __il)
982 {
983 __tree_.__assign_unique(__il.begin(), __il.end());
984 return *this;
985 }
986
Howard Hinnante3e32912011-08-12 21:56:02987#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16988
Howard Hinnant82894812010-09-22 16:48:34989 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16990 explicit map(const allocator_type& __a)
991 : __tree_(__a)
992 {
993 }
994
Howard Hinnant82894812010-09-22 16:48:34995 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16996 map(const map& __m, const allocator_type& __a)
997 : __tree_(__m.__tree_.value_comp(), __a)
998 {
999 insert(__m.begin(), __m.end());
1000 }
1001
Howard Hinnant82894812010-09-22 16:48:341002 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7686add2011-06-04 14:31:571003 iterator begin() _NOEXCEPT {return __tree_.begin();}
Howard Hinnant82894812010-09-22 16:48:341004 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7686add2011-06-04 14:31:571005 const_iterator begin() const _NOEXCEPT {return __tree_.begin();}
Howard Hinnant82894812010-09-22 16:48:341006 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7686add2011-06-04 14:31:571007 iterator end() _NOEXCEPT {return __tree_.end();}
Howard Hinnant82894812010-09-22 16:48:341008 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7686add2011-06-04 14:31:571009 const_iterator end() const _NOEXCEPT {return __tree_.end();}
Howard Hinnantbc8d3f92010-05-11 19:42:161010
Howard Hinnant82894812010-09-22 16:48:341011 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7686add2011-06-04 14:31:571012 reverse_iterator rbegin() _NOEXCEPT {return reverse_iterator(end());}
Howard Hinnant82894812010-09-22 16:48:341013 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7686add2011-06-04 14:31:571014 const_reverse_iterator rbegin() const _NOEXCEPT
1015 {return const_reverse_iterator(end());}
Howard Hinnant82894812010-09-22 16:48:341016 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7686add2011-06-04 14:31:571017 reverse_iterator rend() _NOEXCEPT
1018 {return reverse_iterator(begin());}
Howard Hinnant82894812010-09-22 16:48:341019 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7686add2011-06-04 14:31:571020 const_reverse_iterator rend() const _NOEXCEPT
1021 {return const_reverse_iterator(begin());}
Howard Hinnantbc8d3f92010-05-11 19:42:161022
Howard Hinnant82894812010-09-22 16:48:341023 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7686add2011-06-04 14:31:571024 const_iterator cbegin() const _NOEXCEPT {return begin();}
Howard Hinnant82894812010-09-22 16:48:341025 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7686add2011-06-04 14:31:571026 const_iterator cend() const _NOEXCEPT {return end();}
Howard Hinnant82894812010-09-22 16:48:341027 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7686add2011-06-04 14:31:571028 const_reverse_iterator crbegin() const _NOEXCEPT {return rbegin();}
Howard Hinnant82894812010-09-22 16:48:341029 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7686add2011-06-04 14:31:571030 const_reverse_iterator crend() const _NOEXCEPT {return rend();}
Howard Hinnantbc8d3f92010-05-11 19:42:161031
Howard Hinnant82894812010-09-22 16:48:341032 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7686add2011-06-04 14:31:571033 bool empty() const _NOEXCEPT {return __tree_.size() == 0;}
Howard Hinnant82894812010-09-22 16:48:341034 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7686add2011-06-04 14:31:571035 size_type size() const _NOEXCEPT {return __tree_.size();}
Howard Hinnant82894812010-09-22 16:48:341036 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7686add2011-06-04 14:31:571037 size_type max_size() const _NOEXCEPT {return __tree_.max_size();}
Howard Hinnantbc8d3f92010-05-11 19:42:161038
1039 mapped_type& operator[](const key_type& __k);
Howard Hinnant73d21a42010-09-04 23:28:191040#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:161041 mapped_type& operator[](key_type&& __k);
1042#endif
1043
1044 mapped_type& at(const key_type& __k);
1045 const mapped_type& at(const key_type& __k) const;
1046
Howard Hinnant82894812010-09-22 16:48:341047 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7686add2011-06-04 14:31:571048 allocator_type get_allocator() const _NOEXCEPT {return __tree_.__alloc();}
Howard Hinnant82894812010-09-22 16:48:341049 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161050 key_compare key_comp() const {return __tree_.value_comp().key_comp();}
Howard Hinnant82894812010-09-22 16:48:341051 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161052 value_compare value_comp() const {return value_compare(__tree_.value_comp().key_comp());}
1053
Howard Hinnant73d21a42010-09-04 23:28:191054#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant73d21a42010-09-04 23:28:191055#ifndef _LIBCPP_HAS_NO_VARIADICS
1056
Howard Hinnant635ce1d2012-05-25 22:04:211057 template <class ..._Args>
Howard Hinnantbc8d3f92010-05-11 19:42:161058 pair<iterator, bool>
Howard Hinnant635ce1d2012-05-25 22:04:211059 emplace(_Args&& ...__args);
Howard Hinnantbc8d3f92010-05-11 19:42:161060
Howard Hinnant635ce1d2012-05-25 22:04:211061 template <class ..._Args>
Howard Hinnantbc8d3f92010-05-11 19:42:161062 iterator
Howard Hinnant635ce1d2012-05-25 22:04:211063 emplace_hint(const_iterator __p, _Args&& ...__args);
Howard Hinnantbc8d3f92010-05-11 19:42:161064
Howard Hinnant73d21a42010-09-04 23:28:191065#endif // _LIBCPP_HAS_NO_VARIADICS
1066
Howard Hinnant99968442011-11-29 18:15:501067 template <class _Pp,
1068 class = typename enable_if<is_constructible<value_type, _Pp>::value>::type>
Howard Hinnant82894812010-09-22 16:48:341069 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant99968442011-11-29 18:15:501070 pair<iterator, bool> insert(_Pp&& __p)
1071 {return __tree_.__insert_unique(_VSTD::forward<_Pp>(__p));}
Howard Hinnantbc8d3f92010-05-11 19:42:161072
Howard Hinnant99968442011-11-29 18:15:501073 template <class _Pp,
1074 class = typename enable_if<is_constructible<value_type, _Pp>::value>::type>
Howard Hinnant82894812010-09-22 16:48:341075 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant99968442011-11-29 18:15:501076 iterator insert(const_iterator __pos, _Pp&& __p)
1077 {return __tree_.__insert_unique(__pos.__i_, _VSTD::forward<_Pp>(__p));}
Howard Hinnantbc8d3f92010-05-11 19:42:161078
Howard Hinnant73d21a42010-09-04 23:28:191079#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:161080
Howard Hinnant82894812010-09-22 16:48:341081 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161082 pair<iterator, bool>
1083 insert(const value_type& __v) {return __tree_.__insert_unique(__v);}
1084
Howard Hinnant82894812010-09-22 16:48:341085 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161086 iterator
1087 insert(const_iterator __p, const value_type& __v)
1088 {return __tree_.__insert_unique(__p.__i_, __v);}
1089
Marshall Clow3426a862016-01-05 19:32:411090#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
1091 _LIBCPP_INLINE_VISIBILITY
1092 pair<iterator, bool>
1093 insert( value_type&& __v) {return __tree_.__insert_unique(_VSTD::forward<value_type>(__v));}
1094
1095 _LIBCPP_INLINE_VISIBILITY
1096 iterator
1097 insert(const_iterator __p, value_type&& __v)
1098 {return __tree_.__insert_unique(__p.__i_, _VSTD::forward<value_type>(__v));}
1099#endif
1100
Howard Hinnantbc8d3f92010-05-11 19:42:161101 template <class _InputIterator>
Howard Hinnant82894812010-09-22 16:48:341102 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161103 void insert(_InputIterator __f, _InputIterator __l)
1104 {
1105 for (const_iterator __e = cend(); __f != __l; ++__f)
1106 insert(__e.__i_, *__f);
1107 }
1108
Howard Hinnante3e32912011-08-12 21:56:021109#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1110
Howard Hinnant82894812010-09-22 16:48:341111 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161112 void insert(initializer_list<value_type> __il)
1113 {insert(__il.begin(), __il.end());}
1114
Howard Hinnante3e32912011-08-12 21:56:021115#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1116
Marshall Clowf3a1a182015-07-07 03:37:331117#if _LIBCPP_STD_VER > 14
1118#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
1119#ifndef _LIBCPP_HAS_NO_VARIADICS
1120 template <class... _Args>
1121 _LIBCPP_INLINE_VISIBILITY
1122 pair<iterator, bool> try_emplace(const key_type& __k, _Args&&... __args)
1123 {
1124 iterator __p = lower_bound(__k);
1125 if ( __p != end() && !key_comp()(__k, __p->first))
1126 return _VSTD::make_pair(__p, false);
1127 else
1128 return _VSTD::make_pair(
1129 emplace_hint(__p,
1130 _VSTD::piecewise_construct, _VSTD::forward_as_tuple(__k),
1131 _VSTD::forward_as_tuple(_VSTD::forward<_Args>(__args)...)),
1132 true);
1133 }
1134
1135 template <class... _Args>
1136 _LIBCPP_INLINE_VISIBILITY
1137 pair<iterator, bool> try_emplace(key_type&& __k, _Args&&... __args)
1138 {
1139 iterator __p = lower_bound(__k);
1140 if ( __p != end() && !key_comp()(__k, __p->first))
1141 return _VSTD::make_pair(__p, false);
1142 else
1143 return _VSTD::make_pair(
1144 emplace_hint(__p,
1145 _VSTD::piecewise_construct, _VSTD::forward_as_tuple(_VSTD::move(__k)),
1146 _VSTD::forward_as_tuple(_VSTD::forward<_Args>(__args)...)),
1147 true);
1148 }
1149
1150 template <class... _Args>
1151 _LIBCPP_INLINE_VISIBILITY
1152 iterator try_emplace(const_iterator __h, const key_type& __k, _Args&&... __args)
1153 {
1154 iterator __p = lower_bound(__k);
1155 if ( __p != end() && !key_comp()(__k, __p->first))
1156 return __p;
1157 else
1158 return emplace_hint(__p,
1159 _VSTD::piecewise_construct, _VSTD::forward_as_tuple(__k),
1160 _VSTD::forward_as_tuple(_VSTD::forward<_Args>(__args)...));
1161 }
1162
1163 template <class... _Args>
1164 _LIBCPP_INLINE_VISIBILITY
1165 iterator try_emplace(const_iterator __h, key_type&& __k, _Args&&... __args)
1166 {
1167 iterator __p = lower_bound(__k);
1168 if ( __p != end() && !key_comp()(__k, __p->first))
1169 return __p;
1170 else
1171 return emplace_hint(__p,
1172 _VSTD::piecewise_construct, _VSTD::forward_as_tuple(_VSTD::move(__k)),
1173 _VSTD::forward_as_tuple(_VSTD::forward<_Args>(__args)...));
1174 }
1175
1176 template <class _Vp>
1177 _LIBCPP_INLINE_VISIBILITY
1178 pair<iterator, bool> insert_or_assign(const key_type& __k, _Vp&& __v)
1179 {
1180 iterator __p = lower_bound(__k);
1181 if ( __p != end() && !key_comp()(__k, __p->first))
1182 {
1183 __p->second = _VSTD::forward<_Vp>(__v);
1184 return _VSTD::make_pair(__p, false);
1185 }
1186 return _VSTD::make_pair(emplace_hint(__p, __k, _VSTD::forward<_Vp>(__v)), true);
1187 }
1188
1189 template <class _Vp>
1190 _LIBCPP_INLINE_VISIBILITY
1191 pair<iterator, bool> insert_or_assign(key_type&& __k, _Vp&& __v)
1192 {
1193 iterator __p = lower_bound(__k);
1194 if ( __p != end() && !key_comp()(__k, __p->first))
1195 {
1196 __p->second = _VSTD::forward<_Vp>(__v);
1197 return _VSTD::make_pair(__p, false);
1198 }
1199 return _VSTD::make_pair(emplace_hint(__p, _VSTD::move(__k), _VSTD::forward<_Vp>(__v)), true);
1200 }
1201
1202 template <class _Vp>
1203 _LIBCPP_INLINE_VISIBILITY
1204 iterator insert_or_assign(const_iterator __h, const key_type& __k, _Vp&& __v)
1205 {
1206 iterator __p = lower_bound(__k);
1207 if ( __p != end() && !key_comp()(__k, __p->first))
1208 {
1209 __p->second = _VSTD::forward<_Vp>(__v);
1210 return __p;
1211 }
1212 return emplace_hint(__h, __k, _VSTD::forward<_Vp>(__v));
1213 }
1214
1215 template <class _Vp>
1216 _LIBCPP_INLINE_VISIBILITY
1217 iterator insert_or_assign(const_iterator __h, key_type&& __k, _Vp&& __v)
1218 {
1219 iterator __p = lower_bound(__k);
1220 if ( __p != end() && !key_comp()(__k, __p->first))
1221 {
1222 __p->second = _VSTD::forward<_Vp>(__v);
1223 return __p;
1224 }
1225 return emplace_hint(__h, _VSTD::move(__k), _VSTD::forward<_Vp>(__v));
1226 }
1227#endif
1228#endif
1229#endif
1230
Howard Hinnant82894812010-09-22 16:48:341231 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161232 iterator erase(const_iterator __p) {return __tree_.erase(__p.__i_);}
Howard Hinnant82894812010-09-22 16:48:341233 _LIBCPP_INLINE_VISIBILITY
Marshall Clow488025c2015-05-10 13:35:001234 iterator erase(iterator __p) {return __tree_.erase(__p.__i_);}
1235 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161236 size_type erase(const key_type& __k)
1237 {return __tree_.__erase_unique(__k);}
Howard Hinnant82894812010-09-22 16:48:341238 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161239 iterator erase(const_iterator __f, const_iterator __l)
1240 {return __tree_.erase(__f.__i_, __l.__i_);}
Howard Hinnant82894812010-09-22 16:48:341241 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7686add2011-06-04 14:31:571242 void clear() _NOEXCEPT {__tree_.clear();}
Howard Hinnantbc8d3f92010-05-11 19:42:161243
Howard Hinnant82894812010-09-22 16:48:341244 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7686add2011-06-04 14:31:571245 void swap(map& __m)
1246 _NOEXCEPT_(__is_nothrow_swappable<__base>::value)
1247 {__tree_.swap(__m.__tree_);}
Howard Hinnantbc8d3f92010-05-11 19:42:161248
Howard Hinnant82894812010-09-22 16:48:341249 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161250 iterator find(const key_type& __k) {return __tree_.find(__k);}
Howard Hinnant82894812010-09-22 16:48:341251 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161252 const_iterator find(const key_type& __k) const {return __tree_.find(__k);}
Marshall Clow5cfc6ab2013-08-13 22:18:471253#if _LIBCPP_STD_VER > 11
1254 template <typename _K2>
1255 _LIBCPP_INLINE_VISIBILITY
1256 typename enable_if<__is_transparent<_Compare, _K2>::value,iterator>::type
1257 find(const _K2& __k) {return __tree_.find(__k);}
1258 template <typename _K2>
1259 _LIBCPP_INLINE_VISIBILITY
1260 typename enable_if<__is_transparent<_Compare, _K2>::value,const_iterator>::type
1261 find(const _K2& __k) const {return __tree_.find(__k);}
1262#endif
1263
Howard Hinnant82894812010-09-22 16:48:341264 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161265 size_type count(const key_type& __k) const
1266 {return __tree_.__count_unique(__k);}
Marshall Clow4de32042014-08-24 23:54:161267#if _LIBCPP_STD_VER > 11
1268 template <typename _K2>
1269 _LIBCPP_INLINE_VISIBILITY
1270 typename enable_if<__is_transparent<_Compare, _K2>::value,size_type>::type
Marshall Clow58113db2015-06-30 18:15:411271 count(const _K2& __k) const {return __tree_.__count_unique(__k);}
Marshall Clow4de32042014-08-24 23:54:161272#endif
Howard Hinnant82894812010-09-22 16:48:341273 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161274 iterator lower_bound(const key_type& __k)
1275 {return __tree_.lower_bound(__k);}
Howard Hinnant82894812010-09-22 16:48:341276 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161277 const_iterator lower_bound(const key_type& __k) const
1278 {return __tree_.lower_bound(__k);}
Marshall Clow5cfc6ab2013-08-13 22:18:471279#if _LIBCPP_STD_VER > 11
1280 template <typename _K2>
1281 _LIBCPP_INLINE_VISIBILITY
1282 typename enable_if<__is_transparent<_Compare, _K2>::value,iterator>::type
1283 lower_bound(const _K2& __k) {return __tree_.lower_bound(__k);}
1284
1285 template <typename _K2>
1286 _LIBCPP_INLINE_VISIBILITY
1287 typename enable_if<__is_transparent<_Compare, _K2>::value,const_iterator>::type
1288 lower_bound(const _K2& __k) const {return __tree_.lower_bound(__k);}
1289#endif
1290
Howard Hinnant82894812010-09-22 16:48:341291 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161292 iterator upper_bound(const key_type& __k)
1293 {return __tree_.upper_bound(__k);}
Howard Hinnant82894812010-09-22 16:48:341294 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161295 const_iterator upper_bound(const key_type& __k) const
1296 {return __tree_.upper_bound(__k);}
Marshall Clow5cfc6ab2013-08-13 22:18:471297#if _LIBCPP_STD_VER > 11
1298 template <typename _K2>
1299 _LIBCPP_INLINE_VISIBILITY
1300 typename enable_if<__is_transparent<_Compare, _K2>::value,iterator>::type
1301 upper_bound(const _K2& __k) {return __tree_.upper_bound(__k);}
1302 template <typename _K2>
1303 _LIBCPP_INLINE_VISIBILITY
1304 typename enable_if<__is_transparent<_Compare, _K2>::value,const_iterator>::type
1305 upper_bound(const _K2& __k) const {return __tree_.upper_bound(__k);}
1306#endif
1307
Howard Hinnant82894812010-09-22 16:48:341308 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161309 pair<iterator,iterator> equal_range(const key_type& __k)
1310 {return __tree_.__equal_range_unique(__k);}
Howard Hinnant82894812010-09-22 16:48:341311 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161312 pair<const_iterator,const_iterator> equal_range(const key_type& __k) const
1313 {return __tree_.__equal_range_unique(__k);}
Marshall Clow5cfc6ab2013-08-13 22:18:471314#if _LIBCPP_STD_VER > 11
1315 template <typename _K2>
1316 _LIBCPP_INLINE_VISIBILITY
1317 typename enable_if<__is_transparent<_Compare, _K2>::value,pair<iterator,iterator>>::type
1318 equal_range(const _K2& __k) {return __tree_.__equal_range_unique(__k);}
1319 template <typename _K2>
1320 _LIBCPP_INLINE_VISIBILITY
1321 typename enable_if<__is_transparent<_Compare, _K2>::value,pair<const_iterator,const_iterator>>::type
1322 equal_range(const _K2& __k) const {return __tree_.__equal_range_unique(__k);}
1323#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161324
1325private:
1326 typedef typename __base::__node __node;
1327 typedef typename __base::__node_allocator __node_allocator;
1328 typedef typename __base::__node_pointer __node_pointer;
1329 typedef typename __base::__node_const_pointer __node_const_pointer;
1330 typedef typename __base::__node_base_pointer __node_base_pointer;
1331 typedef typename __base::__node_base_const_pointer __node_base_const_pointer;
Howard Hinnant99968442011-11-29 18:15:501332 typedef __map_node_destructor<__node_allocator> _Dp;
1333 typedef unique_ptr<__node, _Dp> __node_holder;
Howard Hinnantbc8d3f92010-05-11 19:42:161334
Howard Hinnant73d21a42010-09-04 23:28:191335#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:161336 __node_holder __construct_node();
Howard Hinnant635ce1d2012-05-25 22:04:211337 template <class _A0>
Howard Hinnantb66e1c32013-07-04 20:59:161338 __node_holder __construct_node(_A0&& __a0);
1339 __node_holder __construct_node_with_key(key_type&& __k);
Howard Hinnant73d21a42010-09-04 23:28:191340#ifndef _LIBCPP_HAS_NO_VARIADICS
Howard Hinnant635ce1d2012-05-25 22:04:211341 template <class _A0, class _A1, class ..._Args>
1342 __node_holder __construct_node(_A0&& __a0, _A1&& __a1, _Args&& ...__args);
Howard Hinnant73d21a42010-09-04 23:28:191343#endif // _LIBCPP_HAS_NO_VARIADICS
Howard Hinnantbc8d3f92010-05-11 19:42:161344#endif
Howard Hinnantb66e1c32013-07-04 20:59:161345 __node_holder __construct_node_with_key(const key_type& __k);
Howard Hinnantbc8d3f92010-05-11 19:42:161346
1347 __node_base_pointer&
1348 __find_equal_key(__node_base_pointer& __parent, const key_type& __k);
Howard Hinnantbc8d3f92010-05-11 19:42:161349 __node_base_const_pointer
1350 __find_equal_key(__node_base_const_pointer& __parent, const key_type& __k) const;
1351};
1352
1353// Find place to insert if __k doesn't exist
1354// Set __parent to parent of null leaf
1355// Return reference to null leaf
1356// If __k exists, set parent to node of __k and return reference to node of __k
1357template <class _Key, class _Tp, class _Compare, class _Allocator>
1358typename map<_Key, _Tp, _Compare, _Allocator>::__node_base_pointer&
1359map<_Key, _Tp, _Compare, _Allocator>::__find_equal_key(__node_base_pointer& __parent,
1360 const key_type& __k)
1361{
1362 __node_pointer __nd = __tree_.__root();
1363 if (__nd != nullptr)
1364 {
1365 while (true)
1366 {
Howard Hinnant70342b92013-06-19 21:29:401367 if (__tree_.value_comp().key_comp()(__k, __nd->__value_.__cc.first))
Howard Hinnantbc8d3f92010-05-11 19:42:161368 {
1369 if (__nd->__left_ != nullptr)
1370 __nd = static_cast<__node_pointer>(__nd->__left_);
1371 else
1372 {
Howard Hinnant70342b92013-06-19 21:29:401373 __parent = static_cast<__node_base_pointer>(__nd);
Howard Hinnantbc8d3f92010-05-11 19:42:161374 return __parent->__left_;
1375 }
1376 }
Howard Hinnant70342b92013-06-19 21:29:401377 else if (__tree_.value_comp().key_comp()(__nd->__value_.__cc.first, __k))
Howard Hinnantbc8d3f92010-05-11 19:42:161378 {
1379 if (__nd->__right_ != nullptr)
1380 __nd = static_cast<__node_pointer>(__nd->__right_);
1381 else
1382 {
Howard Hinnant70342b92013-06-19 21:29:401383 __parent = static_cast<__node_base_pointer>(__nd);
Howard Hinnantbc8d3f92010-05-11 19:42:161384 return __parent->__right_;
1385 }
1386 }
1387 else
1388 {
Howard Hinnant70342b92013-06-19 21:29:401389 __parent = static_cast<__node_base_pointer>(__nd);
Howard Hinnantbc8d3f92010-05-11 19:42:161390 return __parent;
1391 }
1392 }
1393 }
Howard Hinnant70342b92013-06-19 21:29:401394 __parent = static_cast<__node_base_pointer>(__tree_.__end_node());
Howard Hinnantbc8d3f92010-05-11 19:42:161395 return __parent->__left_;
1396}
1397
Howard Hinnantbc8d3f92010-05-11 19:42:161398// Find __k
1399// Set __parent to parent of null leaf and
1400// return reference to null leaf iv __k does not exist.
1401// If __k exists, set parent to node of __k and return reference to node of __k
1402template <class _Key, class _Tp, class _Compare, class _Allocator>
1403typename map<_Key, _Tp, _Compare, _Allocator>::__node_base_const_pointer
1404map<_Key, _Tp, _Compare, _Allocator>::__find_equal_key(__node_base_const_pointer& __parent,
1405 const key_type& __k) const
1406{
1407 __node_const_pointer __nd = __tree_.__root();
1408 if (__nd != nullptr)
1409 {
1410 while (true)
1411 {
Howard Hinnant70342b92013-06-19 21:29:401412 if (__tree_.value_comp().key_comp()(__k, __nd->__value_.__cc.first))
Howard Hinnantbc8d3f92010-05-11 19:42:161413 {
1414 if (__nd->__left_ != nullptr)
1415 __nd = static_cast<__node_pointer>(__nd->__left_);
1416 else
1417 {
Howard Hinnant70342b92013-06-19 21:29:401418 __parent = static_cast<__node_base_pointer>(__nd);
Howard Hinnantbc8d3f92010-05-11 19:42:161419 return const_cast<const __node_base_const_pointer&>(__parent->__left_);
1420 }
1421 }
Howard Hinnant70342b92013-06-19 21:29:401422 else if (__tree_.value_comp().key_comp()(__nd->__value_.__cc.first, __k))
Howard Hinnantbc8d3f92010-05-11 19:42:161423 {
1424 if (__nd->__right_ != nullptr)
1425 __nd = static_cast<__node_pointer>(__nd->__right_);
1426 else
1427 {
Howard Hinnant70342b92013-06-19 21:29:401428 __parent = static_cast<__node_base_pointer>(__nd);
Howard Hinnantbc8d3f92010-05-11 19:42:161429 return const_cast<const __node_base_const_pointer&>(__parent->__right_);
1430 }
1431 }
1432 else
1433 {
Howard Hinnant70342b92013-06-19 21:29:401434 __parent = static_cast<__node_base_pointer>(__nd);
Howard Hinnantbc8d3f92010-05-11 19:42:161435 return __parent;
1436 }
1437 }
1438 }
Howard Hinnant70342b92013-06-19 21:29:401439 __parent = static_cast<__node_base_pointer>(__tree_.__end_node());
Howard Hinnantbc8d3f92010-05-11 19:42:161440 return const_cast<const __node_base_const_pointer&>(__parent->__left_);
1441}
1442
Howard Hinnant73d21a42010-09-04 23:28:191443#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:161444
1445template <class _Key, class _Tp, class _Compare, class _Allocator>
1446map<_Key, _Tp, _Compare, _Allocator>::map(map&& __m, const allocator_type& __a)
Howard Hinnant0949eed2011-06-30 21:18:191447 : __tree_(_VSTD::move(__m.__tree_), __a)
Howard Hinnantbc8d3f92010-05-11 19:42:161448{
1449 if (__a != __m.get_allocator())
1450 {
1451 const_iterator __e = cend();
1452 while (!__m.empty())
1453 __tree_.__insert_unique(__e.__i_,
Howard Hinnant0949eed2011-06-30 21:18:191454 _VSTD::move(__m.__tree_.remove(__m.begin().__i_)->__value_));
Howard Hinnantbc8d3f92010-05-11 19:42:161455 }
1456}
1457
1458template <class _Key, class _Tp, class _Compare, class _Allocator>
1459typename map<_Key, _Tp, _Compare, _Allocator>::__node_holder
1460map<_Key, _Tp, _Compare, _Allocator>::__construct_node()
1461{
1462 __node_allocator& __na = __tree_.__node_alloc();
Howard Hinnant99968442011-11-29 18:15:501463 __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
Howard Hinnant70342b92013-06-19 21:29:401464 __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__cc.first));
Howard Hinnantbc8d3f92010-05-11 19:42:161465 __h.get_deleter().__first_constructed = true;
Howard Hinnant70342b92013-06-19 21:29:401466 __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__cc.second));
Howard Hinnantbc8d3f92010-05-11 19:42:161467 __h.get_deleter().__second_constructed = true;
1468 return __h;
1469}
1470
1471template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant635ce1d2012-05-25 22:04:211472template <class _A0>
Howard Hinnantb66e1c32013-07-04 20:59:161473typename map<_Key, _Tp, _Compare, _Allocator>::__node_holder
Howard Hinnantbc8d3f92010-05-11 19:42:161474map<_Key, _Tp, _Compare, _Allocator>::__construct_node(_A0&& __a0)
1475{
1476 __node_allocator& __na = __tree_.__node_alloc();
Howard Hinnant99968442011-11-29 18:15:501477 __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
Howard Hinnant0949eed2011-06-30 21:18:191478 __node_traits::construct(__na, _VSTD::addressof(__h->__value_), _VSTD::forward<_A0>(__a0));
Howard Hinnantbc8d3f92010-05-11 19:42:161479 __h.get_deleter().__first_constructed = true;
1480 __h.get_deleter().__second_constructed = true;
1481 return __h;
1482}
1483
1484template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnantb66e1c32013-07-04 20:59:161485typename map<_Key, _Tp, _Compare, _Allocator>::__node_holder
1486map<_Key, _Tp, _Compare, _Allocator>::__construct_node_with_key(key_type&& __k)
Howard Hinnantbc8d3f92010-05-11 19:42:161487{
1488 __node_allocator& __na = __tree_.__node_alloc();
Howard Hinnant99968442011-11-29 18:15:501489 __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
Howard Hinnantb66e1c32013-07-04 20:59:161490 __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__cc.first), _VSTD::move(__k));
Howard Hinnantbc8d3f92010-05-11 19:42:161491 __h.get_deleter().__first_constructed = true;
Howard Hinnant70342b92013-06-19 21:29:401492 __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__cc.second));
Howard Hinnant635ce1d2012-05-25 22:04:211493 __h.get_deleter().__second_constructed = true;
Howard Hinnant9a894d92013-08-22 18:29:501494 return __h;
Howard Hinnant635ce1d2012-05-25 22:04:211495}
1496
1497#ifndef _LIBCPP_HAS_NO_VARIADICS
1498
1499template <class _Key, class _Tp, class _Compare, class _Allocator>
1500template <class _A0, class _A1, class ..._Args>
1501typename map<_Key, _Tp, _Compare, _Allocator>::__node_holder
1502map<_Key, _Tp, _Compare, _Allocator>::__construct_node(_A0&& __a0, _A1&& __a1, _Args&& ...__args)
1503{
1504 __node_allocator& __na = __tree_.__node_alloc();
1505 __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
1506 __node_traits::construct(__na, _VSTD::addressof(__h->__value_),
1507 _VSTD::forward<_A0>(__a0), _VSTD::forward<_A1>(__a1),
1508 _VSTD::forward<_Args>(__args)...);
1509 __h.get_deleter().__first_constructed = true;
Howard Hinnantbc8d3f92010-05-11 19:42:161510 __h.get_deleter().__second_constructed = true;
1511 return __h;
1512}
1513
Howard Hinnant73d21a42010-09-04 23:28:191514#endif // _LIBCPP_HAS_NO_VARIADICS
1515
Howard Hinnantb66e1c32013-07-04 20:59:161516#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:161517
1518template <class _Key, class _Tp, class _Compare, class _Allocator>
1519typename map<_Key, _Tp, _Compare, _Allocator>::__node_holder
Howard Hinnantb66e1c32013-07-04 20:59:161520map<_Key, _Tp, _Compare, _Allocator>::__construct_node_with_key(const key_type& __k)
Howard Hinnantbc8d3f92010-05-11 19:42:161521{
1522 __node_allocator& __na = __tree_.__node_alloc();
Howard Hinnant99968442011-11-29 18:15:501523 __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
Howard Hinnant70342b92013-06-19 21:29:401524 __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__cc.first), __k);
Howard Hinnantbc8d3f92010-05-11 19:42:161525 __h.get_deleter().__first_constructed = true;
Howard Hinnant70342b92013-06-19 21:29:401526 __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__cc.second));
Howard Hinnantbc8d3f92010-05-11 19:42:161527 __h.get_deleter().__second_constructed = true;
Dimitry Andric89663502015-08-19 06:43:331528 return _LIBCPP_EXPLICIT_MOVE(__h); // explicitly moved for C++03
Howard Hinnantbc8d3f92010-05-11 19:42:161529}
1530
Howard Hinnantbc8d3f92010-05-11 19:42:161531template <class _Key, class _Tp, class _Compare, class _Allocator>
1532_Tp&
1533map<_Key, _Tp, _Compare, _Allocator>::operator[](const key_type& __k)
1534{
1535 __node_base_pointer __parent;
1536 __node_base_pointer& __child = __find_equal_key(__parent, __k);
1537 __node_pointer __r = static_cast<__node_pointer>(__child);
1538 if (__child == nullptr)
1539 {
Howard Hinnantb66e1c32013-07-04 20:59:161540 __node_holder __h = __construct_node_with_key(__k);
Howard Hinnant70342b92013-06-19 21:29:401541 __tree_.__insert_node_at(__parent, __child, static_cast<__node_base_pointer>(__h.get()));
Howard Hinnantbc8d3f92010-05-11 19:42:161542 __r = __h.release();
1543 }
Howard Hinnant70342b92013-06-19 21:29:401544 return __r->__value_.__cc.second;
Howard Hinnantbc8d3f92010-05-11 19:42:161545}
1546
Howard Hinnant73d21a42010-09-04 23:28:191547#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:161548
1549template <class _Key, class _Tp, class _Compare, class _Allocator>
1550_Tp&
1551map<_Key, _Tp, _Compare, _Allocator>::operator[](key_type&& __k)
1552{
1553 __node_base_pointer __parent;
1554 __node_base_pointer& __child = __find_equal_key(__parent, __k);
1555 __node_pointer __r = static_cast<__node_pointer>(__child);
1556 if (__child == nullptr)
1557 {
Howard Hinnantb66e1c32013-07-04 20:59:161558 __node_holder __h = __construct_node_with_key(_VSTD::move(__k));
Howard Hinnant70342b92013-06-19 21:29:401559 __tree_.__insert_node_at(__parent, __child, static_cast<__node_base_pointer>(__h.get()));
Howard Hinnantbc8d3f92010-05-11 19:42:161560 __r = __h.release();
1561 }
Howard Hinnant70342b92013-06-19 21:29:401562 return __r->__value_.__cc.second;
Howard Hinnantbc8d3f92010-05-11 19:42:161563}
1564
Howard Hinnant73d21a42010-09-04 23:28:191565#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:161566
1567template <class _Key, class _Tp, class _Compare, class _Allocator>
1568_Tp&
1569map<_Key, _Tp, _Compare, _Allocator>::at(const key_type& __k)
1570{
1571 __node_base_pointer __parent;
1572 __node_base_pointer& __child = __find_equal_key(__parent, __k);
Howard Hinnantd4444702010-08-11 17:04:311573#ifndef _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:161574 if (__child == nullptr)
1575 throw out_of_range("map::at: key not found");
Howard Hinnant324bb032010-08-22 00:02:431576#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant70342b92013-06-19 21:29:401577 return static_cast<__node_pointer>(__child)->__value_.__cc.second;
Howard Hinnantbc8d3f92010-05-11 19:42:161578}
1579
1580template <class _Key, class _Tp, class _Compare, class _Allocator>
1581const _Tp&
1582map<_Key, _Tp, _Compare, _Allocator>::at(const key_type& __k) const
1583{
1584 __node_base_const_pointer __parent;
1585 __node_base_const_pointer __child = __find_equal_key(__parent, __k);
Howard Hinnantd4444702010-08-11 17:04:311586#ifndef _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:161587 if (__child == nullptr)
1588 throw out_of_range("map::at: key not found");
Howard Hinnant324bb032010-08-22 00:02:431589#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant70342b92013-06-19 21:29:401590 return static_cast<__node_const_pointer>(__child)->__value_.__cc.second;
Howard Hinnantbc8d3f92010-05-11 19:42:161591}
1592
Howard Hinnant73d21a42010-09-04 23:28:191593#if !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
Howard Hinnantbc8d3f92010-05-11 19:42:161594
1595template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant635ce1d2012-05-25 22:04:211596template <class ..._Args>
Howard Hinnantbc8d3f92010-05-11 19:42:161597pair<typename map<_Key, _Tp, _Compare, _Allocator>::iterator, bool>
Howard Hinnant635ce1d2012-05-25 22:04:211598map<_Key, _Tp, _Compare, _Allocator>::emplace(_Args&& ...__args)
Howard Hinnantbc8d3f92010-05-11 19:42:161599{
Howard Hinnant635ce1d2012-05-25 22:04:211600 __node_holder __h = __construct_node(_VSTD::forward<_Args>(__args)...);
Howard Hinnantbc8d3f92010-05-11 19:42:161601 pair<iterator, bool> __r = __tree_.__node_insert_unique(__h.get());
1602 if (__r.second)
1603 __h.release();
1604 return __r;
1605}
1606
1607template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant635ce1d2012-05-25 22:04:211608template <class ..._Args>
Howard Hinnantbc8d3f92010-05-11 19:42:161609typename map<_Key, _Tp, _Compare, _Allocator>::iterator
1610map<_Key, _Tp, _Compare, _Allocator>::emplace_hint(const_iterator __p,
Howard Hinnant635ce1d2012-05-25 22:04:211611 _Args&& ...__args)
Howard Hinnantbc8d3f92010-05-11 19:42:161612{
Howard Hinnant635ce1d2012-05-25 22:04:211613 __node_holder __h = __construct_node(_VSTD::forward<_Args>(__args)...);
Howard Hinnantbc8d3f92010-05-11 19:42:161614 iterator __r = __tree_.__node_insert_unique(__p.__i_, __h.get());
1615 if (__r.__i_.__ptr_ == __h.get())
1616 __h.release();
1617 return __r;
1618}
1619
Howard Hinnant73d21a42010-09-04 23:28:191620#endif // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
Howard Hinnantbc8d3f92010-05-11 19:42:161621
1622template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant82894812010-09-22 16:48:341623inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161624bool
1625operator==(const map<_Key, _Tp, _Compare, _Allocator>& __x,
1626 const map<_Key, _Tp, _Compare, _Allocator>& __y)
1627{
Howard Hinnant0949eed2011-06-30 21:18:191628 return __x.size() == __y.size() && _VSTD::equal(__x.begin(), __x.end(), __y.begin());
Howard Hinnantbc8d3f92010-05-11 19:42:161629}
1630
1631template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant82894812010-09-22 16:48:341632inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161633bool
1634operator< (const map<_Key, _Tp, _Compare, _Allocator>& __x,
1635 const map<_Key, _Tp, _Compare, _Allocator>& __y)
1636{
Howard Hinnant0949eed2011-06-30 21:18:191637 return _VSTD::lexicographical_compare(__x.begin(), __x.end(), __y.begin(), __y.end());
Howard Hinnantbc8d3f92010-05-11 19:42:161638}
1639
1640template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant82894812010-09-22 16:48:341641inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161642bool
1643operator!=(const map<_Key, _Tp, _Compare, _Allocator>& __x,
1644 const map<_Key, _Tp, _Compare, _Allocator>& __y)
1645{
1646 return !(__x == __y);
1647}
1648
1649template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant82894812010-09-22 16:48:341650inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161651bool
1652operator> (const map<_Key, _Tp, _Compare, _Allocator>& __x,
1653 const map<_Key, _Tp, _Compare, _Allocator>& __y)
1654{
1655 return __y < __x;
1656}
1657
1658template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant82894812010-09-22 16:48:341659inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161660bool
1661operator>=(const map<_Key, _Tp, _Compare, _Allocator>& __x,
1662 const map<_Key, _Tp, _Compare, _Allocator>& __y)
1663{
1664 return !(__x < __y);
1665}
1666
1667template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant82894812010-09-22 16:48:341668inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161669bool
1670operator<=(const map<_Key, _Tp, _Compare, _Allocator>& __x,
1671 const map<_Key, _Tp, _Compare, _Allocator>& __y)
1672{
1673 return !(__y < __x);
1674}
1675
1676template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant82894812010-09-22 16:48:341677inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161678void
1679swap(map<_Key, _Tp, _Compare, _Allocator>& __x,
1680 map<_Key, _Tp, _Compare, _Allocator>& __y)
Howard Hinnant7686add2011-06-04 14:31:571681 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
Howard Hinnantbc8d3f92010-05-11 19:42:161682{
1683 __x.swap(__y);
1684}
1685
1686template <class _Key, class _Tp, class _Compare = less<_Key>,
1687 class _Allocator = allocator<pair<const _Key, _Tp> > >
Howard Hinnant0f678bd2013-08-12 18:38:341688class _LIBCPP_TYPE_VIS_ONLY multimap
Howard Hinnantbc8d3f92010-05-11 19:42:161689{
1690public:
1691 // types:
1692 typedef _Key key_type;
1693 typedef _Tp mapped_type;
1694 typedef pair<const key_type, mapped_type> value_type;
Howard Hinnant70342b92013-06-19 21:29:401695 typedef pair<key_type, mapped_type> __nc_value_type;
Howard Hinnantbc8d3f92010-05-11 19:42:161696 typedef _Compare key_compare;
1697 typedef _Allocator allocator_type;
1698 typedef value_type& reference;
1699 typedef const value_type& const_reference;
1700
Marshall Clow14ba0ad2015-11-26 01:24:041701 static_assert((is_same<typename allocator_type::value_type, value_type>::value),
1702 "Allocator::value_type must be same type as value_type");
1703
Howard Hinnant0f678bd2013-08-12 18:38:341704 class _LIBCPP_TYPE_VIS_ONLY value_compare
Howard Hinnantbc8d3f92010-05-11 19:42:161705 : public binary_function<value_type, value_type, bool>
1706 {
1707 friend class multimap;
1708 protected:
1709 key_compare comp;
1710
Howard Hinnant82894812010-09-22 16:48:341711 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161712 value_compare(key_compare c) : comp(c) {}
1713 public:
Howard Hinnant82894812010-09-22 16:48:341714 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161715 bool operator()(const value_type& __x, const value_type& __y) const
1716 {return comp(__x.first, __y.first);}
1717 };
1718
1719private:
Howard Hinnant70342b92013-06-19 21:29:401720
Howard Hinnantff7546e2013-09-30 19:08:221721 typedef _VSTD::__value_type<key_type, mapped_type> __value_type;
Howard Hinnant9b128e02013-07-05 18:06:001722 typedef __map_value_compare<key_type, __value_type, key_compare> __vc;
Marshall Clow66302c62015-04-07 05:21:381723 typedef typename __rebind_alloc_helper<allocator_traits<allocator_type>,
1724 __value_type>::type __allocator_type;
Howard Hinnantbc8d3f92010-05-11 19:42:161725 typedef __tree<__value_type, __vc, __allocator_type> __base;
1726 typedef typename __base::__node_traits __node_traits;
1727 typedef allocator_traits<allocator_type> __alloc_traits;
1728
1729 __base __tree_;
1730
1731public:
1732 typedef typename __alloc_traits::pointer pointer;
1733 typedef typename __alloc_traits::const_pointer const_pointer;
1734 typedef typename __alloc_traits::size_type size_type;
1735 typedef typename __alloc_traits::difference_type difference_type;
1736 typedef __map_iterator<typename __base::iterator> iterator;
1737 typedef __map_const_iterator<typename __base::const_iterator> const_iterator;
Howard Hinnant0949eed2011-06-30 21:18:191738 typedef _VSTD::reverse_iterator<iterator> reverse_iterator;
1739 typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator;
Howard Hinnantbc8d3f92010-05-11 19:42:161740
Howard Hinnant82894812010-09-22 16:48:341741 _LIBCPP_INLINE_VISIBILITY
Marshall Clowcaaa1412014-03-10 04:50:101742 multimap()
1743 _NOEXCEPT_(
1744 is_nothrow_default_constructible<allocator_type>::value &&
1745 is_nothrow_default_constructible<key_compare>::value &&
1746 is_nothrow_copy_constructible<key_compare>::value)
1747 : __tree_(__vc(key_compare())) {}
1748
1749 _LIBCPP_INLINE_VISIBILITY
1750 explicit multimap(const key_compare& __comp)
Howard Hinnant7686add2011-06-04 14:31:571751 _NOEXCEPT_(
1752 is_nothrow_default_constructible<allocator_type>::value &&
Howard Hinnant7686add2011-06-04 14:31:571753 is_nothrow_copy_constructible<key_compare>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:161754 : __tree_(__vc(__comp)) {}
1755
Howard Hinnant82894812010-09-22 16:48:341756 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161757 explicit multimap(const key_compare& __comp, const allocator_type& __a)
1758 : __tree_(__vc(__comp), __a) {}
1759
1760 template <class _InputIterator>
Howard Hinnant82894812010-09-22 16:48:341761 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161762 multimap(_InputIterator __f, _InputIterator __l,
1763 const key_compare& __comp = key_compare())
1764 : __tree_(__vc(__comp))
1765 {
1766 insert(__f, __l);
1767 }
1768
1769 template <class _InputIterator>
Howard Hinnant82894812010-09-22 16:48:341770 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161771 multimap(_InputIterator __f, _InputIterator __l,
1772 const key_compare& __comp, const allocator_type& __a)
1773 : __tree_(__vc(__comp), __a)
1774 {
1775 insert(__f, __l);
1776 }
1777
Marshall Clow49d596d2013-09-11 01:15:471778#if _LIBCPP_STD_VER > 11
1779 template <class _InputIterator>
1780 _LIBCPP_INLINE_VISIBILITY
1781 multimap(_InputIterator __f, _InputIterator __l, const allocator_type& __a)
1782 : multimap(__f, __l, key_compare(), __a) {}
1783#endif
1784
Howard Hinnant82894812010-09-22 16:48:341785 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161786 multimap(const multimap& __m)
1787 : __tree_(__m.__tree_.value_comp(),
1788 __alloc_traits::select_on_container_copy_construction(__m.__tree_.__alloc()))
1789 {
1790 insert(__m.begin(), __m.end());
1791 }
1792
Howard Hinnant61aa6012011-07-01 19:24:361793 _LIBCPP_INLINE_VISIBILITY
1794 multimap& operator=(const multimap& __m)
1795 {
Howard Hinnant70342b92013-06-19 21:29:401796#if __cplusplus >= 201103L
Howard Hinnant61aa6012011-07-01 19:24:361797 __tree_ = __m.__tree_;
Howard Hinnant70342b92013-06-19 21:29:401798#else
Marshall Clowebfc50e2014-02-08 04:03:141799 if (this != &__m) {
1800 __tree_.clear();
1801 __tree_.value_comp() = __m.__tree_.value_comp();
1802 __tree_.__copy_assign_alloc(__m.__tree_);
1803 insert(__m.begin(), __m.end());
1804 }
Howard Hinnant70342b92013-06-19 21:29:401805#endif
Howard Hinnant61aa6012011-07-01 19:24:361806 return *this;
1807 }
1808
Howard Hinnant73d21a42010-09-04 23:28:191809#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:161810
Howard Hinnant82894812010-09-22 16:48:341811 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161812 multimap(multimap&& __m)
Howard Hinnant7686add2011-06-04 14:31:571813 _NOEXCEPT_(is_nothrow_move_constructible<__base>::value)
Howard Hinnant0949eed2011-06-30 21:18:191814 : __tree_(_VSTD::move(__m.__tree_))
Howard Hinnantbc8d3f92010-05-11 19:42:161815 {
1816 }
1817
1818 multimap(multimap&& __m, const allocator_type& __a);
1819
Howard Hinnant82894812010-09-22 16:48:341820 _LIBCPP_INLINE_VISIBILITY
Howard Hinnante3e32912011-08-12 21:56:021821 multimap& operator=(multimap&& __m)
1822 _NOEXCEPT_(is_nothrow_move_assignable<__base>::value)
1823 {
1824 __tree_ = _VSTD::move(__m.__tree_);
1825 return *this;
1826 }
1827
1828#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
1829
1830#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1831
1832 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161833 multimap(initializer_list<value_type> __il, const key_compare& __comp = key_compare())
1834 : __tree_(__vc(__comp))
1835 {
1836 insert(__il.begin(), __il.end());
1837 }
1838
Howard Hinnant82894812010-09-22 16:48:341839 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161840 multimap(initializer_list<value_type> __il, const key_compare& __comp, const allocator_type& __a)
1841 : __tree_(__vc(__comp), __a)
1842 {
1843 insert(__il.begin(), __il.end());
1844 }
1845
Marshall Clow49d596d2013-09-11 01:15:471846#if _LIBCPP_STD_VER > 11
1847 _LIBCPP_INLINE_VISIBILITY
1848 multimap(initializer_list<value_type> __il, const allocator_type& __a)
1849 : multimap(__il, key_compare(), __a) {}
1850#endif
1851
Howard Hinnant82894812010-09-22 16:48:341852 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161853 multimap& operator=(initializer_list<value_type> __il)
1854 {
1855 __tree_.__assign_multi(__il.begin(), __il.end());
1856 return *this;
1857 }
Howard Hinnante3e32912011-08-12 21:56:021858
1859#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:161860
Howard Hinnant82894812010-09-22 16:48:341861 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161862 explicit multimap(const allocator_type& __a)
1863 : __tree_(__a)
1864 {
1865 }
1866
Howard Hinnant82894812010-09-22 16:48:341867 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161868 multimap(const multimap& __m, const allocator_type& __a)
1869 : __tree_(__m.__tree_.value_comp(), __a)
1870 {
1871 insert(__m.begin(), __m.end());
1872 }
1873
Howard Hinnant82894812010-09-22 16:48:341874 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7686add2011-06-04 14:31:571875 iterator begin() _NOEXCEPT {return __tree_.begin();}
Howard Hinnant82894812010-09-22 16:48:341876 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7686add2011-06-04 14:31:571877 const_iterator begin() const _NOEXCEPT {return __tree_.begin();}
Howard Hinnant82894812010-09-22 16:48:341878 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7686add2011-06-04 14:31:571879 iterator end() _NOEXCEPT {return __tree_.end();}
Howard Hinnant82894812010-09-22 16:48:341880 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7686add2011-06-04 14:31:571881 const_iterator end() const _NOEXCEPT {return __tree_.end();}
Howard Hinnantbc8d3f92010-05-11 19:42:161882
Howard Hinnant82894812010-09-22 16:48:341883 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7686add2011-06-04 14:31:571884 reverse_iterator rbegin() _NOEXCEPT {return reverse_iterator(end());}
Howard Hinnant82894812010-09-22 16:48:341885 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7686add2011-06-04 14:31:571886 const_reverse_iterator rbegin() const _NOEXCEPT
1887 {return const_reverse_iterator(end());}
Howard Hinnant82894812010-09-22 16:48:341888 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7686add2011-06-04 14:31:571889 reverse_iterator rend() _NOEXCEPT {return reverse_iterator(begin());}
Howard Hinnant82894812010-09-22 16:48:341890 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7686add2011-06-04 14:31:571891 const_reverse_iterator rend() const _NOEXCEPT
1892 {return const_reverse_iterator(begin());}
Howard Hinnantbc8d3f92010-05-11 19:42:161893
Howard Hinnant82894812010-09-22 16:48:341894 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7686add2011-06-04 14:31:571895 const_iterator cbegin() const _NOEXCEPT {return begin();}
Howard Hinnant82894812010-09-22 16:48:341896 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7686add2011-06-04 14:31:571897 const_iterator cend() const _NOEXCEPT {return end();}
Howard Hinnant82894812010-09-22 16:48:341898 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7686add2011-06-04 14:31:571899 const_reverse_iterator crbegin() const _NOEXCEPT {return rbegin();}
Howard Hinnant82894812010-09-22 16:48:341900 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7686add2011-06-04 14:31:571901 const_reverse_iterator crend() const _NOEXCEPT {return rend();}
Howard Hinnantbc8d3f92010-05-11 19:42:161902
Howard Hinnant82894812010-09-22 16:48:341903 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7686add2011-06-04 14:31:571904 bool empty() const _NOEXCEPT {return __tree_.size() == 0;}
Howard Hinnant82894812010-09-22 16:48:341905 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7686add2011-06-04 14:31:571906 size_type size() const _NOEXCEPT {return __tree_.size();}
Howard Hinnant82894812010-09-22 16:48:341907 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7686add2011-06-04 14:31:571908 size_type max_size() const _NOEXCEPT {return __tree_.max_size();}
Howard Hinnantbc8d3f92010-05-11 19:42:161909
Howard Hinnant82894812010-09-22 16:48:341910 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7686add2011-06-04 14:31:571911 allocator_type get_allocator() const _NOEXCEPT {return __tree_.__alloc();}
Howard Hinnant82894812010-09-22 16:48:341912 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7686add2011-06-04 14:31:571913 key_compare key_comp() const {return __tree_.value_comp().key_comp();}
Howard Hinnant82894812010-09-22 16:48:341914 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7686add2011-06-04 14:31:571915 value_compare value_comp() const
1916 {return value_compare(__tree_.value_comp().key_comp());}
Howard Hinnantbc8d3f92010-05-11 19:42:161917
Howard Hinnant73d21a42010-09-04 23:28:191918#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant73d21a42010-09-04 23:28:191919#ifndef _LIBCPP_HAS_NO_VARIADICS
1920
Howard Hinnant635ce1d2012-05-25 22:04:211921 template <class ..._Args>
Howard Hinnantbc8d3f92010-05-11 19:42:161922 iterator
Howard Hinnant635ce1d2012-05-25 22:04:211923 emplace(_Args&& ...__args);
Howard Hinnantbc8d3f92010-05-11 19:42:161924
Howard Hinnant635ce1d2012-05-25 22:04:211925 template <class ..._Args>
Howard Hinnantbc8d3f92010-05-11 19:42:161926 iterator
Howard Hinnant635ce1d2012-05-25 22:04:211927 emplace_hint(const_iterator __p, _Args&& ...__args);
Howard Hinnantbc8d3f92010-05-11 19:42:161928
Howard Hinnant73d21a42010-09-04 23:28:191929#endif // _LIBCPP_HAS_NO_VARIADICS
1930
Howard Hinnant99968442011-11-29 18:15:501931 template <class _Pp,
1932 class = typename enable_if<is_constructible<value_type, _Pp>::value>::type>
Howard Hinnant82894812010-09-22 16:48:341933 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant99968442011-11-29 18:15:501934 iterator insert(_Pp&& __p)
1935 {return __tree_.__insert_multi(_VSTD::forward<_Pp>(__p));}
Howard Hinnantbc8d3f92010-05-11 19:42:161936
Howard Hinnant99968442011-11-29 18:15:501937 template <class _Pp,
1938 class = typename enable_if<is_constructible<value_type, _Pp>::value>::type>
Howard Hinnant82894812010-09-22 16:48:341939 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant99968442011-11-29 18:15:501940 iterator insert(const_iterator __pos, _Pp&& __p)
1941 {return __tree_.__insert_multi(__pos.__i_, _VSTD::forward<_Pp>(__p));}
Howard Hinnantbc8d3f92010-05-11 19:42:161942
Howard Hinnant73d21a42010-09-04 23:28:191943#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:161944
Howard Hinnant82894812010-09-22 16:48:341945 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161946 iterator insert(const value_type& __v) {return __tree_.__insert_multi(__v);}
1947
Howard Hinnant82894812010-09-22 16:48:341948 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161949 iterator insert(const_iterator __p, const value_type& __v)
1950 {return __tree_.__insert_multi(__p.__i_, __v);}
1951
Marshall Clow3426a862016-01-05 19:32:411952#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
1953 _LIBCPP_INLINE_VISIBILITY
1954 iterator insert( value_type&& __v) {return __tree_.__insert_multi(_VSTD::forward<value_type>(__v));}
1955
1956 _LIBCPP_INLINE_VISIBILITY
1957 iterator insert(const_iterator __p, value_type&& __v)
1958 {return __tree_.__insert_multi(__p.__i_, _VSTD::forward<value_type>(__v));}
1959#endif
1960
Howard Hinnantbc8d3f92010-05-11 19:42:161961 template <class _InputIterator>
Howard Hinnant82894812010-09-22 16:48:341962 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161963 void insert(_InputIterator __f, _InputIterator __l)
1964 {
1965 for (const_iterator __e = cend(); __f != __l; ++__f)
1966 __tree_.__insert_multi(__e.__i_, *__f);
1967 }
1968
Howard Hinnante3e32912011-08-12 21:56:021969#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1970
Howard Hinnant82894812010-09-22 16:48:341971 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161972 void insert(initializer_list<value_type> __il)
1973 {insert(__il.begin(), __il.end());}
1974
Howard Hinnante3e32912011-08-12 21:56:021975#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1976
Howard Hinnant82894812010-09-22 16:48:341977 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161978 iterator erase(const_iterator __p) {return __tree_.erase(__p.__i_);}
Howard Hinnant82894812010-09-22 16:48:341979 _LIBCPP_INLINE_VISIBILITY
Marshall Clow488025c2015-05-10 13:35:001980 iterator erase(iterator __p) {return __tree_.erase(__p.__i_);}
1981 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161982 size_type erase(const key_type& __k) {return __tree_.__erase_multi(__k);}
Howard Hinnant82894812010-09-22 16:48:341983 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161984 iterator erase(const_iterator __f, const_iterator __l)
1985 {return __tree_.erase(__f.__i_, __l.__i_);}
Howard Hinnant82894812010-09-22 16:48:341986 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161987 void clear() {__tree_.clear();}
1988
Howard Hinnant82894812010-09-22 16:48:341989 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7686add2011-06-04 14:31:571990 void swap(multimap& __m)
1991 _NOEXCEPT_(__is_nothrow_swappable<__base>::value)
1992 {__tree_.swap(__m.__tree_);}
Howard Hinnantbc8d3f92010-05-11 19:42:161993
Howard Hinnant82894812010-09-22 16:48:341994 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161995 iterator find(const key_type& __k) {return __tree_.find(__k);}
Howard Hinnant82894812010-09-22 16:48:341996 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161997 const_iterator find(const key_type& __k) const {return __tree_.find(__k);}
Marshall Clow5cfc6ab2013-08-13 22:18:471998#if _LIBCPP_STD_VER > 11
1999 template <typename _K2>
2000 _LIBCPP_INLINE_VISIBILITY
2001 typename enable_if<__is_transparent<_Compare, _K2>::value,iterator>::type
2002 find(const _K2& __k) {return __tree_.find(__k);}
2003 template <typename _K2>
2004 _LIBCPP_INLINE_VISIBILITY
2005 typename enable_if<__is_transparent<_Compare, _K2>::value,const_iterator>::type
2006 find(const _K2& __k) const {return __tree_.find(__k);}
2007#endif
2008
Howard Hinnant82894812010-09-22 16:48:342009 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:162010 size_type count(const key_type& __k) const
2011 {return __tree_.__count_multi(__k);}
Marshall Clow4de32042014-08-24 23:54:162012#if _LIBCPP_STD_VER > 11
2013 template <typename _K2>
2014 _LIBCPP_INLINE_VISIBILITY
2015 typename enable_if<__is_transparent<_Compare, _K2>::value,size_type>::type
Marshall Clow58113db2015-06-30 18:15:412016 count(const _K2& __k) const {return __tree_.__count_multi(__k);}
Marshall Clow4de32042014-08-24 23:54:162017#endif
Howard Hinnant82894812010-09-22 16:48:342018 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:162019 iterator lower_bound(const key_type& __k)
2020 {return __tree_.lower_bound(__k);}
Howard Hinnant82894812010-09-22 16:48:342021 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:162022 const_iterator lower_bound(const key_type& __k) const
2023 {return __tree_.lower_bound(__k);}
Marshall Clow5cfc6ab2013-08-13 22:18:472024#if _LIBCPP_STD_VER > 11
2025 template <typename _K2>
2026 _LIBCPP_INLINE_VISIBILITY
2027 typename enable_if<__is_transparent<_Compare, _K2>::value,iterator>::type
2028 lower_bound(const _K2& __k) {return __tree_.lower_bound(__k);}
2029
2030 template <typename _K2>
2031 _LIBCPP_INLINE_VISIBILITY
2032 typename enable_if<__is_transparent<_Compare, _K2>::value,const_iterator>::type
2033 lower_bound(const _K2& __k) const {return __tree_.lower_bound(__k);}
2034#endif
2035
Howard Hinnant82894812010-09-22 16:48:342036 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:162037 iterator upper_bound(const key_type& __k)
2038 {return __tree_.upper_bound(__k);}
Howard Hinnant82894812010-09-22 16:48:342039 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:162040 const_iterator upper_bound(const key_type& __k) const
2041 {return __tree_.upper_bound(__k);}
Marshall Clow5cfc6ab2013-08-13 22:18:472042#if _LIBCPP_STD_VER > 11
2043 template <typename _K2>
2044 _LIBCPP_INLINE_VISIBILITY
2045 typename enable_if<__is_transparent<_Compare, _K2>::value,iterator>::type
2046 upper_bound(const _K2& __k) {return __tree_.upper_bound(__k);}
2047 template <typename _K2>
2048 _LIBCPP_INLINE_VISIBILITY
2049 typename enable_if<__is_transparent<_Compare, _K2>::value,const_iterator>::type
2050 upper_bound(const _K2& __k) const {return __tree_.upper_bound(__k);}
2051#endif
2052
Howard Hinnant82894812010-09-22 16:48:342053 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:162054 pair<iterator,iterator> equal_range(const key_type& __k)
2055 {return __tree_.__equal_range_multi(__k);}
Howard Hinnant82894812010-09-22 16:48:342056 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:162057 pair<const_iterator,const_iterator> equal_range(const key_type& __k) const
2058 {return __tree_.__equal_range_multi(__k);}
Marshall Clow5cfc6ab2013-08-13 22:18:472059#if _LIBCPP_STD_VER > 11
2060 template <typename _K2>
2061 _LIBCPP_INLINE_VISIBILITY
2062 typename enable_if<__is_transparent<_Compare, _K2>::value,pair<iterator,iterator>>::type
2063 equal_range(const _K2& __k) {return __tree_.__equal_range_multi(__k);}
2064 template <typename _K2>
2065 _LIBCPP_INLINE_VISIBILITY
2066 typename enable_if<__is_transparent<_Compare, _K2>::value,pair<const_iterator,const_iterator>>::type
2067 equal_range(const _K2& __k) const {return __tree_.__equal_range_multi(__k);}
2068#endif
Howard Hinnantbc8d3f92010-05-11 19:42:162069
2070private:
2071 typedef typename __base::__node __node;
2072 typedef typename __base::__node_allocator __node_allocator;
2073 typedef typename __base::__node_pointer __node_pointer;
2074 typedef typename __base::__node_const_pointer __node_const_pointer;
Howard Hinnant99968442011-11-29 18:15:502075 typedef __map_node_destructor<__node_allocator> _Dp;
2076 typedef unique_ptr<__node, _Dp> __node_holder;
Howard Hinnantbc8d3f92010-05-11 19:42:162077
Howard Hinnant73d21a42010-09-04 23:28:192078#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:162079 __node_holder __construct_node();
Howard Hinnant635ce1d2012-05-25 22:04:212080 template <class _A0>
Howard Hinnantb66e1c32013-07-04 20:59:162081 __node_holder
Howard Hinnant635ce1d2012-05-25 22:04:212082 __construct_node(_A0&& __a0);
Howard Hinnant73d21a42010-09-04 23:28:192083#ifndef _LIBCPP_HAS_NO_VARIADICS
Howard Hinnant635ce1d2012-05-25 22:04:212084 template <class _A0, class _A1, class ..._Args>
2085 __node_holder __construct_node(_A0&& __a0, _A1&& __a1, _Args&& ...__args);
Howard Hinnant73d21a42010-09-04 23:28:192086#endif // _LIBCPP_HAS_NO_VARIADICS
2087#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:162088};
2089
Howard Hinnant73d21a42010-09-04 23:28:192090#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:162091
2092template <class _Key, class _Tp, class _Compare, class _Allocator>
2093multimap<_Key, _Tp, _Compare, _Allocator>::multimap(multimap&& __m, const allocator_type& __a)
Howard Hinnant0949eed2011-06-30 21:18:192094 : __tree_(_VSTD::move(__m.__tree_), __a)
Howard Hinnantbc8d3f92010-05-11 19:42:162095{
2096 if (__a != __m.get_allocator())
2097 {
2098 const_iterator __e = cend();
2099 while (!__m.empty())
2100 __tree_.__insert_multi(__e.__i_,
Howard Hinnant0949eed2011-06-30 21:18:192101 _VSTD::move(__m.__tree_.remove(__m.begin().__i_)->__value_));
Howard Hinnantbc8d3f92010-05-11 19:42:162102 }
2103}
2104
2105template <class _Key, class _Tp, class _Compare, class _Allocator>
2106typename multimap<_Key, _Tp, _Compare, _Allocator>::__node_holder
2107multimap<_Key, _Tp, _Compare, _Allocator>::__construct_node()
2108{
2109 __node_allocator& __na = __tree_.__node_alloc();
Howard Hinnant99968442011-11-29 18:15:502110 __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
Howard Hinnant70342b92013-06-19 21:29:402111 __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__cc.first));
Howard Hinnantbc8d3f92010-05-11 19:42:162112 __h.get_deleter().__first_constructed = true;
Howard Hinnant70342b92013-06-19 21:29:402113 __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__cc.second));
Howard Hinnantbc8d3f92010-05-11 19:42:162114 __h.get_deleter().__second_constructed = true;
2115 return __h;
2116}
2117
2118template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant635ce1d2012-05-25 22:04:212119template <class _A0>
Howard Hinnantb66e1c32013-07-04 20:59:162120typename multimap<_Key, _Tp, _Compare, _Allocator>::__node_holder
Howard Hinnantbc8d3f92010-05-11 19:42:162121multimap<_Key, _Tp, _Compare, _Allocator>::__construct_node(_A0&& __a0)
2122{
2123 __node_allocator& __na = __tree_.__node_alloc();
Howard Hinnant99968442011-11-29 18:15:502124 __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
Howard Hinnant0949eed2011-06-30 21:18:192125 __node_traits::construct(__na, _VSTD::addressof(__h->__value_), _VSTD::forward<_A0>(__a0));
Howard Hinnantbc8d3f92010-05-11 19:42:162126 __h.get_deleter().__first_constructed = true;
2127 __h.get_deleter().__second_constructed = true;
2128 return __h;
2129}
2130
Howard Hinnant635ce1d2012-05-25 22:04:212131#ifndef _LIBCPP_HAS_NO_VARIADICS
2132
2133template <class _Key, class _Tp, class _Compare, class _Allocator>
2134template <class _A0, class _A1, class ..._Args>
2135typename multimap<_Key, _Tp, _Compare, _Allocator>::__node_holder
2136multimap<_Key, _Tp, _Compare, _Allocator>::__construct_node(_A0&& __a0, _A1&& __a1, _Args&& ...__args)
2137{
2138 __node_allocator& __na = __tree_.__node_alloc();
2139 __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
2140 __node_traits::construct(__na, _VSTD::addressof(__h->__value_),
2141 _VSTD::forward<_A0>(__a0), _VSTD::forward<_A1>(__a1),
2142 _VSTD::forward<_Args>(__args)...);
2143 __h.get_deleter().__first_constructed = true;
Howard Hinnantbc8d3f92010-05-11 19:42:162144 __h.get_deleter().__second_constructed = true;
2145 return __h;
2146}
2147
Howard Hinnant73d21a42010-09-04 23:28:192148#endif // _LIBCPP_HAS_NO_VARIADICS
2149#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:162150
Howard Hinnant73d21a42010-09-04 23:28:192151#if !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
Howard Hinnantbc8d3f92010-05-11 19:42:162152
2153template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant635ce1d2012-05-25 22:04:212154template <class ..._Args>
Howard Hinnantbc8d3f92010-05-11 19:42:162155typename multimap<_Key, _Tp, _Compare, _Allocator>::iterator
Howard Hinnant635ce1d2012-05-25 22:04:212156multimap<_Key, _Tp, _Compare, _Allocator>::emplace(_Args&& ...__args)
Howard Hinnantbc8d3f92010-05-11 19:42:162157{
Howard Hinnant635ce1d2012-05-25 22:04:212158 __node_holder __h = __construct_node(_VSTD::forward<_Args>(__args)...);
Howard Hinnantbc8d3f92010-05-11 19:42:162159 iterator __r = __tree_.__node_insert_multi(__h.get());
2160 __h.release();
2161 return __r;
2162}
2163
2164template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant635ce1d2012-05-25 22:04:212165template <class ..._Args>
Howard Hinnantbc8d3f92010-05-11 19:42:162166typename multimap<_Key, _Tp, _Compare, _Allocator>::iterator
2167multimap<_Key, _Tp, _Compare, _Allocator>::emplace_hint(const_iterator __p,
Howard Hinnantbc8d3f92010-05-11 19:42:162168 _Args&& ...__args)
2169{
Howard Hinnant635ce1d2012-05-25 22:04:212170 __node_holder __h = __construct_node(_VSTD::forward<_Args>(__args)...);
Howard Hinnantbc8d3f92010-05-11 19:42:162171 iterator __r = __tree_.__node_insert_multi(__p.__i_, __h.get());
2172 __h.release();
2173 return __r;
2174}
2175
Howard Hinnant73d21a42010-09-04 23:28:192176#endif // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
Howard Hinnantbc8d3f92010-05-11 19:42:162177
2178template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant82894812010-09-22 16:48:342179inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:162180bool
2181operator==(const multimap<_Key, _Tp, _Compare, _Allocator>& __x,
2182 const multimap<_Key, _Tp, _Compare, _Allocator>& __y)
2183{
Howard Hinnant0949eed2011-06-30 21:18:192184 return __x.size() == __y.size() && _VSTD::equal(__x.begin(), __x.end(), __y.begin());
Howard Hinnantbc8d3f92010-05-11 19:42:162185}
2186
2187template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant82894812010-09-22 16:48:342188inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:162189bool
2190operator< (const multimap<_Key, _Tp, _Compare, _Allocator>& __x,
2191 const multimap<_Key, _Tp, _Compare, _Allocator>& __y)
2192{
Howard Hinnant0949eed2011-06-30 21:18:192193 return _VSTD::lexicographical_compare(__x.begin(), __x.end(), __y.begin(), __y.end());
Howard Hinnantbc8d3f92010-05-11 19:42:162194}
2195
2196template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant82894812010-09-22 16:48:342197inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:162198bool
2199operator!=(const multimap<_Key, _Tp, _Compare, _Allocator>& __x,
2200 const multimap<_Key, _Tp, _Compare, _Allocator>& __y)
2201{
2202 return !(__x == __y);
2203}
2204
2205template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant82894812010-09-22 16:48:342206inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:162207bool
2208operator> (const multimap<_Key, _Tp, _Compare, _Allocator>& __x,
2209 const multimap<_Key, _Tp, _Compare, _Allocator>& __y)
2210{
2211 return __y < __x;
2212}
2213
2214template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant82894812010-09-22 16:48:342215inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:162216bool
2217operator>=(const multimap<_Key, _Tp, _Compare, _Allocator>& __x,
2218 const multimap<_Key, _Tp, _Compare, _Allocator>& __y)
2219{
2220 return !(__x < __y);
2221}
2222
2223template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant82894812010-09-22 16:48:342224inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:162225bool
2226operator<=(const multimap<_Key, _Tp, _Compare, _Allocator>& __x,
2227 const multimap<_Key, _Tp, _Compare, _Allocator>& __y)
2228{
2229 return !(__y < __x);
2230}
2231
2232template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant82894812010-09-22 16:48:342233inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:162234void
2235swap(multimap<_Key, _Tp, _Compare, _Allocator>& __x,
2236 multimap<_Key, _Tp, _Compare, _Allocator>& __y)
Howard Hinnant7686add2011-06-04 14:31:572237 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
Howard Hinnantbc8d3f92010-05-11 19:42:162238{
2239 __x.swap(__y);
2240}
2241
2242_LIBCPP_END_NAMESPACE_STD
2243
2244#endif // _LIBCPP_MAP